wp/wp-admin/network/themes.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
--- a/wp/wp-admin/network/themes.php	Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-admin/network/themes.php	Mon Oct 14 17:39:30 2019 +0200
@@ -10,11 +10,8 @@
 /** Load WordPress Administration Bootstrap */
 require_once( dirname( __FILE__ ) . '/admin.php' );
 
-if ( ! is_multisite() )
-	wp_die( __( 'Multisite support is not enabled.' ) );
-
 if ( !current_user_can('manage_network_themes') )
-	wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) );
+	wp_die( __( 'Sorry, you are not allowed to manage network themes.' ) );
 
 $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
 $pagenum = $wp_list_table->get_pagenum();
@@ -29,12 +26,10 @@
 $referer = remove_query_arg( $temp_args, wp_get_referer() );
 
 if ( $action ) {
-	$allowed_themes = get_site_option( 'allowedthemes' );
 	switch ( $action ) {
 		case 'enable':
 			check_admin_referer('enable-theme_' . $_GET['theme']);
-			$allowed_themes[ $_GET['theme'] ] = true;
-			update_site_option( 'allowedthemes', $allowed_themes );
+			WP_Theme::network_enable_theme( $_GET['theme'] );
 			if ( false === strpos( $referer, '/network/themes.php' ) )
 				wp_redirect( network_admin_url( 'themes.php?enabled=1' ) );
 			else
@@ -42,8 +37,7 @@
 			exit;
 		case 'disable':
 			check_admin_referer('disable-theme_' . $_GET['theme']);
-			unset( $allowed_themes[ $_GET['theme'] ] );
-			update_site_option( 'allowedthemes', $allowed_themes );
+			WP_Theme::network_disable_theme( $_GET['theme'] );
 			wp_safe_redirect( add_query_arg( 'disabled', '1', $referer ) );
 			exit;
 		case 'enable-selected':
@@ -53,9 +47,7 @@
 				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 				exit;
 			}
-			foreach( (array) $themes as $theme )
-				$allowed_themes[ $theme ] = true;
-			update_site_option( 'allowedthemes', $allowed_themes );
+			WP_Theme::network_enable_theme( (array) $themes );
 			wp_safe_redirect( add_query_arg( 'enabled', count( $themes ), $referer ) );
 			exit;
 		case 'disable-selected':
@@ -65,9 +57,7 @@
 				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
 				exit;
 			}
-			foreach( (array) $themes as $theme )
-				unset( $allowed_themes[ $theme ] );
-			update_site_option( 'allowedthemes', $allowed_themes );
+			WP_Theme::network_disable_theme( (array) $themes );
 			wp_safe_redirect( add_query_arg( 'disabled', count( $themes ), $referer ) );
 			exit;
 		case 'update-selected' :
@@ -86,7 +76,7 @@
 			require_once(ABSPATH . 'wp-admin/admin-header.php');
 
 			echo '<div class="wrap">';
-			echo '<h2>' . esc_html( $title ) . '</h2>';
+			echo '<h1>' . esc_html( $title ) . '</h1>';
 
 			$url = self_admin_url('update.php?action=update-selected-themes&amp;themes=' . urlencode( join(',', $themes) ));
 			$url = wp_nonce_url($url, 'bulk-update-themes');
@@ -97,7 +87,7 @@
 			exit;
 		case 'delete-selected':
 			if ( ! current_user_can( 'delete_themes' ) ) {
-				wp_die( __('You do not have sufficient permissions to delete themes for this site.') );
+				wp_die( __('Sorry, you are not allowed to delete themes for this site.') );
 			}
 
 			check_admin_referer( 'bulk-themes' );
@@ -116,27 +106,9 @@
 				exit;
 			}
 
-			$files_to_delete = $theme_info = array();
-			$theme_translations = wp_get_installed_translations( 'themes' );
+			$theme_info = array();
 			foreach ( $themes as $key => $theme ) {
 				$theme_info[ $theme ] = wp_get_theme( $theme );
-
-				// Locate all the files in that folder.
-				$files = list_files( $theme_info[ $theme ]->get_stylesheet_directory() );
-				if ( $files ) {
-					$files_to_delete = array_merge( $files_to_delete, $files );
-				}
-
-				// Add translation files.
-				$theme_slug = $theme_info[ $theme ]->get_stylesheet();
-				if ( ! empty( $theme_translations[ $theme_slug ] ) ) {
-					$translations = $theme_translations[ $theme_slug ];
-
-					foreach ( $translations as $translation => $data ) {
-						$files_to_delete[] = $theme_slug . '-' . $translation . '.po';
-						$files_to_delete[] = $theme_slug . '-' . $translation . '.mo';
-					}
-				}
 			}
 
 			include(ABSPATH . 'wp-admin/update.php');
@@ -150,19 +122,23 @@
 				?>
 			<div class="wrap">
 				<?php if ( 1 == $themes_to_delete ) : ?>
-					<h2><?php _e( 'Delete Theme' ); ?></h2>
+					<h1><?php _e( 'Delete Theme' ); ?></h1>
 					<div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'This theme may be active on other sites in the network.' ); ?></p></div>
 					<p><?php _e( 'You are about to remove the following theme:' ); ?></p>
 				<?php else : ?>
