wp/wp-admin/network/themes.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     8  */
     8  */
     9 
     9 
    10 /** Load WordPress Administration Bootstrap */
    10 /** Load WordPress Administration Bootstrap */
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    12 
    12 
    13 if ( !current_user_can('manage_network_themes') )
    13 if ( ! current_user_can( 'manage_network_themes' ) ) {
    14 	wp_die( __( 'Sorry, you are not allowed to manage network themes.' ) );
    14 	wp_die( __( 'Sorry, you are not allowed to manage network themes.' ) );
    15 
    15 }
    16 $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
    16 
    17 $pagenum = $wp_list_table->get_pagenum();
    17 $wp_list_table = _get_list_table( 'WP_MS_Themes_List_Table' );
       
    18 $pagenum       = $wp_list_table->get_pagenum();
    18 
    19 
    19 $action = $wp_list_table->current_action();
    20 $action = $wp_list_table->current_action();
    20 
    21 
    21 $s = isset($_REQUEST['s']) ? $_REQUEST['s'] : '';
    22 $s = isset( $_REQUEST['s'] ) ? $_REQUEST['s'] : '';
    22 
    23 
    23 // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    24 // Clean up request URI from temporary args for screen options/paging uri's to work as expected.
    24 $temp_args = array( 'enabled', 'disabled', 'deleted', 'error' );
    25 $temp_args              = array( 'enabled', 'disabled', 'deleted', 'error' );
    25 $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
    26 $_SERVER['REQUEST_URI'] = remove_query_arg( $temp_args, $_SERVER['REQUEST_URI'] );
    26 $referer = remove_query_arg( $temp_args, wp_get_referer() );
    27 $referer                = remove_query_arg( $temp_args, wp_get_referer() );
    27 
    28 
    28 if ( $action ) {
    29 if ( $action ) {
    29 	switch ( $action ) {
    30 	switch ( $action ) {
    30 		case 'enable':
    31 		case 'enable':
    31 			check_admin_referer('enable-theme_' . $_GET['theme']);
    32 			check_admin_referer( 'enable-theme_' . $_GET['theme'] );
    32 			WP_Theme::network_enable_theme( $_GET['theme'] );
    33 			WP_Theme::network_enable_theme( $_GET['theme'] );
    33 			if ( false === strpos( $referer, '/network/themes.php' ) )
    34 			if ( false === strpos( $referer, '/network/themes.php' ) ) {
    34 				wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
    35 				wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
    35 			else
    36 			} else {
    36 				wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
    37 				wp_safe_redirect( add_query_arg( 'enabled', 1, $referer ) );
       
    38 			}
    37 			exit;
    39 			exit;
    38 		case 'disable':
    40 		case 'disable':
    39 			check_admin_referer('disable-theme_' . $_GET['theme']);
    41 			check_admin_referer( 'disable-theme_' . $_GET['theme'] );
    40 			WP_Theme::network_disable_theme( $_GET['theme'] );
    42 			WP_Theme::network_disable_theme( $_GET['theme'] );
    41 			wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
    43 			wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
    42 			exit;
    44 			exit;
    43 		case 'enable-selected':
    45 		case 'enable-selected':
    44 			check_admin_referer('bulk-themes');
    46 			check_admin_referer( 'bulk-themes' );
    45 			$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    47 			$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    46 			if ( empty($themes) ) {
    48 			if ( empty( $themes ) ) {
    47 				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
    49 				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
    48 				exit;
    50 				exit;
    49 			}
    51 			}
    50 			WP_Theme::network_enable_theme( (array) $themes );
    52 			WP_Theme::network_enable_theme( (array) $themes );
    51 			wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
    53 			wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
    52 			exit;
    54 			exit;
    53 		case 'disable-selected':
    55 		case 'disable-selected':
    54 			check_admin_referer('bulk-themes');
    56 			check_admin_referer( 'bulk-themes' );
    55 			$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    57 			$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
    56 			if ( empty($themes) ) {
    58 			if ( empty( $themes ) ) {
    57 				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
    59 				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
    58 				exit;
    60 				exit;
    59 			}
    61 			}
    60 			WP_Theme::network_disable_theme( (array) $themes );
    62 			WP_Theme::network_disable_theme( (array) $themes );
    61 			wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
    63 			wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
    62 			exit;
    64 			exit;
    63 		case 'update-selected' :
    65 		case 'update-selected':
    64 			check_admin_referer( 'bulk-themes' );
    66 			check_admin_referer( 'bulk-themes' );
    65 
    67 
    66 			if ( isset( $_GET['themes'] ) )
    68 			if ( isset( $_GET['themes'] ) ) {
    67 				$themes = explode( ',', $_GET['themes'] );
    69 				$themes = explode( ',', $_GET['themes'] );
    68 			elseif ( isset( $_POST['checked'] ) )
    70 			} elseif ( isset( $_POST['checked'] ) ) {
    69 				$themes = (array) $_POST['checked'];
    71 				$themes = (array) $_POST['checked'];
    70 			else
    72 			} else {
    71 				$themes = array();
    73 				$themes = array();
    72 
    74 			}
    73 			$title = __( 'Update Themes' );
    75 
       
    76 			$title       = __( 'Update Themes' );
    74 			$parent_file = 'themes.php';
    77 			$parent_file = 'themes.php';
    75 
    78 
    76 			require_once(ABSPATH . 'wp-admin/admin-header.php');
    79 			require_once( ABSPATH . 'wp-admin/admin-header.php' );
    77 
    80 
    78 			echo '<div class="wrap">';
    81 			echo '<div class="wrap">';
    79 			echo '<h1>' . esc_html( $title ) . '</h1>';
    82 			echo '<h1>' . esc_html( $title ) . '</h1>';
    80 
    83 
    81 			$url = self_admin_url('update.php?action=update-selected-themes&amp;themes=' . urlencode( join(',', $themes) ));
    84 			$url = self_admin_url( 'update.php?action=update-selected-themes&amp;themes=' . urlencode( join( ',', $themes ) ) );
    82 			$url = wp_nonce_url($url, 'bulk-update-themes');
    85 			$url = wp_nonce_url( $url, 'bulk-update-themes' );
    83 
    86 
    84 			echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
    87 			echo "<iframe src='$url' style='width: 100%; height:100%; min-height:850px;'></iframe>";
    85 			echo '</div>';
    88 			echo '</div>';
    86 			require_once(ABSPATH . 'wp-admin/admin-footer.php');
    89 			require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    87 			exit;
    90 			exit;
    88 		case 'delete-selected':
    91 		case 'delete-selected':
    89 			if ( ! current_user_can( 'delete_themes' ) ) {
    92 			if ( ! current_user_can( 'delete_themes' ) ) {
    90 				wp_die( __('Sorry, you are not allowed to delete themes for this site.') );
    93 				wp_die( __( 'Sorry, you are not allowed to delete themes for this site.' ) );
    91 			}
    94 			}
    92 
    95 
    93 			check_admin_referer( 'bulk-themes' );
    96 			check_admin_referer( 'bulk-themes' );
    94 
    97 
    95 			$themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
    98 			$themes = isset( $_REQUEST['checked'] ) ? (array) $_REQUEST['checked'] : array();
   109 			$theme_info = array();
   112 			$theme_info = array();
   110 			foreach ( $themes as $key => $theme ) {
   113 			foreach ( $themes as $key => $theme ) {
   111 				$theme_info[ $theme ] = wp_get_theme( $theme );
   114 				$theme_info[ $theme ] = wp_get_theme( $theme );
   112 			}
   115 			}
   113 
   116 
   114 			include(ABSPATH . 'wp-admin/update.php');
   117 			include( ABSPATH . 'wp-admin/update.php' );
   115 
   118 
   116 			$parent_file = 'themes.php';
   119 			$parent_file = 'themes.php';
   117 
   120 
   118 			if ( ! isset( $_REQUEST['verify-delete'] ) ) {
   121 			if ( ! isset( $_REQUEST['verify-delete'] ) ) {
   119 				wp_enqueue_script( 'jquery' );
   122 				wp_enqueue_script( 'jquery' );
   130 					<div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These themes may be active on other sites in the network.' ); ?></p></div>
   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>
   131 					<p><?php _e( 'You are about to remove the following themes:' ); ?></p>
   134 					<p><?php _e( 'You are about to remove the following themes:' ); ?></p>
   132 				<?php endif; ?>
   135 				<?php endif; ?>
   133 					<ul class="ul-disc">
   136 					<ul class="ul-disc">
   134 					<?php
   137 					<?php
   135 						foreach ( $theme_info as $theme ) {
   138 					foreach ( $theme_info as $theme ) {
   136 							echo '<li>' . sprintf(
   139 						echo '<li>' . sprintf(
   137 								/* translators: 1: theme name, 2: theme author */
   140 							/* translators: 1: theme name, 2: theme author */
   138 								_x( '%1$s by %2$s', 'theme' ),
   141 							_x( '%1$s by %2$s', 'theme' ),
   139 								'<strong>' . $theme->display( 'Name' ) . '</strong>',
   142 							'<strong>' . $theme->display( 'Name' ) . '</strong>',
   140 								'<em>' . $theme->display( 'Author' ) . '</em>'
   143 							'<em>' . $theme->display( 'Author' ) . '</em>'
   141 							) . '</li>';
   144 						) . '</li>';
   142 						}
   145 					}
   143 					?>
   146 					?>
   144 					</ul>
   147 					</ul>
   145 				<?php if ( 1 == $themes_to_delete ) : ?>
   148 				<?php if ( 1 == $themes_to_delete ) : ?>
   146 					<p><?php _e( 'Are you sure you wish to delete this theme?' ); ?></p>
   149 					<p><?php _e( 'Are you sure you wish to delete this theme?' ); ?></p>
   147 				<?php else : ?>
   150 				<?php else : ?>
   148 					<p><?php _e( 'Are you sure you wish to delete these themes?' ); ?></p>
   151 					<p><?php _e( 'Are you sure you wish to delete these themes?' ); ?></p>
   149 				<?php endif; ?>
   152 				<?php endif; ?>
   150 				<form method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" style="display:inline;">
   153 				<form method="post" action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" style="display:inline;">
   151 					<input type="hidden" name="verify-delete" value="1" />
   154 					<input type="hidden" name="verify-delete" value="1" />
   152 					<input type="hidden" name="action" value="delete-selected" />
   155 					<input type="hidden" name="action" value="delete-selected" />
   153 					<?php
   156 					<?php
   154 						foreach ( (array) $themes as $theme ) {
   157 					foreach ( (array) $themes as $theme ) {
   155 							echo '<input type="hidden" name="checked[]" value="' . esc_attr($theme) . '" />';
   158 						echo '<input type="hidden" name="checked[]" value="' . esc_attr( $theme ) . '" />';
   156 						}
   159 					}
   157 
   160 
   158 						wp_nonce_field( 'bulk-themes' );
   161 						wp_nonce_field( 'bulk-themes' );
   159 
   162 
   160 						if ( 1 == $themes_to_delete ) {
   163 					if ( 1 == $themes_to_delete ) {
   161 							submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
   164 						submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
   162 						} else {
   165 					} else {
   163 							submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
   166 						submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
   164 						}
   167 					}
   165 					?>
   168 					?>
   166 				</form>
   169 				</form>
   167 				<?php
   170 				<?php
   168 				$referer = wp_get_referer();
   171 				$referer = wp_get_referer();
   169 				?>
   172 				?>
   170 				<form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
   173 				<form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
   171 					<?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?>
   174 					<?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?>
   172 				</form>
   175 				</form>
   173 			</div>
   176 			</div>
   174 				<?php
   177 				<?php
   175 				require_once(ABSPATH . 'wp-admin/admin-footer.php');
   178 				require_once( ABSPATH . 'wp-admin/admin-footer.php' );
   176 				exit;
   179 				exit;
   177 			} // Endif verify-delete
   180 			} // Endif verify-delete
   178 
   181 
   179 			foreach ( $themes as $theme ) {
   182 			foreach ( $themes as $theme ) {
   180 				$delete_result = delete_theme( $theme, esc_url( add_query_arg( array(
   183 				$delete_result = delete_theme(
   181 					'verify-delete' => 1,
   184 					$theme,
   182 					'action' => 'delete-selected',
   185 					esc_url(
   183 					'checked' => $_REQUEST['checked'],
   186 						add_query_arg(
   184 					'_wpnonce' => $_REQUEST['_wpnonce']
   187 							array(
   185 				), network_admin_url( 'themes.php' ) ) ) );
   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 				);
   186 			}
   197 			}
   187 
   198 
   188 			$paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
   199 			$paged = ( $_REQUEST['paged'] ) ? $_REQUEST['paged'] : 1;
   189 			wp_redirect( add_query_arg( array(
   200 			wp_redirect(
   190 				'deleted' => count( $themes ),
   201 				add_query_arg(
   191 				'paged' => $paged,
   202 					array(
   192 				's' => $s
   203 						'deleted' => count( $themes ),
   193 			), network_admin_url( 'themes.php' ) ) );
   204 						'paged'   => $paged,
       
   205 						's'       => $s,
       
   206 					),
       
   207 					network_admin_url( 'themes.php' )
       
   208 				)
       
   209 			);
   194 			exit;
   210 			exit;
   195 		default:
   211 		default:
   196 			$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
   212 			$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
   197 			if ( empty( $themes ) ) {
   213 			if ( empty( $themes ) ) {
   198 				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
   214 				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
   204 			$referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes );
   220 			$referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes );
   205 
   221 
   206 			wp_safe_redirect( $referer );
   222 			wp_safe_redirect( $referer );
   207 			exit;
   223 			exit;
   208 	}
   224 	}
   209 
       
   210 }
   225 }
   211 
   226 
   212 $wp_list_table->prepare_items();
   227 $wp_list_table->prepare_items();
   213 
   228 
   214 add_thickbox();
   229 add_thickbox();
   215 
   230 
   216 add_screen_option( 'per_page' );
   231 add_screen_option( 'per_page' );
   217 
   232 
   218 get_current_screen()->add_help_tab( array(
   233 get_current_screen()->add_help_tab(
   219 	'id'      => 'overview',
   234 	array(
   220 	'title'   => __('Overview'),
   235 		'id'      => 'overview',
   221 	'content' =>
   236 		'title'   => __( 'Overview' ),
   222 		'<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>' .
   237 		'content' =>
   223 		'<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>' .
   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>' .
   224 		'<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>'
   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>' .
   225 ) );
   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 );
   226 
   243 
   227 get_current_screen()->set_help_sidebar(
   244 get_current_screen()->set_help_sidebar(
   228 	'<p><strong>' . __('For more information:') . '</strong></p>' .
   245 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   229 	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>') . '</p>' .
   246 	'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>' ) . '</p>' .
   230 	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
   247 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
   231 );
   248 );
   232 
   249 
   233 get_current_screen()->set_screen_reader_content( array(
   250 get_current_screen()->set_screen_reader_content(
   234 	'heading_views'      => __( 'Filter themes list' ),
   251 	array(
   235 	'heading_pagination' => __( 'Themes list navigation' ),
   252 		'heading_views'      => __( 'Filter themes list' ),
   236 	'heading_list'       => __( 'Themes list' ),
   253 		'heading_pagination' => __( 'Themes list navigation' ),
   237 ) );
   254 		'heading_list'       => __( 'Themes list' ),
   238 
   255 	)
   239 $title = __('Themes');
   256 );
       
   257 
       
   258 $title       = __( 'Themes' );
   240 $parent_file = 'themes.php';
   259 $parent_file = 'themes.php';
   241 
   260 
   242 wp_enqueue_script( 'updates' );
   261 wp_enqueue_script( 'updates' );
   243 wp_enqueue_script( 'theme-preview' );
   262 wp_enqueue_script( 'theme-preview' );
   244 
   263 
   245 require_once(ABSPATH . 'wp-admin/admin-header.php');
   264 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   246 
   265 
   247 ?>
   266 ?>
   248 
   267 
   249 <div class="wrap">
   268 <div class="wrap">
   250 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
   269 <h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
   300 </form>
   319 </form>
   301 
   320 
   302 <?php
   321 <?php
   303 $wp_list_table->views();
   322 $wp_list_table->views();
   304 
   323 
   305 if ( 'broken' == $status )
   324 if ( 'broken' == $status ) {
   306 	echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
   325 	echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
       
   326 }
   307 ?>
   327 ?>
   308 
   328 
   309 <form id="bulk-action-form" method="post">
   329 <form id="bulk-action-form" method="post">
   310 <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
   330 <input type="hidden" name="theme_status" value="<?php echo esc_attr( $status ); ?>" />
   311 <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
   331 <input type="hidden" name="paged" value="<?php echo esc_attr( $page ); ?>" />
   312 
   332 
   313 <?php $wp_list_table->display(); ?>
   333 <?php $wp_list_table->display(); ?>
   314 </form>
   334 </form>
   315 
   335 
   316 </div>
   336 </div>
   318 <?php
   338 <?php
   319 wp_print_request_filesystem_credentials_modal();
   339 wp_print_request_filesystem_credentials_modal();
   320 wp_print_admin_notice_templates();
   340 wp_print_admin_notice_templates();
   321 wp_print_update_row_templates();
   341 wp_print_update_row_templates();
   322 
   342 
   323 include(ABSPATH . 'wp-admin/admin-footer.php');
   343 include( ABSPATH . 'wp-admin/admin-footer.php' );