[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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 ( ! str_contains( $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                      <?php
 139                      wp_admin_notice(
 140                          '<strong>' . __( 'Caution:' ) . '</strong> ' . __( 'This theme may be active on other sites in the network.' ),
 141                          array(
 142                              'additional_classes' => array( 'error' ),
 143                          )
 144                      );
 145                      ?>
 146                      <p><?php _e( 'You are about to remove the following theme:' ); ?></p>
 147                  <?php else : ?>
 148                      <h1><?php _e( 'Delete Themes' ); ?></h1>
 149                      <?php
 150                      wp_admin_notice(
 151                          '<strong>' . __( 'Caution:' ) . '</strong> ' . __( 'These themes may be active on other sites in the network.' ),
 152                          array(
 153                              'additional_classes' => array( 'error' ),
 154                          )
 155                      );
 156                      ?>
 157                      <p><?php _e( 'You are about to remove the following themes:' ); ?></p>
 158                  <?php endif; ?>
 159                      <ul class="ul-disc">
 160                      <?php
 161                      foreach ( $theme_info as $theme ) {
 162                          echo '<li>' . sprintf(
 163                              /* translators: 1: Theme name, 2: Theme author. */
 164                              _x( '%1$s by %2$s', 'theme' ),
 165                              '<strong>' . $theme->display( 'Name' ) . '</strong>',
 166                              '<em>' . $theme->display( 'Author' ) . '</em>'
 167                          ) . '</li>';
 168                      }
 169                      ?>
 170                      </ul>
 171                  <?php if ( 1 === $themes_to_delete ) : ?>
 172                      <p><?php _e( 'Are you sure you want to delete this theme?' ); ?></p>
 173                  <?php else : ?>
 174                      <p><?php _e( 'Are you sure you want to delete these themes?' ); ?></p>
 175                  <?php endif; ?>
 176                  <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" style="display:inline;">
 177                      <input type="hidden" name="verify-delete" value="1" />
 178                      <input type="hidden" name="action" value="delete-selected" />
 179                      <?php
 180  
 181                      foreach ( (array) $themes as $theme ) {
 182                          echo '<input type="hidden" name="checked[]" value="' . esc_attr( $theme ) . '" />';
 183                      }
 184  
 185                      wp_nonce_field( 'bulk-themes' );
 186  
 187                      if ( 1 === $themes_to_delete ) {
 188                          submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
 189                      } else {
 190                          submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
 191                      }
 192  
 193                      ?>
 194                  </form>
 195                  <?php $referer = wp_get_referer(); ?>
 196                  <form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
 197                      <?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?>
 198                  </form>
 199                  </div>
 200                  <?php
 201  
 202                  require_once  ABSPATH . 'wp-admin/admin-footer.php';
 203                  exit;
 204              } // End if verify-delete.
 205  
 206              foreach ( $themes as $theme ) {
 207                  $delete_result = delete_theme(
 208                      $theme,
 209                      esc_url(
 210                          add_query_arg(
 211                              array(
 212                                  'verify-delete' => 1,
 213                                  'action'        => 'delete-selected',
 214                                  'checked'       => $_REQUEST['checked'],
 215                                  '_wpnonce'      => $_REQUEST['_wpnonce'],
 216                              ),
 217                              network_admin_url( 'themes.php' )
 218                          )
 219                      )
 220                  );
 221              }
 222  
 223              $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
 224              wp_redirect(
 225                  add_query_arg(
 226                      array(
 227                          'deleted' => count( $themes ),
 228                          'paged'   => $paged,
 229                          's'       => $s,
 230                      ),
 231                      network_admin_url( 'themes.php' )
 232                  )
 233              );
 234              exit;
 235          case 'enable-auto-update':
 236          case 'disable-auto-update':
 237          case 'enable-auto-update-selected':
 238          case 'disable-auto-update-selected':
 239              if ( ! ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) ) {
 240                  wp_die( __( 'Sorry, you are not allowed to change themes automatic update settings.' ) );
 241              }
 242  
 243              if ( 'enable-auto-update' === $action || 'disable-auto-update' === $action ) {
 244                  check_admin_referer( 'updates' );
 245              } else {
 246                  if ( empty( $_POST['checked'] ) ) {
 247                      // Nothing to do.
 248                      wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 249                      exit;
 250                  }
 251  
 252                  check_admin_referer( 'bulk-themes' );
 253              }
 254  
 255              $auto_updates = (array) get_site_option( 'auto_update_themes', array() );
 256  
 257              if ( 'enable-auto-update' === $action ) {
 258                  $auto_updates[] = $_GET['theme'];
 259                  $auto_updates   = array_unique( $auto_updates );
 260                  $referer        = add_query_arg( 'enabled-auto-update', 1, $referer );
 261              } elseif ( 'disable-auto-update' === $action ) {
 262                  $auto_updates = array_diff( $auto_updates, array( $_GET['theme'] ) );
 263                  $referer      = add_query_arg( 'disabled-auto-update', 1, $referer );
 264              } else {
 265                  // Bulk enable/disable.
 266                  $themes = (array) wp_unslash( $_POST['checked'] );
 267  
 268                  if ( 'enable-auto-update-selected' === $action ) {
 269                      $auto_updates = array_merge( $auto_updates, $themes );
 270                      $auto_updates = array_unique( $auto_updates );
 271                      $referer      = add_query_arg( 'enabled-auto-update', count( $themes ), $referer );
 272                  } else {
 273                      $auto_updates = array_diff( $auto_updates, $themes );
 274                      $referer      = add_query_arg( 'disabled-auto-update', count( $themes ), $referer );
 275                  }
 276              }
 277  
 278              $all_items = wp_get_themes();
 279  
 280              // Remove themes that don't exist or have been deleted since the option was last updated.
 281              $auto_updates = array_intersect( $auto_updates, array_keys( $all_items ) );
 282  
 283              update_site_option( 'auto_update_themes', $auto_updates );
 284  
 285              wp_safe_redirect( $referer );
 286              exit;
 287          default:
 288              $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
 289              if ( empty( $themes ) ) {
 290                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 291                  exit;
 292              }
 293              check_admin_referer( 'bulk-themes' );
 294  
 295              /** This action is documented in wp-admin/network/site-themes.php */
 296              $referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 297  
 298              wp_safe_redirect( $referer );
 299              exit;
 300      }
 301  }
 302  
 303  $wp_list_table->prepare_items();
 304  
 305  add_thickbox();
 306  
 307  add_screen_option( 'per_page' );
 308  
 309  get_current_screen()->add_help_tab(
 310      array(
 311          'id'      => 'overview',
 312          'title'   => __( 'Overview' ),
 313          'content' =>
 314              '<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>' .
 315              '<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>' .
 316              '<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>',
 317      )
 318  );
 319  
 320  $help_sidebar_autoupdates = '';
 321  
 322  if ( current_user_can( 'update_themes' ) && wp_is_auto_update_enabled_for_type( 'theme' ) ) {
 323      get_current_screen()->add_help_tab(
 324          array(
 325              'id'      => 'plugins-themes-auto-updates',
 326              'title'   => __( 'Auto-updates' ),
 327              'content' =>
 328                  '<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>' .
 329                  '<p>' . __( 'Please note: Third-party themes and plugins, or custom code, may override WordPress scheduling.' ) . '</p>',
 330          )
 331      );
 332  
 333      $help_sidebar_autoupdates = '<p>' . __( '<a href="https://wordpress.org/documentation/article/plugins-themes-auto-updates/">Documentation on Auto-updates</a>' ) . '</p>';
 334  }
 335  
 336  get_current_screen()->set_help_sidebar(
 337      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 338      '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>' ) . '</p>' .
 339      $help_sidebar_autoupdates .
 340      '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
 341  );
 342  
 343  get_current_screen()->set_screen_reader_content(
 344      array(
 345          'heading_views'      => __( 'Filter themes list' ),
 346          'heading_pagination' => __( 'Themes list navigation' ),
 347          'heading_list'       => __( 'Themes list' ),
 348      )
 349  );
 350  
 351  // Used in the HTML title tag.
 352  $title       = __( 'Themes' );
 353  $parent_file = 'themes.php';
 354  
 355  wp_enqueue_script( 'updates' );
 356  wp_enqueue_script( 'theme-preview' );
 357  
 358  require_once  ABSPATH . 'wp-admin/admin-header.php';
 359  
 360  ?>
 361  
 362  <div class="wrap">
 363  <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
 364  
 365  <?php if ( current_user_can( 'install_themes' ) ) : ?>
 366      <a href="theme-install.php" class="page-title-action"><?php echo esc_html__( 'Add New Theme' ); ?></a>
 367  <?php endif; ?>
 368  
 369  <?php
 370  if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
 371      echo '<span class="subtitle">';
 372      printf(
 373          /* translators: %s: Search query. */
 374          __( 'Search results for: %s' ),
 375          '<strong>' . esc_html( $s ) . '</strong>'
 376      );
 377      echo '</span>';
 378  }
 379  ?>
 380  
 381  <hr class="wp-header-end">
 382  
 383  <?php
 384  $message = '';
 385  $type    = 'success';
 386  
 387  if ( isset( $_GET['enabled'] ) ) {
 388      $enabled = absint( $_GET['enabled'] );
 389      if ( 1 === $enabled ) {
 390          $message = __( 'Theme enabled.' );
 391      } else {
 392          $message = sprintf(
 393              /* translators: %s: Number of themes. */
 394              _n( '%s theme enabled.', '%s themes enabled.', $enabled ),
 395              number_format_i18n( $enabled )
 396          );
 397      }
 398  } elseif ( isset( $_GET['disabled'] ) ) {
 399      $disabled = absint( $_GET['disabled'] );
 400      if ( 1 === $disabled ) {
 401          $message = __( 'Theme disabled.' );
 402      } else {
 403          $message = sprintf(
 404              /* translators: %s: Number of themes. */
 405              _n( '%s theme disabled.', '%s themes disabled.', $disabled ),
 406              number_format_i18n( $disabled )
 407          );
 408      }
 409  } elseif ( isset( $_GET['deleted'] ) ) {
 410      $deleted = absint( $_GET['deleted'] );
 411      if ( 1 === $deleted ) {
 412          $message = __( 'Theme deleted.' );
 413      } else {
 414          $message = sprintf(
 415              /* translators: %s: Number of themes. */
 416              _n( '%s theme deleted.', '%s themes deleted.', $deleted ),
 417              number_format_i18n( $deleted )
 418          );
 419      }
 420  } elseif ( isset( $_GET['enabled-auto-update'] ) ) {
 421      $enabled = absint( $_GET['enabled-auto-update'] );
 422      if ( 1 === $enabled ) {
 423          $message = __( 'Theme will be auto-updated.' );
 424      } else {
 425          $message = sprintf(
 426              /* translators: %s: Number of themes. */
 427              _n( '%s theme will be auto-updated.', '%s themes will be auto-updated.', $enabled ),
 428              number_format_i18n( $enabled )
 429          );
 430      }
 431  } elseif ( isset( $_GET['disabled-auto-update'] ) ) {
 432      $disabled = absint( $_GET['disabled-auto-update'] );
 433      if ( 1 === $disabled ) {
 434          $message = __( 'Theme will no longer be auto-updated.' );
 435      } else {
 436          $message = sprintf(
 437              /* translators: %s: Number of themes. */
 438              _n( '%s theme will no longer be auto-updated.', '%s themes will no longer be auto-updated.', $disabled ),
 439              number_format_i18n( $disabled )
 440          );
 441      }
 442  } elseif ( isset( $_GET['error'] ) && 'none' === $_GET['error'] ) {
 443      $message = __( 'No theme selected.' );
 444      $type    = 'error';
 445  } elseif ( isset( $_GET['error'] ) && 'main' === $_GET['error'] ) {
 446      $message = __( 'You cannot delete a theme while it is active on the main site.' );
 447      $type    = 'error';
 448  }
 449  
 450  if ( '' !== $message ) {
 451      wp_admin_notice(
 452          $message,
 453          array(
 454              'type'        => $type,
 455              'dismissible' => true,
 456              'id'          => 'message',
 457          )
 458      );
 459  }
 460  ?>
 461  
 462  <form method="get">
 463  <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
 464  </form>
 465  
 466  <?php
 467  $wp_list_table->views();
 468  
 469  if ( 'broken' === $status ) {
 470      echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
 471  }
 472  ?>
 473  
 474  <form id="bulk-action-form" method="post">
 475  <input type="hidden" name="theme_status" value="<?php echo esc_attr( $status ); ?>" />
 476  <input type="hidden" name="paged" value="<?php echo esc_attr( $page ); ?>" />
 477  
 478  <?php $wp_list_table->display(); ?>
 479  </form>
 480  
 481  </div>
 482  
 483  <?php
 484  wp_print_request_filesystem_credentials_modal();
 485  wp_print_admin_notice_templates();
 486  wp_print_update_row_templates();
 487  
 488  require_once  ABSPATH . 'wp-admin/admin-footer.php';


Generated : Mon Mar 18 08:20:01 2024 Cross-referenced by PHPXref