[ 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  __DIR__ . '/admin.php';
  11  
  12  if ( ! current_user_can( 'switch_themes' ) && ! current_user_can( 'edit_theme_options' ) ) {
  13      wp_die(
  14          '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  15          '<p>' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '</p>',
  16          403
  17      );
  18  }
  19  
  20  if ( current_user_can( 'switch_themes' ) && isset( $_GET['action'] ) ) {
  21      if ( 'activate' === $_GET['action'] ) {
  22          check_admin_referer( 'switch-theme_' . $_GET['stylesheet'] );
  23          $theme = wp_get_theme( $_GET['stylesheet'] );
  24  
  25          if ( ! $theme->exists() || ! $theme->is_allowed() ) {
  26              wp_die(
  27                  '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
  28                  '<p>' . __( 'The requested theme does not exist.' ) . '</p>',
  29                  403
  30              );
  31          }
  32  
  33          switch_theme( $theme->get_stylesheet() );
  34          wp_redirect( admin_url( 'themes.php?activated=true' ) );
  35          exit;
  36      } elseif ( 'resume' === $_GET['action'] ) {
  37          check_admin_referer( 'resume-theme_' . $_GET['stylesheet'] );
  38          $theme = wp_get_theme( $_GET['stylesheet'] );
  39  
  40          if ( ! current_user_can( 'resume_theme', $_GET['stylesheet'] ) ) {
  41              wp_die(
  42                  '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  43                  '<p>' . __( 'Sorry, you are not allowed to resume this theme.' ) . '</p>',
  44                  403
  45              );
  46          }
  47  
  48          $result = resume_theme( $theme->get_stylesheet(), self_admin_url( 'themes.php?error=resuming' ) );
  49  
  50          if ( is_wp_error( $result ) ) {
  51              wp_die( $result );
  52          }
  53  
  54          wp_redirect( admin_url( 'themes.php?resumed=true' ) );
  55          exit;
  56      } elseif ( 'delete' === $_GET['action'] ) {
  57          check_admin_referer( 'delete-theme_' . $_GET['stylesheet'] );
  58          $theme = wp_get_theme( $_GET['stylesheet'] );
  59  
  60          if ( ! current_user_can( 'delete_themes' ) ) {
  61              wp_die(
  62                  '<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
  63                  '<p>' . __( 'Sorry, you are not allowed to delete this item.' ) . '</p>',
  64                  403
  65              );
  66          }
  67  
  68          if ( ! $theme->exists() ) {
  69              wp_die(
  70                  '<h1>' . __( 'Something went wrong.' ) . '</h1>' .
  71                  '<p>' . __( 'The requested theme does not exist.' ) . '</p>',
  72                  403
  73              );
  74          }
  75  
  76          $active = wp_get_theme();
  77          if ( $active->get( 'Template' ) == $_GET['stylesheet'] ) {
  78              wp_redirect( admin_url( 'themes.php?delete-active-child=true' ) );
  79          } else {
  80              delete_theme( $_GET['stylesheet'] );
  81              wp_redirect( admin_url( 'themes.php?deleted=true' ) );
  82          }
  83          exit;
  84      } elseif ( 'enable-auto-update' === $_GET['action'] ) {
  85          if ( ! ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) ) {
  86              wp_die( __( 'Sorry, you are not allowed to enable themes automatic updates.' ) );
  87          }
  88  
  89          check_admin_referer( 'updates' );
  90  
  91          $all_items    = wp_get_themes();
  92          $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
  93  
  94          $auto_updates[] = $_GET['stylesheet'];
  95          $auto_updates   = array_unique( $auto_updates );
  96          // Remove themes that have been deleted since the site option was last updated.
  97          $auto_updates = array_intersect( $auto_updates, array_keys( $all_items ) );
  98  
  99          update_site_option( 'auto_update_themes', $auto_updates );
 100  
 101          wp_redirect( admin_url( 'themes.php?enabled-auto-update=true' ) );
 102  
 103          exit;
 104      } elseif ( 'disable-auto-update' === $_GET['action'] ) {
 105          if ( ! ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) ) {
 106              wp_die( __( 'Sorry, you are not allowed to disable themes automatic updates.' ) );
 107          }
 108  
 109          check_admin_referer( 'updates' );
 110  
 111          $all_items    = wp_get_themes();
 112          $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
 113  
 114          $auto_updates = array_diff( $auto_updates, array( $_GET['stylesheet'] ) );
 115          // Remove themes that have been deleted since the site option was last updated.
 116          $auto_updates = array_intersect( $auto_updates, array_keys( $all_items ) );
 117  
 118          update_site_option( 'auto_update_themes', $auto_updates );
 119  
 120          wp_redirect( admin_url( 'themes.php?disabled-auto-update=true' ) );
 121  
 122          exit;
 123      }
 124  }
 125  
 126  $title       = __( 'Manage Themes' );
 127  $parent_file = 'themes.php';
 128  
 129  // Help tab: Overview.
 130  if ( current_user_can( 'switch_themes' ) ) {
 131      $help_overview = '<p>' . __( 'This screen is used for managing your installed themes. Aside from the default theme(s) included with your WordPress installation, themes are designed and developed by third parties.' ) . '</p>' .
 132          '<p>' . __( 'From this screen you can:' ) . '</p>' .
 133          '<ul><li>' . __( 'Hover or tap to see Activate and Live Preview buttons' ) . '</li>' .
 134          '<li>' . __( 'Click on the theme to see the theme name, version, author, description, tags, and the Delete link' ) . '</li>' .
 135          '<li>' . __( 'Click Customize for the current theme or Live Preview for any other theme to see a live preview' ) . '</li></ul>' .
 136          '<p>' . __( 'The current theme is displayed highlighted as the first theme.' ) . '</p>' .
 137          '<p>' . __( 'The search for installed themes will search for terms in their name, description, author, or tag.' ) . ' <span id="live-search-desc">' . __( 'The search results will be updated as you type.' ) . '</span></p>';
 138  
 139      get_current_screen()->add_help_tab(
 140          array(
 141              'id'      => 'overview',
 142              'title'   => __( 'Overview' ),
 143              'content' => $help_overview,
 144          )
 145      );
 146  } // End if 'switch_themes'.
 147  
 148  // Help tab: Adding Themes.
 149  if ( current_user_can( 'install_themes' ) ) {
 150      if ( is_multisite() ) {
 151          $help_install = '<p>' . __( 'Installing themes on Multisite can only be done from the Network Admin section.' ) . '</p>';
 152      } else {
 153          $help_install = '<p>' . sprintf(
 154              /* translators: %s: https://wordpress.org/themes/ */
 155              __( 'If you would like to see more themes to choose from, click on the &#8220;Add New&#8221; button and you will be able to browse or search for additional themes from the <a href="%s">WordPress Theme Directory</a>. Themes in the WordPress Theme Directory are designed and developed by third parties, and are compatible with the license WordPress uses. Oh, and they&#8217;re free!' ),
 156              __( 'https://wordpress.org/themes/' )
 157          ) . '</p>';
 158      }
 159  
 160      get_current_screen()->add_help_tab(
 161          array(
 162              'id'      => 'adding-themes',
 163              'title'   => __( 'Adding Themes' ),
 164              'content' => $help_install,
 165          )
 166      );
 167  } // End if 'install_themes'.
 168  
 169  // Help tab: Previewing and Customizing.
 170  if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) {
 171      $help_customize =
 172          '<p>' . __( 'Tap or hover on any theme then click the Live Preview button to see a live preview of that theme and change theme options in a separate, full-screen view. You can also find a Live Preview button at the bottom of the theme details screen. Any installed theme can be previewed and customized in this way.' ) . '</p>' .
 173          '<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. The settings may 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 Publish &amp; Activate button above the menu.' ) . '</p>' .
 174          '<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>';
 175  
 176      get_current_screen()->add_help_tab(
 177          array(
 178              'id'      => 'customize-preview-themes',
 179              'title'   => __( 'Previewing and Customizing' ),
 180              'content' => $help_customize,
 181          )
 182      );
 183  } // End if 'edit_theme_options' && 'customize'.
 184  
 185  $help_sidebar_autoupdates = '';
 186  
 187  // Help tab: Auto-updates.
 188  if ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) {
 189      $help_tab_autoupdates =
 190          '<p>' . __( 'Auto-updates can be enabled or disabled for each individual theme. Themes with auto-updates enabled will display the estimated date of the next auto-update. Auto-updates depends on the WP-Cron task scheduling system.' ) . '</p>' .
 191          '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>';
 192  
 193      get_current_screen()->add_help_tab(
 194          array(
 195              'id'      => 'plugins-themes-auto-updates',
 196              'title'   => __( 'Auto-updates' ),
 197              'content' => $help_tab_autoupdates,
 198          )
 199      );
 200  
 201      $help_sidebar_autoupdates = '<p>' . __( '<a href="https://wordpress.org/support/article/plugins-themes-auto-updates/">Learn more: Auto-updates documentation</a>' ) . '</p>';
 202  } // End if 'update_themes' && 'wp_is_auto_update_enabled_for_type'.
 203  
 204  get_current_screen()->set_help_sidebar(
 205      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 206      '<p>' . __( '<a href="https://wordpress.org/support/article/using-themes/">Documentation on Using Themes</a>' ) . '</p>' .
 207      $help_sidebar_autoupdates .
 208      '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
 209  );
 210  
 211  if ( current_user_can( 'switch_themes' ) ) {
 212      $themes = wp_prepare_themes_for_js();
 213  } else {
 214      $themes = wp_prepare_themes_for_js( array( wp_get_theme() ) );
 215  }
 216  wp_reset_vars( array( 'theme', 'search' ) );
 217  
 218  wp_localize_script(
 219      'theme',
 220      '_wpThemeSettings',
 221      array(
 222          'themes'   => $themes,
 223          'settings' => array(
 224              'canInstall'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ),
 225              'installURI'    => ( ! is_multisite() && current_user_can( 'install_themes' ) ) ? admin_url( 'theme-install.php' ) : null,
 226              'confirmDelete' => __( "Are you sure you want to delete this theme?\n\nClick 'Cancel' to go back, 'OK' to confirm the delete." ),
 227              'adminUrl'      => parse_url( admin_url(), PHP_URL_PATH ),
 228          ),
 229          'l10n'     => array(
 230              'addNew'            => __( 'Add New Theme' ),
 231              'search'            => __( 'Search Installed Themes' ),
 232              'searchPlaceholder' => __( 'Search installed themes...' ), // Placeholder (no ellipsis).
 233              /* translators: %d: Number of themes. */
 234              'themesFound'       => __( 'Number of Themes found: %d' ),
 235              'noThemesFound'     => __( 'No themes found. Try a different search.' ),
 236          ),
 237      )
 238  );
 239  
 240  add_thickbox();
 241  wp_enqueue_script( 'theme' );
 242  wp_enqueue_script( 'updates' );
 243  
 244  require_once ABSPATH . 'wp-admin/admin-header.php';
 245  ?>
 246  
 247  <div class="wrap">
 248      <h1 class="wp-heading-inline"><?php esc_html_e( 'Themes' ); ?>
 249          <span class="title-count theme-count"><?php echo ! empty( $_GET['search'] ) ? __( '&hellip;' ) : count( $themes ); ?></span>
 250      </h1>
 251  
 252      <?php if ( ! is_multisite() && current_user_can( 'install_themes' ) ) : ?>
 253          <a href="<?php echo admin_url( 'theme-install.php' ); ?>" class="hide-if-no-js page-title-action"><?php echo esc_html_x( 'Add New', 'theme' ); ?></a>
 254      <?php endif; ?>
 255  
 256      <form class="search-form"></form>
 257  
 258      <hr class="wp-header-end">
 259  <?php
 260  if ( ! validate_current_theme() || isset( $_GET['broken'] ) ) {
 261      ?>
 262      <div id="message1" class="updated notice is-dismissible"><p><?php _e( 'The active theme is broken. Reverting to the default theme.' ); ?></p></div>
 263      <?php
 264  } elseif ( isset( $_GET['activated'] ) ) {
 265      if ( isset( $_GET['previewed'] ) ) {
 266          ?>
 267          <div id="message2" class="updated notice is-dismissible"><p><?php _e( 'Settings saved and theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
 268          <?php
 269      } else {
 270          ?>
 271          <div id="message2" class="updated notice is-dismissible"><p><?php _e( 'New theme activated.' ); ?> <a href="<?php echo home_url( '/' ); ?>"><?php _e( 'Visit site' ); ?></a></p></div>
 272          <?php
 273      }
 274  } elseif ( isset( $_GET['deleted'] ) ) {
 275      ?>
 276      <div id="message3" class="updated notice is-dismissible"><p><?php _e( 'Theme deleted.' ); ?></p></div>
 277      <?php
 278  } elseif ( isset( $_GET['delete-active-child'] ) ) {
 279      ?>
 280      <div id="message4" class="error"><p><?php _e( 'You cannot delete a theme while it has an active child theme.' ); ?></p></div>
 281      <?php
 282  } elseif ( isset( $_GET['resumed'] ) ) {
 283      ?>
 284      <div id="message5" class="updated notice is-dismissible"><p><?php _e( 'Theme resumed.' ); ?></p></div>
 285      <?php
 286  } elseif ( isset( $_GET['error'] ) && 'resuming' === $_GET['error'] ) {
 287      ?>
 288      <div id="message6" class="error"><p><?php _e( 'Theme could not be resumed because it triggered a <strong>fatal error</strong>.' ); ?></p></div>
 289      <?php
 290  } elseif ( isset( $_GET['enabled-auto-update'] ) ) {
 291      ?>
 292      <div id="message7" class="updated notice is-dismissible"><p><?php _e( 'Theme will be auto-updated.' ); ?></p></div>
 293      <?php
 294  } elseif ( isset( $_GET['disabled-auto-update'] ) ) {
 295      ?>
 296      <div id="message8" class="updated notice is-dismissible"><p><?php _e( 'Theme will no longer be auto-updated.' ); ?></p></div>
 297      <?php
 298  }
 299  
 300  $ct = wp_get_theme();
 301  
 302  if ( $ct->errors() && ( ! is_multisite() || current_user_can( 'manage_network_themes' ) ) ) {
 303      echo '<div class="error"><p>' . __( 'Error:' ) . ' ' . $ct->errors()->get_error_message() . '</p></div>';
 304  }
 305  
 306  /*
 307  // Certain error codes are less fatal than others. We can still display theme information in most cases.
 308  if ( ! $ct->errors() || ( 1 === count( $ct->errors()->get_error_codes() )
 309      && in_array( $ct->errors()->get_error_code(), array( 'theme_no_parent', 'theme_parent_invalid', 'theme_no_index' ) ) ) ) : ?>
 310  */
 311  
 312      // Pretend you didn't see this.
 313      $current_theme_actions = array();
 314  if ( is_array( $submenu ) && isset( $submenu['themes.php'] ) ) {
 315      foreach ( (array) $submenu['themes.php'] as $item ) {
 316          $class = '';
 317          if ( 'themes.php' === $item[2] || 'theme-editor.php' === $item[2] || 0 === strpos( $item[2], 'customize.php' ) ) {
 318              continue;
 319          }
 320          // 0 = name, 1 = capability, 2 = file.
 321          if ( ( strcmp( $self, $item[2] ) == 0 && empty( $parent_file ) ) || ( $parent_file && ( $item[2] == $parent_file ) ) ) {
 322              $class = ' current';
 323          }
 324          if ( ! empty( $submenu[ $item[2] ] ) ) {
 325              $submenu[ $item[2] ] = array_values( $submenu[ $item[2] ] ); // Re-index.
 326              $menu_hook           = get_plugin_page_hook( $submenu[ $item[2] ][0][2], $item[2] );
 327              if ( file_exists( WP_PLUGIN_DIR . "/{$submenu[$item[2]][0][2]}" ) || ! empty( $menu_hook ) ) {
 328                  $current_theme_actions[] = "<a class='button$class' href='admin.php?page={$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
 329              } else {
 330                  $current_theme_actions[] = "<a class='button$class' href='{$submenu[$item[2]][0][2]}'>{$item[0]}</a>";
 331              }
 332          } elseif ( ! empty( $item[2] ) && current_user_can( $item[1] ) ) {
 333              $menu_file = $item[2];
 334  
 335              if ( current_user_can( 'customize' ) ) {
 336                  if ( 'custom-header' === $menu_file ) {
 337                      $current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=header_image'>{$item[0]}</a>";
 338                  } elseif ( 'custom-background' === $menu_file ) {
 339                      $current_theme_actions[] = "<a class='button hide-if-no-customize$class' href='customize.php?autofocus[control]=background_image'>{$item[0]}</a>";
 340                  }
 341              }
 342  
 343              $pos = strpos( $menu_file, '?' );
 344              if ( false !== $pos ) {
 345                  $menu_file = substr( $menu_file, 0, $pos );
 346              }
 347  
 348              if ( file_exists( ABSPATH . "wp-admin/$menu_file" ) ) {
 349                  $current_theme_actions[] = "<a class='button$class' href='{$item[2]}'>{$item[0]}</a>";
 350              } else {
 351                  $current_theme_actions[] = "<a class='button$class' href='themes.php?page={$item[2]}'>{$item[0]}</a>";
 352              }
 353          }
 354      }
 355  }
 356  
 357  ?>
 358  
 359  <?php
 360  $class_name = 'theme-browser';
 361  if ( ! empty( $_GET['search'] ) ) {
 362      $class_name .= ' search-loading';
 363  }
 364  ?>
 365  <div class="<?php echo esc_attr( $class_name ); ?>">
 366      <div class="themes wp-clearfix">
 367  
 368  <?php
 369  /*
 370   * This PHP is synchronized with the tmpl-theme template below!
 371   */
 372  
 373  foreach ( $themes as $theme ) :
 374      $aria_action = esc_attr( $theme['id'] . '-action' );
 375      $aria_name   = esc_attr( $theme['id'] . '-name' );
 376  
 377      $active_class = '';
 378      if ( $theme['active'] ) {
 379          $active_class = ' active';
 380      }
 381      ?>
 382  <div class="theme<?php echo $active_class; ?>" tabindex="0" aria-describedby="<?php echo $aria_action . ' ' . $aria_name; ?>">
 383      <?php if ( ! empty( $theme['screenshot'][0] ) ) { ?>
 384          <div class="theme-screenshot">
 385              <img src="<?php echo $theme['screenshot'][0]; ?>" alt="" />
 386          </div>
 387      <?php } else { ?>
 388          <div class="theme-screenshot blank"></div>
 389      <?php } ?>
 390  
 391      <?php if ( $theme['hasUpdate'] ) : ?>
 392          <div class="update-message notice inline notice-warning notice-alt">
 393          <?php if ( $theme['hasPackage'] ) : ?>
 394              <p><?php _e( 'New version available. <button class="button-link" type="button">Update now</button>' ); ?></p>
 395          <?php else : ?>
 396              <p><?php _e( 'New version available.' ); ?></p>
 397          <?php endif; ?>
 398          </div>
 399      <?php endif; ?>
 400  
 401      <span class="more-details" id="<?php echo $aria_action; ?>"><?php _e( 'Theme Details' ); ?></span>
 402      <div class="theme-author">
 403          <?php
 404          /* translators: %s: Theme author name. */
 405          printf( __( 'By %s' ), $theme['author'] );
 406          ?>
 407      </div>
 408  
 409      <div class="theme-id-container">
 410          <?php if ( $theme['active'] ) { ?>
 411              <h2 class="theme-name" id="<?php echo $aria_name; ?>">
 412                  <span><?php _ex( 'Active:', 'theme' ); ?></span> <?php echo $theme['name']; ?>
 413              </h2>
 414          <?php } else { ?>
 415              <h2 class="theme-name" id="<?php echo $aria_name; ?>"><?php echo $theme['name']; ?></h2>
 416          <?php } ?>
 417  
 418          <div class="theme-actions">
 419          <?php if ( $theme['active'] ) { ?>
 420              <?php if ( $theme['actions']['customize'] && current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
 421                  <a class="button button-primary customize load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Customize' ); ?></a>
 422              <?php } ?>
 423          <?php } elseif ( $theme['compatibleWP'] && $theme['compatiblePHP'] ) { ?>
 424              <?php
 425              /* translators: %s: Theme name. */
 426              $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
 427              ?>
 428              <a class="button activate" href="<?php echo $theme['actions']['activate']; ?>" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _e( 'Activate' ); ?></a>
 429              <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
 430                  <a class="button button-primary load-customize hide-if-no-customize" href="<?php echo $theme['actions']['customize']; ?>"><?php _e( 'Live Preview' ); ?></a>
 431              <?php } ?>
 432          <?php } else { ?>
 433              <?php
 434              /* translators: %s: Theme name. */
 435              $aria_label = sprintf( _x( 'Cannot Activate %s', 'theme' ), '{{ data.name }}' );
 436              ?>
 437              <a class="button disabled" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
 438              <?php if ( current_user_can( 'edit_theme_options' ) && current_user_can( 'customize' ) ) { ?>
 439                  <a class="button button-primary hide-if-no-customize disabled"><?php _e( 'Live Preview' ); ?></a>
 440              <?php } ?>
 441          <?php } ?>
 442  
 443          </div>
 444      </div>
 445  </div>
 446  <?php endforeach; ?>
 447      </div>
 448  </div>
 449  <div class="theme-overlay" tabindex="0" role="dialog" aria-label="<?php esc_attr_e( 'Theme Details' ); ?>"></div>
 450  
 451  <p class="no-themes"><?php _e( 'No themes found. Try a different search.' ); ?></p>
 452  
 453  <?php
 454  // List broken themes, if any.
 455  $broken_themes = wp_get_themes( array( 'errors' => true ) );
 456  if ( ! is_multisite() && $broken_themes ) {
 457      ?>
 458  
 459  <div class="broken-themes">
 460  <h3><?php _e( 'Broken Themes' ); ?></h3>
 461  <p><?php _e( 'The following themes are installed but incomplete.' ); ?></p>
 462  
 463      <?php
 464      $can_resume  = current_user_can( 'resume_themes' );
 465      $can_delete  = current_user_can( 'delete_themes' );
 466      $can_install = current_user_can( 'install_themes' );
 467      ?>
 468  <table>
 469      <tr>
 470          <th><?php _ex( 'Name', 'theme name' ); ?></th>
 471          <th><?php _e( 'Description' ); ?></th>
 472          <?php if ( $can_resume ) { ?>
 473              <td></td>
 474          <?php } ?>
 475          <?php if ( $can_delete ) { ?>
 476              <td></td>
 477          <?php } ?>
 478          <?php if ( $can_install ) { ?>
 479              <td></td>
 480          <?php } ?>
 481      </tr>
 482      <?php foreach ( $broken_themes as $broken_theme ) : ?>
 483          <tr>
 484              <td><?php echo $broken_theme->get( 'Name' ) ? $broken_theme->display( 'Name' ) : esc_html( $broken_theme->get_stylesheet() ); ?></td>
 485              <td><?php echo $broken_theme->errors()->get_error_message(); ?></td>
 486              <?php
 487              if ( $can_resume ) {
 488                  if ( 'theme_paused' === $broken_theme->errors()->get_error_code() ) {
 489                      $stylesheet = $broken_theme->get_stylesheet();
 490                      $resume_url = add_query_arg(
 491                          array(
 492                              'action'     => 'resume',
 493                              'stylesheet' => urlencode( $stylesheet ),
 494                          ),
 495                          admin_url( 'themes.php' )
 496                      );
 497                      $resume_url = wp_nonce_url( $resume_url, 'resume-theme_' . $stylesheet );
 498                      ?>
 499                      <td><a href="<?php echo esc_url( $resume_url ); ?>" class="button resume-theme"><?php _e( 'Resume' ); ?></a></td>
 500                      <?php
 501                  } else {
 502                      ?>
 503                      <td></td>
 504                      <?php
 505                  }
 506              }
 507  
 508              if ( $can_delete ) {
 509                  $stylesheet = $broken_theme->get_stylesheet();
 510                  $delete_url = add_query_arg(
 511                      array(
 512                          'action'     => 'delete',
 513                          'stylesheet' => urlencode( $stylesheet ),
 514                      ),
 515                      admin_url( 'themes.php' )
 516                  );
 517                  $delete_url = wp_nonce_url( $delete_url, 'delete-theme_' . $stylesheet );
 518                  ?>
 519                  <td><a href="<?php echo esc_url( $delete_url ); ?>" class="button delete-theme"><?php _e( 'Delete' ); ?></a></td>
 520                  <?php
 521              }
 522  
 523              if ( $can_install && 'theme_no_parent' === $broken_theme->errors()->get_error_code() ) {
 524                  $parent_theme_name = $broken_theme->get( 'Template' );
 525                  $parent_theme      = themes_api( 'theme_information', array( 'slug' => urlencode( $parent_theme_name ) ) );
 526  
 527                  if ( ! is_wp_error( $parent_theme ) ) {
 528                      $install_url = add_query_arg(
 529                          array(
 530                              'action' => 'install-theme',
 531                              'theme'  => urlencode( $parent_theme_name ),
 532                          ),
 533                          admin_url( 'update.php' )
 534                      );
 535                      $install_url = wp_nonce_url( $install_url, 'install-theme_' . $parent_theme_name );
 536                      ?>
 537                      <td><a href="<?php echo esc_url( $install_url ); ?>" class="button install-theme"><?php _e( 'Install Parent Theme' ); ?></a></td>
 538                      <?php
 539                  }
 540              }
 541              ?>
 542          </tr>
 543      <?php endforeach; ?>
 544  </table>
 545  </div>
 546  
 547      <?php
 548  }
 549  ?>
 550  </div><!-- .wrap -->
 551  
 552  <?php
 553  
 554  /**
 555   * Returns the JavaScript template used to display the auto-update setting for a theme.
 556   *
 557   * @since 5.5.0
 558   *
 559   * @return string The template for displaying the auto-update setting link.
 560   */
 561  function wp_theme_auto_update_setting_template() {
 562      $template = '
 563          <div class="theme-autoupdate">
 564              <# if ( data.autoupdate ) { #>
 565                  <a href="{{{ data.actions.autoupdate }}}" class="toggle-auto-update" data-slug="{{ data.id }}" data-wp-action="disable">
 566                      <span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>
 567                      <span class="label">' . __( 'Disable auto-updates' ) . '</span>
 568                  </a>
 569              <# } else { #>
 570                  <a href="{{{ data.actions.autoupdate }}}" class="toggle-auto-update" data-slug="{{ data.id }}" data-wp-action="enable">
 571                      <span class="dashicons dashicons-update spin hidden" aria-hidden="true"></span>
 572                      <span class="label">' . __( 'Enable auto-updates' ) . '</span>
 573                  </a>
 574              <# } #>
 575              <# if ( data.hasUpdate ) { #>
 576                  <# if ( data.autoupdate ) { #>
 577                      <span class="auto-update-time">
 578                  <# } else { #>
 579                      <span class="auto-update-time hidden">
 580                  <# } #>
 581                  <br />' . wp_get_auto_update_message() . '</span>
 582              <# } #>
 583              <div class="notice notice-error notice-alt inline hidden"><p></p></div>
 584          </div>
 585      ';
 586  
 587      /**
 588       * Filters the JavaScript template used to display the auto-update setting for a theme (in the overlay).
 589       *
 590       * See {@see wp_prepare_themes_for_js()} for the properties of the `data` object.
 591       *
 592       * @since 5.5.0
 593       *
 594       * @param string $template The template for displaying the auto-update setting link.
 595       */
 596      return apply_filters( 'theme_auto_update_setting_template', $template );
 597  }
 598  
 599  /*
 600   * The tmpl-theme template is synchronized with PHP above!
 601   */
 602  ?>
 603  <script id="tmpl-theme" type="text/template">
 604      <# if ( data.screenshot[0] ) { #>
 605          <div class="theme-screenshot">
 606              <img src="{{ data.screenshot[0] }}" alt="" />
 607          </div>
 608      <# } else { #>
 609          <div class="theme-screenshot blank"></div>
 610      <# } #>
 611  
 612      <# if ( data.hasUpdate ) { #>
 613          <# if ( data.hasPackage ) { #>
 614              <div class="update-message notice inline notice-warning notice-alt"><p><?php _e( 'New version available. <button class="button-link" type="button">Update now</button>' ); ?></p></div>
 615          <# } else { #>
 616              <div class="update-message notice inline notice-warning notice-alt"><p><?php _e( 'New version available.' ); ?></p></div>
 617          <# } #>
 618      <# } #>
 619  
 620      <span class="more-details" id="{{ data.id }}-action"><?php _e( 'Theme Details' ); ?></span>
 621      <div class="theme-author">
 622          <?php
 623          /* translators: %s: Theme author name. */
 624          printf( __( 'By %s' ), '{{{ data.author }}}' );
 625          ?>
 626      </div>
 627  
 628      <div class="theme-id-container">
 629          <# if ( data.active ) { #>
 630              <h2 class="theme-name" id="{{ data.id }}-name">
 631                  <span><?php _ex( 'Active:', 'theme' ); ?></span> {{{ data.name }}}
 632              </h2>
 633          <# } else { #>
 634              <h2 class="theme-name" id="{{ data.id }}-name">{{{ data.name }}}</h2>
 635          <# } #>
 636  
 637          <div class="theme-actions">
 638              <# if ( data.active ) { #>
 639                  <# if ( data.actions.customize ) { #>
 640                      <a class="button button-primary customize load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Customize' ); ?></a>
 641                  <# } #>
 642              <# } else { #>
 643                  <# if ( data.compatibleWP && data.compatiblePHP ) { #>
 644                      <?php
 645                      /* translators: %s: Theme name. */
 646                      $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
 647                      ?>
 648                      <a class="button activate" href="{{{ data.actions.activate }}}" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
 649                      <a class="button button-primary load-customize hide-if-no-customize" href="{{{ data.actions.customize }}}"><?php _e( 'Live Preview' ); ?></a>
 650                  <# } else { #>
 651                      <?php
 652                      /* translators: %s: Theme name. */
 653                      $aria_label = sprintf( _x( 'Cannot Activate %s', 'theme' ), '{{ data.name }}' );
 654                      ?>
 655                      <a class="button disabled" aria-label="<?php echo esc_attr( $aria_label ); ?>"><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
 656                      <a class="button button-primary hide-if-no-customize disabled"><?php _e( 'Live Preview' ); ?></a>
 657                  <# } #>
 658              <# } #>
 659          </div>
 660      </div>
 661  </script>
 662  
 663  <script id="tmpl-theme-single" type="text/template">
 664      <div class="theme-backdrop"></div>
 665      <div class="theme-wrap wp-clearfix" role="document">
 666          <div class="theme-header">
 667              <button class="left dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show previous theme' ); ?></span></button>
 668              <button class="right dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Show next theme' ); ?></span></button>
 669              <button class="close dashicons dashicons-no"><span class="screen-reader-text"><?php _e( 'Close details dialog' ); ?></span></button>
 670          </div>
 671          <div class="theme-about wp-clearfix">
 672              <div class="theme-screenshots">
 673              <# if ( data.screenshot[0] ) { #>
 674                  <div class="screenshot"><img src="{{ data.screenshot[0] }}" alt="" /></div>
 675              <# } else { #>
 676                  <div class="screenshot blank"></div>
 677              <# } #>
 678              </div>
 679  
 680              <div class="theme-info">
 681                  <# if ( data.active ) { #>
 682                      <span class="current-label"><?php _e( 'Current Theme' ); ?></span>
 683                  <# } #>
 684                  <h2 class="theme-name">{{{ data.name }}}<span class="theme-version">
 685                      <?php
 686                      /* translators: %s: Theme version. */
 687                      printf( __( 'Version: %s' ), '{{ data.version }}' );
 688                      ?>
 689                  </span></h2>
 690                  <p class="theme-author">
 691                      <?php
 692                      /* translators: %s: Theme author link. */
 693                      printf( __( 'By %s' ), '{{{ data.authorAndUri }}}' );
 694                      ?>
 695                  </p>
 696  
 697                  <# if ( data.actions.autoupdate ) { #>
 698                      <?php echo wp_theme_auto_update_setting_template(); ?>
 699                  <# } #>
 700  
 701                  <# if ( data.hasUpdate ) { #>
 702                  <div class="notice notice-warning notice-alt notice-large">
 703                      <h3 class="notice-title"><?php _e( 'Update Available' ); ?></h3>
 704                      {{{ data.update }}}
 705                  </div>
 706                  <# } #>
 707                  <p class="theme-description">{{{ data.description }}}</p>
 708  
 709                  <# if ( data.parent ) { #>
 710                      <p class="parent-theme">
 711                          <?php
 712                          /* translators: %s: Theme name. */
 713                          printf( __( 'This is a child theme of %s.' ), '<strong>{{{ data.parent }}}</strong>' );
 714                          ?>
 715                      </p>
 716                  <# } #>
 717  
 718                  <# if ( data.tags ) { #>
 719                      <p class="theme-tags"><span><?php _e( 'Tags:' ); ?></span> {{{ data.tags }}}</p>
 720                  <# } #>
 721              </div>
 722          </div>
 723  
 724          <div class="theme-actions">
 725              <div class="active-theme">
 726                  <a href="{{{ data.actions.customize }}}" class="button button-primary customize load-customize hide-if-no-customize"><?php _e( 'Customize' ); ?></a>
 727                  <?php echo implode( ' ', $current_theme_actions ); ?>
 728              </div>
 729              <div class="inactive-theme">
 730                  <# if ( data.compatibleWP && data.compatiblePHP ) { #>
 731                      <?php
 732                      /* translators: %s: Theme name. */
 733                      $aria_label = sprintf( _x( 'Activate %s', 'theme' ), '{{ data.name }}' );
 734                      ?>
 735                      <# if ( data.actions.activate ) { #>
 736                          <a href="{{{ data.actions.activate }}}" class="button activate" aria-label="<?php echo $aria_label; ?>"><?php _e( 'Activate' ); ?></a>
 737                      <# } #>
 738                      <a href="{{{ data.actions.customize }}}" class="button button-primary load-customize hide-if-no-customize"><?php _e( 'Live Preview' ); ?></a>
 739                  <# } else { #>
 740                      <?php
 741                      /* translators: %s: Theme name. */
 742                      $aria_label = sprintf( _x( 'Cannot Activate %s', 'theme' ), '{{ data.name }}' );
 743                      ?>
 744                      <# if ( data.actions.activate ) { #>
 745                          <a class="button disabled" aria-label="<?php echo $aria_label; ?>"><?php _ex( 'Cannot Activate', 'theme' ); ?></a>
 746                      <# } #>
 747                      <a class="button button-primary hide-if-no-customize disabled"><?php _e( 'Live Preview' ); ?></a>
 748                  <# } #>
 749              </div>
 750  
 751              <# if ( ! data.active && data.actions['delete'] ) { #>
 752                  <a href="{{{ data.actions['delete'] }}}" class="button delete-theme"><?php _e( 'Delete' ); ?></a>
 753              <# } #>
 754          </div>
 755      </div>
 756  </script>
 757  
 758  <?php
 759  wp_print_request_filesystem_credentials_modal();
 760  wp_print_admin_notice_templates();
 761  wp_print_update_row_templates();
 762  
 763  wp_localize_script(
 764      'updates',
 765      '_wpUpdatesItemCounts',
 766      array(
 767          'totals' => wp_get_update_data(),
 768      )
 769  );
 770  
 771  require_once ABSPATH . 'wp-admin/admin-footer.php';


Generated: Thu Jul 9 01:00:03 2020 Cross-referenced by PHPXref 0.7.1