[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/ -> themes.php (source)

   1  <?php
   2  /**
   3   * Themes administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   */
   8  
   9  /** WordPress Administration Bootstrap */
  10  require_once ('./admin.php');
  11  
  12  if ( !current_user_can('switch_themes') && !current_user_can('edit_theme_options') )
  13      wp_die( __( 'Cheatin&#8217; uh?' ) );
  14  
  15  $wp_list_table = _get_list_table('WP_Themes_List_Table');
  16  
  17  if ( current_user_can( 'switch_themes' ) && isset($_GET['action'] ) ) {
  18      if ( 'activate' == $_GET['action'] ) {
  19          check_admin_referer('switch-theme_' . $_GET['template']);
  20          switch_theme($_GET['template'], $_GET['stylesheet']);
  21          wp_redirect( admin_url('themes.php?activated=true') );
  22          exit;
  23      } elseif ( 'delete' == $_GET['action'] ) {
  24          check_admin_referer('delete-theme_' . $_GET['template']);
  25          if ( !current_user_can('delete_themes') )
  26              wp_die( __( 'Cheatin&#8217; uh?' ) );
  27          delete_theme($_GET['template']);
  28          wp_redirect( admin_url('themes.php?deleted=true') );
  29          exit;
  30      }
  31  }
  32  
  33  $wp_list_table->prepare_items();
  34  
  35  $title = __('Manage Themes');
  36  $parent_file = 'themes.php';
  37  
  38  if ( current_user_can( 'switch_themes' ) ) :
  39  
  40  $help_manage = '<p>' . __('Aside from the default theme included with your WordPress installation, themes are designed and developed by third parties.') . '</p>' .
  41      '<p>' . __('You can see your active theme at the top of the screen. Below are the other themes you have installed that are not currently in use. You can see what your site would look like with one of these themes by clicking the Customize link (see "Previewing and Customizing", below). To change themes, click the Activate link.') . '</p>';
  42  
  43  get_current_screen()->add_help_tab( array(
  44      'id'      => 'overview',
  45      'title'   => __('Overview'),
  46      'content' => $help_manage
  47  ) );
  48  
  49  if ( current_user_can( 'install_themes' ) ) {
  50      if ( is_multisite() ) {
  51          $help_install = '<p>' . __('Installing themes on Multisite can only be done from the Network Admin section.') . '</p>';
  52      } else {
  53          $help_install = '<p>' . sprintf( __('If you would like to see more themes to choose from, click on the &#8220;Install Themes&#8221; tab and you will be able to browse or search for additional themes from the <a href="%s" target="_blank">WordPress.org Theme Directory</a>. Themes in the WordPress.org Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!'), 'http://wordpress.org/extend/themes/' ) . '</p>';
  54      }
  55  
  56      get_current_screen()->add_help_tab( array(
  57          'id'      => 'adding-themes',
  58          'title'   => __('Adding Themes'),
  59          'content' => $help_install
  60      ) );
  61  }
  62  
  63  if ( current_user_can( 'edit_theme_options' ) ) {
  64      $help_customize =
  65          '<p>' . __('Click on the "Customize" link under any theme to preview that theme and change theme options in a separate, full-screen view. Any installed theme can be previewed and customized in this way.') . '</p>'.
  66          '<p>' . __('The theme being previewed is fully interactive &mdash; navigate to different pages to see how the theme handles posts, archives, and other page templates.') . '</p>' .
  67          '<p>' . __('In the left-hand pane of the Theme Customizer you can edit the theme settings. The settings will differ, depending on what theme features the theme being previewed supports. To accept the new settings and activate the theme all in one step, click the "Save and Activate" button at the bottom of the left-hand sidebar.') . '</p>' .
  68          '<p>' . __('When previewing on smaller monitors, you can use the "Collapse" icon at the bottom of the left-hand pane. This will hide the pane, giving you more room to preview your site in the new theme. To bring the pane back, click on the Collapse icon again.') . '</p>';
  69  
  70      get_current_screen()->add_help_tab( array(
  71          'id'        => 'customize-preview-themes',
  72          'title'        => __('Previewing and Customizing'),
  73          'content'    => $help_customize
  74      ) );
  75  }
  76  
  77  get_current_screen()->set_help_sidebar(
  78      '<p><strong>' . __('For more information:') . '</strong></p>' .
  79      '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>' .
  80      '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  81  );
  82  
  83  wp_enqueue_script( 'theme' );
  84  wp_enqueue_script( 'customize-loader' );
  85  
  86  endif;
  87  
  88  require_once ('./admin-header.php');
  89  ?>
  90  
  91  <?php if ( ! validate_current_theme() ) : ?>
  92  <div id="message1" class="updated"><p><?php _e('The active theme is broken. Reverting to the default theme.'); ?></p></div>
  93  <?php elseif ( isset($_GET['activated']) ) :
  94          if ( isset($wp_registered_sidebars) && count( (array) $wp_registered_sidebars ) && current_user_can('edit_theme_options') ) { ?>
  95  <div id="message2" class="updated"><p><?php printf( __('New theme activated. This theme supports widgets, please visit the <a href="%s">widgets settings</a> screen to configure them.'), admin_url( 'widgets.php' ) ); ?></p></div><?php
  96          } else { ?>
  97  <div id="message2" class="updated"><p><?php printf( __( 'New theme activated. <a href="%s">Visit site</a>' ), home_url( '/' ) ); ?></p></div><?php
  98          }
  99      elseif ( isset($_GET['deleted']) ) : ?>
 100  <div id="message3" class="updated"><p><?php _e('Theme deleted.') ?></p></div>
 101  <?php endif; ?>
 102  
 103  <div class="wrap"><?php
 104  screen_icon();
 105  if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
 106  <h2 class="nav-tab-wrapper">
 107  <a href="themes.php" class="nav-tab nav-tab-active"><?php echo esc_html( $title ); ?></a><a href="<?php echo admin_url( 'theme-install.php'); ?>" class="nav-tab"><?php echo esc_html_x('Install Themes', 'theme'); ?></a>
 108  <?php else : ?>
 109  <h2><?php echo esc_html( $title ); ?>
 110  <?php endif; ?>
 111  </h2>
 112  <?php
 113  
 114  $ct = wp_get_theme();
 115  $screenshot = $ct->get_screenshot();
 116  $class = $screenshot ? 'has-screenshot' : '';
 117  
 118  $customize_title = sprintf( __( 'Customize &#8220;%s&#8221;' ), $ct->display('Name') );
 119  
 120  ?>
 121  <div id="current-theme" class="<?php echo esc_attr( $class ); ?>">
 122      <?php if ( $screenshot ) : ?>
 123          <a href="<?php echo wp_customize_url( $ct->get_stylesheet() ); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>">
 124              <img src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
 125          </a>
 126          <img class="hide-if-customize" src="<?php echo esc_url( $screenshot ); ?>" alt="<?php esc_attr_e( 'Current theme preview' ); ?>" />
 127      <?php endif; ?>
 128  
 129      <h3><?php _e('Current Theme'); ?></h3>
 130      <h4>
 131          <?php echo $ct->display('Name'); ?>
 132      </h4>
 133  
 134      <div>
 135          <ul class="theme-info">
 136              <li><?php printf( __('By %s'), $ct->display('Author') ); ?></li>
 137              <li><?php printf( __('Version %s'), $ct->display('Version') ); ?></li>
 138          </ul>
 139          <p class="theme-description"><?php echo $ct->display('Description'); ?></p>
 140          <?php theme_update_available( $ct ); ?>
 141      </div>
 142  
 143  <div class="theme-options">
 144      <a id="customize-current-theme-link" href="<?php echo wp_customize_url( $ct->get_stylesheet() ); ?>" class="load-customize hide-if-no-customize" title="<?php echo esc_attr( $customize_title ); ?>"><?php _e( 'Customize' )?></a>
 145      <span><?php _e( 'Options:' )?></span>
 146      <?php
 147      // Pretend you didn't see this.
 148      $options = array();
 149      if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
 150          foreach ( (array) $submenu['themes.php'] as $item) {
 151              $class = '';
 152              if ( 'themes.php' == $item[2] || 'theme-editor.php' == $item[2] )
 153                  continue;
 154              // 0 = name, 1 = capability, 2 = file
 155              if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
 156                  $class = ' class="current"';
 157              if ( !empty($submenu[$item[2]]) ) {
 158                  $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
 159                  $menu_hook = get_plugin_page_hook($submenu[$item[2]][0][2], $item[2]);
 160                  if ( file_exists(WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}") || !empty($menu_hook))
 161                      $options[] = "<a href='admin.php?page={$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
 162                  else
 163                      $options[] = "<a href='{$submenu[$item[2]][0][2]}'$class>{$item[0]}</a>";
 164              } else if ( current_user_can($item[1]) ) {
 165                  if ( file_exists(ABSPATH . 'wp-admin/' . $item[2]) ) {
 166                      $options[] = "<a href='{$item[2]}'$class>{$item[0]}</a>";
 167                  } else {
 168                      $options[] = "<a href='themes.php?page={$item[2]}'$class>{$item[0]}</a>";
 169                  }
 170              }
 171          }
 172      }
 173  
 174      ?>
 175      <ul>
 176          <?php foreach ( $options as $option ) : ?>
 177              <li><?php echo $option; ?></li>
 178          <?php endforeach; ?>
 179      </ul>
 180  </div>
 181  
 182  </div>
 183  
 184  <br class="clear" />
 185  <?php
 186  if ( ! current_user_can( 'switch_themes' ) ) {
 187      echo '</div>';
 188      require ( './admin-footer.php' );
 189      exit;
 190  }
 191  ?>
 192  
 193  <form class="search-form filter-form" action="" method="get">
 194  
 195  <h3 class="available-themes"><?php _e('Available Themes'); ?></h3>
 196  
 197  <?php if ( !empty( $_REQUEST['s'] ) || !empty( $_REQUEST['features'] ) || $wp_list_table->has_items() ) : ?>
 198  
 199  <p class="search-box">
 200      <label class="screen-reader-text" for="theme-search-input"><?php _e('Search Installed Themes'); ?>:</label>
 201      <input type="search" id="theme-search-input" name="s" value="<?php _admin_search_query(); ?>" />
 202      <?php submit_button( __( 'Search Installed Themes' ), 'button', false, false, array( 'id' => 'search-submit' ) ); ?>
 203      <a id="filter-click" href="?filter=1"><?php _e( 'Feature Filter' ); ?></a>
 204  </p>
 205  
 206  <div id="filter-box" style="<?php if ( empty($_REQUEST['filter']) ) echo 'display: none;'; ?>">
 207  <?php $feature_list = get_theme_feature_list(); ?>
 208      <div class="feature-filter">
 209          <p class="install-help"><?php _e('Theme filters') ?></p>
 210      <?php if ( !empty( $_REQUEST['filter'] ) ) : ?>
 211          <input type="hidden" name="filter" value="1" />
 212      <?php endif; ?>
 213      <?php foreach ( $feature_list as $feature_name => $features ) :
 214              $feature_name = esc_html( $feature_name ); ?>
 215  
 216          <div class="feature-container">
 217              <div class="feature-name"><?php echo $feature_name ?></div>
 218  
 219              <ol class="feature-group">
 220                  <?php foreach ( $features as $key => $feature ) :
 221                          $feature_name = $feature;
 222                          $feature_name = esc_html( $feature_name );
 223                          $feature = esc_attr( $feature );
 224                          ?>
 225                  <li>
 226                      <input type="checkbox" name="features[]" id="feature-id-<?php echo $key; ?>" value="<?php echo $key; ?>" <?php checked( in_array( $key, $wp_list_table->features ) ); ?>/>
 227                      <label for="feature-id-<?php echo $key; ?>"><?php echo $feature_name; ?></label>
 228                  </li>
 229                  <?php endforeach; ?>
 230              </ol>
 231          </div>
 232      <?php endforeach; ?>
 233  
 234      <div class="feature-container">
 235          <?php submit_button( __( 'Apply Filters' ), 'button-secondary submitter', false, false, array( 'id' => 'filter-submit' ) ); ?>
 236          &nbsp;
 237          <a id="mini-filter-click" href="<?php echo esc_url( remove_query_arg( array('filter', 'features', 'submit') ) ); ?>"><?php _e( 'Close filters' )?></a>
 238      </div>
 239      <br/>
 240      </div>
 241      <br class="clear"/>
 242  </div>
 243  
 244  <?php endif; ?>
 245  
 246  <br class="clear" />
 247  
 248  <?php $wp_list_table->display(); ?>
 249  
 250  </form>
 251  <br class="clear" />
 252  
 253  <?php
 254  // List broken themes, if any.
 255  if ( ! is_multisite() && current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
 256  ?>
 257  
 258  <h3><?php _e('Broken Themes'); ?></h3>
 259  <p><?php _e('The following themes are installed but incomplete. Themes must have a stylesheet and a template.'); ?></p>
 260  
 261  <table id="broken-themes">
 262      <tr>
 263          <th><?php _ex('Name', 'theme name'); ?></th>
 264          <th><?php _e('Description'); ?></th>
 265      </tr>
 266  <?php
 267      $alt = '';
 268      foreach ( $broken_themes as $broken_theme ) {
 269          $alt = ('class="alternate"' == $alt) ? '' : 'class="alternate"';
 270          echo "
 271          <tr $alt>
 272               <td>" . $broken_theme->get('Name') ."</td>
 273               <td>" . $broken_theme->errors()->get_error_message() . "</td>
 274          </tr>";
 275      }
 276  ?>
 277  </table>
 278  <?php
 279  }
 280  ?>
 281  </div>
 282  
 283  <?php require ('./admin-footer.php'); ?>


Generated: Fri May 25 03:56:23 2012 Hosted by follow the white rabbit.