[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

   1  <?php
   2  /**
   3   * Multisite themes administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Multisite
   7   * @since 3.1.0
   8   */
   9  
  10  /** Load WordPress Administration Bootstrap */
  11  require_once  __DIR__ . '/admin.php';
  12  
  13  if ( ! current_user_can( 'manage_network_themes' ) ) {
  14      wp_die( __( 'Sorry, you are not allowed to manage network themes.' ) );
  15  }
  16  
  17  $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
  18  $pagenum       = $wp_list_table->get_pagenum();
  19  
  20  $action = $wp_list_table->current_action();
  21  
  22  $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
  23  
  24  // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
  25  $temp_args = array(
  26      'enabled',
  27      'disabled',
  28      'deleted',
  29      'error',
  30      'enabled-auto-update',
  31      'disabled-auto-update',
  32  );
  33  
  34  $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  35  $referer                = remove_query_arg( $temp_args, wp_get_referer() );
  36  
  37  if ( $action ) {
  38      switch ( $action ) {
  39          case 'enable':
  40              check_admin_referer( 'enable-theme_' . $_GET['theme'] );
  41              WP_Theme::network_enable_theme( $_GET['theme'] );
  42              if ( false === strpos( $referer, '/network/themes.php' ) ) {
  43                  wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
  44              } else {
  45                  wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
  46              }
  47              exit;
  48          case 'disable':
  49              check_admin_referer( 'disable-theme_' . $_GET['theme'] );
  50              WP_Theme::network_disable_theme( $_GET['theme'] );
  51              wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
  52              exit;
  53          case 'enable-selected':
  54              check_admin_referer( 'bulk-themes' );
  55              $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  56              if ( empty( $themes ) ) {
  57                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  58                  exit;
  59              }
  60              WP_Theme::network_enable_theme( (array) $themes );
  61              wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
  62              exit;
  63          case 'disable-selected':
  64              check_admin_referer( 'bulk-themes' );
  65              $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  66              if ( empty( $themes ) ) {
  67                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  68                  exit;
  69              }
  70              WP_Theme::network_disable_theme( (array) $themes );
  71              wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
  72              exit;
  73          case 'update-selected':
  74              check_admin_referer( 'bulk-themes' );
  75  
  76              if ( isset( $_GET['themes'] ) ) {
  77                  $themes = explode( ',', $_GET['themes'] );
  78              } elseif ( isset( $_POST['checked'] ) ) {
  79                  $themes = (array) $_POST['checked'];
  80              } else {
  81                  $themes = array();
  82              }
  83  
  84              // Used in the HTML title tag.
  85              $title       = __( 'Update Themes' );
  86              $parent_file = 'themes.php';
  87  
  88              require_once ABSPATH . 'wp-admin/admin-header.php';
  89  
  90              echo '<div class="wrap">';
  91              echo '<h1>' . esc_html( $title ) . '</h1>';
  92  
  93              $url = self_admin_url( 'update.php?action=update-selected-themes&amp;themes=' . urlencode( implode( ',', $themes ) ) );
  94              $url = wp_nonce_url( $url, 'bulk-update-themes' );
  95  
  96              echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
  97              echo '</div>';
  98              require_once ABSPATH . 'wp-admin/admin-footer.php';
  99              exit;
 100          case 'delete-selected':
 101              if ( ! current_user_can( 'delete_themes' ) ) {
 102                  wp_die( __( 'Sorry, you are not allowed to delete themes for this site.' ) );
 103              }
 104  
 105              check_admin_referer( 'bulk-themes' );
 106  
 107              $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
 108  
 109              if ( empty( $themes ) ) {
 110                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 111                  exit;
 112              }
 113  
 114              $themes = array_diff( $themes, array( get_option( 'stylesheet' ), get_option( 'template' ) ) );
 115  
 116              if ( empty( $themes ) ) {
 117                  wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
 118                  exit;
 119              }
 120  
 121              $theme_info = array();
 122              foreach ( $themes as $key => $theme ) {
 123                  $theme_info[ $theme ] = wp_get_theme( $theme );
 124              }
 125  
 126              require ABSPATH . 'wp-admin/update.php';
 127  
 128              $parent_file = 'themes.php';
 129  
 130              if ( ! isset( $_REQUEST['verify-delete'] ) ) {
 131                  wp_enqueue_script( 'jquery' );
 132                  require_once ABSPATH . 'wp-admin/admin-header.php';
 133                  $themes_to_delete = count( $themes );
 134                  ?>
 135                  <div class="wrap">
 136                  <?php if ( 1 === $themes_to_delete ) : ?>
 137                      <h1><?php _e( 'Delete Theme' ); ?></h1>
 138                      <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'This theme may be active on other sites in the network.' ); ?></p></div>
 139                      <p><?php _e( 'You are about to remove the following theme:' ); ?></p>
 140                  <?php else : ?>
 141                      <h1><?php _e( 'Delete Themes' ); ?></h1>
 142                      <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These themes may be active on other sites in the network.' ); ?></p></div>
 143                      <p><?php _e( 'You are about to remove the following themes:' ); ?></p>
 144                  <?php endif; ?>
 145                      <ul class="ul-disc">
 146                      <?php
 147                      foreach ( $theme_info as $theme ) {
 148                          echo '<li>' . sprintf(
 149                              /* translators: 1: Theme name, 2: Theme author. */
 150                              _x( '%1$s by %2$s', 'theme' ),
 151                              '<strong>' . $theme->display( 'Name' ) . '</strong>',
 152                              '<em>' . $theme->display( 'Author' ) . '</em>'
 153                          ) . '</li>';
 154                      }
 155                      ?>
 156                      </ul>
 157                  <?php if ( 1 === $themes_to_delete ) : ?>
 158                      <p><?php _e( 'Are you sure you want to delete this theme?' ); ?></p>
 159                  <?php else : ?>
 160                      <p><?php _e( 'Are you sure you want to delete these themes?' ); ?></p>
 161                  <?php endif; ?>
 162                  <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" style="display:inline;">
 163                      <input type="hidden" name="verify-delete" value="1" />
 164                      <input type="hidden" name="action" value="delete-selected" />
 165                      <?php
 166  
 167                      foreach ( (array) $themes as $theme ) {
 168                          echo '<input type="hidden" name="checked[]" value="' . esc_attr( $theme ) . '" />';
 169                      }
 170  
 171                      wp_nonce_field( 'bulk-themes' );
 172  
 173                      if ( 1 === $themes_to_delete ) {
 174                          submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
 175                      } else {
 176                          submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
 177                      }
 178  
 179                      ?>
 180                  </form>
 181                  <?php $referer = wp_get_referer(); ?>
 182                  <form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
 183                      <?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?>
 184                  </form>
 185                  </div>
 186                  <?php
 187  
 188                  require_once ABSPATH . 'wp-admin/admin-footer.php';
 189                  exit;
 190              } // End if verify-delete.
 191  
 192              foreach ( $themes as $theme ) {
 193                  $delete_result = delete_theme(
 194                      $theme,
 195                      esc_url(
 196                          add_query_arg(
 197                              array(
 198                                  'verify-delete' => 1,
 199                                  'action'        => 'delete-selected',
 200                                  'checked'       => $_REQUEST['checked'],
 201                                  '_wpnonce'      => $_REQUEST['_wpnonce'],
 202                              ),
 203                              network_admin_url( 'themes.php' )
 204                          )
 205                      )
 206                  );
 207              }
 208  
 209              $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
 210              wp_redirect(
 211                  add_query_arg(
 212                      array(
 213                          'deleted' => count( $themes ),
 214                          'paged'   => $paged,
 215                          's'       => $s,
 216                      ),
 217                      network_admin_url( 'themes.php' )
 218                  )
 219              );
 220              exit;
 221          case 'enable-auto-update':
 222          case 'disable-auto-update':
 223          case 'enable-auto-update-selected':
 224          case 'disable-auto-update-selected':
 225              if ( ! ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) ) {
 226                  wp_die( __( 'Sorry, you are not allowed to change themes automatic update settings.' ) );
 227              }
 228  
 229              if ( 'enable-auto-update' === $action || 'disable-auto-update' === $action ) {
 230                  check_admin_referer( 'updates' );
 231              } else {
 232                  if ( empty( $_POST['checked'] ) ) {
 233                      // Nothing to do.
 234                      wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 235                      exit;
 236                  }
 237  
 238                  check_admin_referer( 'bulk-themes' );
 239              }
 240  
 241              $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
 242  
 243              if ( 'enable-auto-update' === $action ) {
 244                  $auto_updates[] = $_GET['theme'];
 245                  $auto_updates   = array_unique( $auto_updates );
 246                  $referer        = add_query_arg( 'enabled-auto-update', 1, $referer );
 247              } elseif ( 'disable-auto-update' === $action ) {
 248                  $auto_updates = array_diff( $auto_updates, array( $_GET['theme'] ) );
 249                  $referer      = add_query_arg( 'disabled-auto-update', 1, $referer );
 250              } else {
 251                  // Bulk enable/disable.
 252                  $themes = (array) wp_unslash( $_POST['checked'] );
 253  
 254                  if ( 'enable-auto-update-selected' === $action ) {
 255                      $auto_updates = array_merge( $auto_updates, $themes );
 256                      $auto_updates = array_unique( $auto_updates );
 257                      $referer      = add_query_arg( 'enabled-auto-update', count( $themes ), $referer );
 258                  } else {
 259                      $auto_updates = array_diff( $auto_updates, $themes );
 260                      $referer      = add_query_arg( 'disabled-auto-update', count( $themes ), $referer );
 261                  }
 262              }
 263  
 264              $all_items = wp_get_themes();
 265  
 266              // Remove themes that don't exist or have been deleted since the option was last updated.
 267              $auto_updates = array_intersect( $auto_updates, array_keys( $all_items ) );
 268  
 269              update_site_option( 'auto_update_themes', $auto_updates );
 270  
 271              wp_safe_redirect( $referer );
 272              exit;
 273          default:
 274              $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
 275              if ( empty( $themes ) ) {
 276                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 277                  exit;
 278              }
 279              check_admin_referer( 'bulk-themes' );
 280  
 281              /** This action is documented in wp-admin/network/site-themes.php */
 282              $referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 283  
 284              wp_safe_redirect( $referer );
 285              exit;
 286      }
 287  }
 288  
 289  $wp_list_table->prepare_items();
 290  
 291  add_thickbox();
 292  
 293  add_screen_option( 'per_page' );
 294  
 295  get_current_screen()->add_help_tab(
 296      array(
 297          'id'      => 'overview',
 298          'title'   => __( 'Overview' ),
 299          'content' =>
 300              '<p>' . __( 'This screen enables and disables the inclusion of themes available to choose in the Appearance menu for each site. It does not activate or deactivate which theme a site is currently using.' ) . '</p>' .
 301              '<p>' . __( 'If the network admin disables a theme that is in use, it can still remain selected on that site. If another theme is chosen, the disabled theme will not appear in the site&#8217;s Appearance > Themes screen.' ) . '</p>' .
 302              '<p>' . __( 'Themes can be enabled on a site by site basis by the network admin on the Edit Site screen (which has a Themes tab); get there via the Edit action link on the All Sites screen. Only network admins are able to install or edit themes.' ) . '</p>',
 303      )
 304  );
 305  
 306  $help_sidebar_autoupdates = '';
 307  
 308  if ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) {
 309      get_current_screen()->add_help_tab(
 310          array(
 311              'id'      => 'plugins-themes-auto-updates',
 312              'title'   => __( 'Auto-updates' ),
 313              'content' =>
 314                  '<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>' .
 315                  '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>',
 316          )
 317      );
 318  
 319      $help_sidebar_autoupdates = '<p>' . __( '<a href="https://wordpress.org/support/article/plugins-themes-auto-updates/">Learn more: Auto-updates documentation</a>' ) . '</p>';
 320  }
 321  
 322  get_current_screen()->set_help_sidebar(
 323      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 324      '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>' ) . '</p>' .
 325      $help_sidebar_autoupdates .
 326      '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
 327  );
 328  
 329  get_current_screen()->set_screen_reader_content(
 330      array(
 331          'heading_views'      => __( 'Filter themes list' ),
 332          'heading_pagination' => __( 'Themes list navigation' ),
 333          'heading_list'       => __( 'Themes list' ),
 334      )
 335  );
 336  
 337  // Used in the HTML title tag.
 338  $title       = __( 'Themes' );
 339  $parent_file = 'themes.php';
 340  
 341  wp_enqueue_script( 'updates' );
 342  wp_enqueue_script( 'theme-preview' );
 343  
 344  require_once ABSPATH . 'wp-admin/admin-header.php';
 345  
 346  ?>
 347  
 348  <div class="wrap">
 349  <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
 350  
 351  <?php if ( current_user_can( 'install_themes' ) ) : ?>
 352      <a href="theme-install.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'theme' ); ?></a>
 353  <?php endif; ?>
 354  
 355  <?php
 356  if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
 357      echo '<span class="subtitle">';
 358      printf(
 359          /* translators: %s: Search query. */
 360          __( 'Search results for: %s' ),
 361          '<strong>' . esc_html( $s ) . '</strong>'
 362      );
 363      echo '</span>';
 364  }
 365  ?>
 366  
 367  <hr class="wp-header-end">
 368  
 369  <?php
 370  if ( isset( $_GET['enabled'] ) ) {
 371      $enabled = absint( $_GET['enabled'] );
 372      if ( 1 === $enabled ) {
 373          $message = __( 'Theme enabled.' );
 374      } else {
 375          /* translators: %s: Number of themes. */
 376          $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
 377      }
 378      echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
 379  } elseif ( isset( $_GET['disabled'] ) ) {
 380      $disabled = absint( $_GET['disabled'] );
 381      if ( 1 === $disabled ) {
 382          $message = __( 'Theme disabled.' );
 383      } else {
 384          /* translators: %s: Number of themes. */
 385          $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
 386      }
 387      echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
 388  } elseif ( isset( $_GET['deleted'] ) ) {
 389      $deleted = absint( $_GET['deleted'] );
 390      if ( 1 === $deleted ) {
 391          $message = __( 'Theme deleted.' );
 392      } else {
 393          /* translators: %s: Number of themes. */
 394          $message = _n( '%s theme deleted.', '%s themes deleted.', $deleted );
 395      }
 396      echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $deleted ) ) . '</p></div>';
 397  } elseif ( isset( $_GET['enabled-auto-update'] ) ) {
 398      $enabled = absint( $_GET['enabled-auto-update'] );
 399      if ( 1 === $enabled ) {
 400          $message = __( 'Theme will be auto-updated.' );
 401      } else {
 402          /* translators: %s: Number of themes. */
 403          $message = _n( '%s theme will be auto-updated.', '%s themes will be auto-updated.', $enabled );
 404      }
 405      echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
 406  } elseif ( isset( $_GET['disabled-auto-update'] ) ) {
 407      $disabled = absint( $_GET['disabled-auto-update'] );
 408      if ( 1 === $disabled ) {
 409          $message = __( 'Theme will no longer be auto-updated.' );
 410      } else {
 411          /* translators: %s: Number of themes. */
 412          $message = _n( '%s theme will no longer be auto-updated.', '%s themes will no longer be auto-updated.', $disabled );
 413      }
 414      echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
 415  } elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) {
 416      echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
 417  } elseif ( isset( $_GET['error'] ) && 'main' === $_GET['error'] ) {
 418      echo '<div class="error notice is-dismissible"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
 419  }
 420  
 421  ?>
 422  
 423  <form method="get">
 424  <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
 425  </form>
 426  
 427  <?php
 428  $wp_list_table->views();
 429  
 430  if ( 'broken' === $status ) {
 431      echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
 432  }
 433  ?>
 434  
 435  <form id="bulk-action-form" method="post">
 436  <input type="hidden" name="theme_status" value="<?php echo esc_attr( $status ); ?>" />
 437  <input type="hidden" name="paged" value="<?php echo esc_attr( $page ); ?>" />
 438  
 439  <?php $wp_list_table->display(); ?>
 440  </form>
 441  
 442  </div>
 443  
 444  <?php
 445  wp_print_request_filesystem_credentials_modal();
 446  wp_print_admin_notice_templates();
 447  wp_print_update_row_templates();
 448  
 449  require_once ABSPATH . 'wp-admin/admin-footer.php';


Generated: Thu Nov 21 01:00:03 2024 Cross-referenced by PHPXref 0.7.1