[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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( dirname( __FILE__ ) . '/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( 'enabled', 'disabled', 'deleted', 'error' );
  26  $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
  27  $referer                = remove_query_arg( $temp_args, wp_get_referer() );
  28  
  29  if ( $action ) {
  30      switch ( $action ) {
  31          case 'enable':
  32              check_admin_referer( 'enable-theme_' . $_GET['theme'] );
  33              WP_Theme::network_enable_theme( $_GET['theme'] );
  34              if ( false === strpos( $referer, '/network/themes.php' ) ) {
  35                  wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
  36              } else {
  37                  wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
  38              }
  39              exit;
  40          case 'disable':
  41              check_admin_referer( 'disable-theme_' . $_GET['theme'] );
  42              WP_Theme::network_disable_theme( $_GET['theme'] );
  43              wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
  44              exit;
  45          case 'enable-selected':
  46              check_admin_referer( 'bulk-themes' );
  47              $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  48              if ( empty( $themes ) ) {
  49                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  50                  exit;
  51              }
  52              WP_Theme::network_enable_theme( (array) $themes );
  53              wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
  54              exit;
  55          case 'disable-selected':
  56              check_admin_referer( 'bulk-themes' );
  57              $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
  58              if ( empty( $themes ) ) {
  59                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
  60                  exit;
  61              }
  62              WP_Theme::network_disable_theme( (array) $themes );
  63              wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
  64              exit;
  65          case 'update-selected':
  66              check_admin_referer( 'bulk-themes' );
  67  
  68              if ( isset( $_GET['themes'] ) ) {
  69                  $themes = explode( ',', $_GET['themes'] );
  70              } elseif ( isset( $_POST['checked'] ) ) {
  71                  $themes = (array) $_POST['checked'];
  72              } else {
  73                  $themes = array();
  74              }
  75  
  76              $title       = __( 'Update Themes' );
  77              $parent_file = 'themes.php';
  78  
  79              require_once ( ABSPATH . 'wp-admin/admin-header.php' );
  80  
  81              echo '<div class="wrap">';
  82              echo '<h1>' . esc_html( $title ) . '</h1>';
  83  
  84              $url = self_admin_url( 'update.php?action=update-selected-themes&amp;themes=' . urlencode( join( ',', $themes ) ) );
  85              $url = wp_nonce_url( $url, 'bulk-update-themes' );
  86  
  87              echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
  88              echo '</div>';
  89              require_once ( ABSPATH . 'wp-admin/admin-footer.php' );
  90              exit;
  91          case 'delete-selected':
  92              if ( ! current_user_can( 'delete_themes' ) ) {
  93                  wp_die( __( 'Sorry, you are not allowed to delete themes for this site.' ) );
  94              }
  95  
  96              check_admin_referer( 'bulk-themes' );
  97  
  98              $themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
  99  
 100              if ( empty( $themes ) ) {
 101                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 102                  exit;
 103              }
 104  
 105              $themes = array_diff( $themes, array( get_option( 'stylesheet' ), get_option( 'template' ) ) );
 106  
 107              if ( empty( $themes ) ) {
 108                  wp_safe_redirect( add_query_arg( 'error', 'main', $referer ) );
 109                  exit;
 110              }
 111  
 112              $theme_info = array();
 113              foreach ( $themes as $key => $theme ) {
 114                  $theme_info[ $theme ] = wp_get_theme( $theme );
 115              }
 116  
 117              include ( ABSPATH . 'wp-admin/update.php' );
 118  
 119              $parent_file = 'themes.php';
 120  
 121              if ( ! isset( $_REQUEST['verify-delete'] ) ) {
 122                  wp_enqueue_script( 'jquery' );
 123                  require_once ( ABSPATH . 'wp-admin/admin-header.php' );
 124                  $themes_to_delete = count( $themes );
 125                  ?>
 126              <div class="wrap">
 127                  <?php if ( 1 == $themes_to_delete ) : ?>
 128                      <h1><?php _e( 'Delete Theme' ); ?></h1>
 129                      <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'This theme may be active on other sites in the network.' ); ?></p></div>
 130                      <p><?php _e( 'You are about to remove the following theme:' ); ?></p>
 131                  <?php else : ?>
 132                      <h1><?php _e( 'Delete Themes' ); ?></h1>
 133                      <div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These themes may be active on other sites in the network.' ); ?></p></div>
 134                      <p><?php _e( 'You are about to remove the following themes:' ); ?></p>
 135                  <?php endif; ?>
 136                      <ul class="ul-disc">
 137                      <?php
 138                      foreach ( $theme_info as $theme ) {
 139                          echo '<li>' . sprintf(
 140                              /* translators: 1: Theme name, 2: Theme author. */
 141                              _x( '%1$s by %2$s', 'theme' ),
 142                              '<strong>' . $theme->display( 'Name' ) . '</strong>',
 143                              '<em>' . $theme->display( 'Author' ) . '</em>'
 144                          ) . '</li>';
 145                      }
 146                      ?>
 147                      </ul>
 148                  <?php if ( 1 == $themes_to_delete ) : ?>
 149                      <p><?php _e( 'Are you sure you want to delete this theme?' ); ?></p>
 150                  <?php else : ?>
 151                      <p><?php _e( 'Are you sure you want to delete these themes?' ); ?></p>
 152                  <?php endif; ?>
 153                  <form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" style="display:inline;">
 154                      <input type="hidden" name="verify-delete" value="1" />
 155                      <input type="hidden" name="action" value="delete-selected" />
 156                      <?php
 157                      foreach ( (array) $themes as $theme ) {
 158                          echo '<input type="hidden" name="checked[]" value="' . esc_attr( $theme ) . '" />';
 159                      }
 160  
 161                          wp_nonce_field( 'bulk-themes' );
 162  
 163                      if ( 1 == $themes_to_delete ) {
 164                          submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
 165                      } else {
 166                          submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
 167                      }
 168                      ?>
 169                  </form>
 170                  <?php
 171                  $referer = wp_get_referer();
 172                  ?>
 173                  <form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
 174                      <?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?>
 175                  </form>
 176              </div>
 177                  <?php
 178                  require_once ( ABSPATH . 'wp-admin/admin-footer.php' );
 179                  exit;
 180              } // Endif verify-delete
 181  
 182              foreach ( $themes as $theme ) {
 183                  $delete_result = delete_theme(
 184                      $theme,
 185                      esc_url(
 186                          add_query_arg(
 187                              array(
 188                                  'verify-delete' => 1,
 189                                  'action'        => 'delete-selected',
 190                                  'checked'       => $_REQUEST['checked'],
 191                                  '_wpnonce'      => $_REQUEST['_wpnonce'],
 192                              ),
 193                              network_admin_url( 'themes.php' )
 194                          )
 195                      )
 196                  );
 197              }
 198  
 199              $paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
 200              wp_redirect(
 201                  add_query_arg(
 202                      array(
 203                          'deleted' => count( $themes ),
 204                          'paged'   => $paged,
 205                          's'       => $s,
 206                      ),
 207                      network_admin_url( 'themes.php' )
 208                  )
 209              );
 210              exit;
 211          default:
 212              $themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
 213              if ( empty( $themes ) ) {
 214                  wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 215                  exit;
 216              }
 217              check_admin_referer( 'bulk-themes' );
 218  
 219              /** This action is documented in wp-admin/network/site-themes.php */
 220              $referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 221  
 222              wp_safe_redirect( $referer );
 223              exit;
 224      }
 225  }
 226  
 227  $wp_list_table->prepare_items();
 228  
 229  add_thickbox();
 230  
 231  add_screen_option( 'per_page' );
 232  
 233  get_current_screen()->add_help_tab(
 234      array(
 235          'id'      => 'overview',
 236          'title'   => __( 'Overview' ),
 237          'content' =>
 238              '<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>' .
 239              '<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>' .
 240              '<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>',
 241      )
 242  );
 243  
 244  get_current_screen()->set_help_sidebar(
 245      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 246      '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>' ) . '</p>' .
 247      '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
 248  );
 249  
 250  get_current_screen()->set_screen_reader_content(
 251      array(
 252          'heading_views'      => __( 'Filter themes list' ),
 253          'heading_pagination' => __( 'Themes list navigation' ),
 254          'heading_list'       => __( 'Themes list' ),
 255      )
 256  );
 257  
 258  $title       = __( 'Themes' );
 259  $parent_file = 'themes.php';
 260  
 261  wp_enqueue_script( 'updates' );
 262  wp_enqueue_script( 'theme-preview' );
 263  
 264  require_once ( ABSPATH . 'wp-admin/admin-header.php' );
 265  
 266  ?>
 267  
 268  <div class="wrap">
 269  <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
 270  
 271  <?php if ( current_user_can( 'install_themes' ) ) : ?>
 272      <a href="theme-install.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'theme' ); ?></a>
 273  <?php endif; ?>
 274  
 275  <?php
 276  if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
 277      /* translators: %s: Search query. */
 278      printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
 279  }
 280  ?>
 281  
 282  <hr class="wp-header-end">
 283  
 284  <?php
 285  if ( isset( $_GET['enabled'] ) ) {
 286      $enabled = absint( $_GET['enabled'] );
 287      if ( 1 == $enabled ) {
 288          $message = __( 'Theme enabled.' );
 289      } else {
 290          /* translators: %s: Number of themes. */
 291          $message = _n( '%s theme enabled.', '%s themes enabled.', $enabled );
 292      }
 293      echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $enabled ) ) . '</p></div>';
 294  } elseif ( isset( $_GET['disabled'] ) ) {
 295      $disabled = absint( $_GET['disabled'] );
 296      if ( 1 == $disabled ) {
 297          $message = __( 'Theme disabled.' );
 298      } else {
 299          /* translators: %s: Number of themes. */
 300          $message = _n( '%s theme disabled.', '%s themes disabled.', $disabled );
 301      }
 302      echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $disabled ) ) . '</p></div>';
 303  } elseif ( isset( $_GET['deleted'] ) ) {
 304      $deleted = absint( $_GET['deleted'] );
 305      if ( 1 == $deleted ) {
 306          $message = __( 'Theme deleted.' );
 307      } else {
 308          /* translators: %s: Number of themes. */
 309          $message = _n( '%s theme deleted.', '%s themes deleted.', $deleted );
 310      }
 311      echo '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $deleted ) ) . '</p></div>';
 312  } elseif ( isset( $_GET['error'] ) && 'none' == $_GET['error'] ) {
 313      echo '<div id="message" class="error notice is-dismissible"><p>' . __( 'No theme selected.' ) . '</p></div>';
 314  } elseif ( isset( $_GET['error'] ) && 'main' == $_GET['error'] ) {
 315      echo '<div class="error notice is-dismissible"><p>' . __( 'You cannot delete a theme while it is active on the main site.' ) . '</p></div>';
 316  }
 317  
 318  ?>
 319  
 320  <form method="get">
 321  <?php $wp_list_table->search_box( __( 'Search Installed Themes' ), 'theme' ); ?>
 322  </form>
 323  
 324  <?php
 325  $wp_list_table->views();
 326  
 327  if ( 'broken' == $status ) {
 328      echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
 329  }
 330  ?>
 331  
 332  <form id="bulk-action-form" method="post">
 333  <input type="hidden" name="theme_status" value="<?php echo esc_attr( $status ); ?>" />
 334  <input type="hidden" name="paged" value="<?php echo esc_attr( $page ); ?>" />
 335  
 336  <?php $wp_list_table->display(); ?>
 337  </form>
 338  
 339  </div>
 340  
 341  <?php
 342  wp_print_request_filesystem_credentials_modal();
 343  wp_print_admin_notice_templates();
 344  wp_print_update_row_templates();
 345  
 346  include ( ABSPATH . 'wp-admin/admin-footer.php' );


Generated: Sat Nov 23 20:47:33 2019 Cross-referenced by PHPXref 0.7