-					<h2><?php _e( 'Delete Themes' ); ?></h2>
+					<h1><?php _e( 'Delete Themes' ); ?></h1>
 					<div class="error"><p><strong><?php _e( 'Caution:' ); ?></strong> <?php _e( 'These themes may be active on other sites in the network.' ); ?></p></div>
 					<p><?php _e( 'You are about to remove the following themes:' ); ?></p>
 				<?php endif; ?>
 					<ul class="ul-disc">
 					<?php
 						foreach ( $theme_info as $theme ) {
-							/* translators: 1: theme name, 2: theme author */
-							echo '<li>', sprintf( __('<strong>%1$s</strong> by <em>%2$s</em>' ), $theme->display('Name'), $theme->display('Author') ), '</li>';
+							echo '<li>' . sprintf(
+								/* translators: 1: theme name, 2: theme author */
+								_x( '%1$s by %2$s', 'theme' ),
+								'<strong>' . $theme->display( 'Name' ) . '</strong>',
+								'<em>' . $theme->display( 'Author' ) . '</em>'
+							) . '</li>';
 						}
 					?>
 					</ul>
@@ -182,9 +158,9 @@
 						wp_nonce_field( 'bulk-themes' );
 
 						if ( 1 == $themes_to_delete ) {
-							submit_button( __( 'Yes, Delete this theme' ), 'button', 'submit', false );
+							submit_button( __( 'Yes, delete this theme' ), '', 'submit', false );
 						} else {
-							submit_button( __( 'Yes, Delete these themes' ), 'button', 'submit', false );
+							submit_button( __( 'Yes, delete these themes' ), '', 'submit', false );
 						}
 					?>
 				</form>
@@ -192,19 +168,8 @@
 				$referer = wp_get_referer();
 				?>
 				<form method="post" action="<?php echo $referer ? esc_url( $referer ) : ''; ?>" style="display:inline;">
-					<?php submit_button( __( 'No, Return me to the theme list' ), 'button', 'submit', false ); ?>
+					<?php submit_button( __( 'No, return me to the theme list' ), '', 'submit', false ); ?>
 				</form>
-
-				<p><a href="#" onclick="jQuery('#files-list').toggle(); return false;"><?php _e('Click to view entire list of files which will be deleted'); ?></a></p>
-				<div id="files-list" style="display:none;">
-					<ul class="code">
-					<?php
-						foreach ( (array) $files_to_delete as $file ) {
-							echo '<li>' . esc_html( str_replace( WP_CONTENT_DIR . '/themes', '', $file ) ) . '</li>';
-						}
-					?>
-					</ul>
-				</div>
 			</div>
 				<?php
 				require_once(ABSPATH . 'wp-admin/admin-footer.php');
@@ -227,7 +192,21 @@
 				's' => $s
 			), network_admin_url( 'themes.php' ) ) );
 			exit;
+		default:
+			$themes = isset( $_POST['checked'] ) ? (array) $_POST['checked'] : array();
+			if ( empty( $themes ) ) {
+				wp_safe_redirect( add_query_arg( 'error', 'none', $referer ) );
+				exit;
+			}
+			check_admin_referer( 'bulk-themes' );
+
+			/** This action is documented in wp-admin/network/site-themes.php */
+			$referer = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $referer, $action, $themes );
+
+			wp_safe_redirect( $referer );
+			exit;
 	}
+
 }
 
 $wp_list_table->prepare_items();
@@ -247,13 +226,20 @@
 
 get_current_screen()->set_help_sidebar(
 	'<p><strong>' . __('For more information:') . '</strong></p>' .
-	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen" target="_blank">Documentation on Network Themes</a>') . '</p>' .
-	'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
+	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Themes_Screen">Documentation on Network Themes</a>') . '</p>' .
+	'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
 );
 
+get_current_screen()->set_screen_reader_content( array(
+	'heading_views'      => __( 'Filter themes list' ),
+	'heading_pagination' => __( 'Themes list navigation' ),
+	'heading_list'       => __( 'Themes list' ),
+) );
+
 $title = __('Themes');
 $parent_file = 'themes.php';
 
+wp_enqueue_script( 'updates' );
 wp_enqueue_script( 'theme-preview' );
 
 require_once(ABSPATH . 'wp-admin/admin-header.php');
@@ -261,10 +247,20 @@
 ?>
 
 <div class="wrap">
-<h2><?php echo esc_html( $title ); if ( current_user_can('install_themes') ) { ?> <a href="theme-install.php" class="add-new-h2"><?php echo esc_html_x('Add New', 'theme'); ?></a><?php }
-if ( $s )
-	printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $s ) ); ?>
-</h2>
+<h1 class="wp-heading-inline"><?php echo esc_html( $title ); ?></h1>
+
+<?php if ( current_user_can( 'install_themes' ) ) : ?>
+	<a href="theme-install.php" class="page-title-action"><?php echo esc_html_x( 'Add New', 'theme' ); ?></a>
+<?php endif; ?>
+
+<?php
+if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
+	/* translators: %s: search keywords */
+	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
+}
+?>
+
+<hr class="wp-header-end">
 
 <?php
 if ( isset( $_GET['enabled'] ) ) {
@@ -307,10 +303,10 @@
 $wp_list_table->views();
 
 if ( 'broken' == $status )
-	echo '<p class="clear">' . __('The following themes are installed but incomplete. Themes must have a stylesheet and a template.') . '</p>';
+	echo '<p class="clear">' . __( 'The following themes are installed but incomplete.' ) . '</p>';
 ?>
 
-<form method="post">
+<form id="bulk-action-form" method="post">
 <input type="hidden" name="theme_status" value="<?php echo esc_attr($status) ?>" />
 <input type="hidden" name="paged" value="<?php echo esc_attr($page) ?>" />
 
@@ -320,4 +316,8 @@
 </div>
 
 <?php
+wp_print_request_filesystem_credentials_modal();
+wp_print_admin_notice_templates();
+wp_print_update_row_templates();
+
 include(ABSPATH . 'wp-admin/admin-footer.php');