wp/wp-admin/network/sites.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     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 ( ! is_multisite() )
       
    14 	wp_die( __( 'Multisite support is not enabled.' ) );
       
    15 
       
    16 if ( ! current_user_can( 'manage_sites' ) )
    13 if ( ! current_user_can( 'manage_sites' ) )
    17 	wp_die( __( 'You do not have permission to access this page.' ), 403 );
    14 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    18 
    15 
    19 $wp_list_table = _get_list_table( 'WP_MS_Sites_List_Table' );
    16 $wp_list_table = _get_list_table( 'WP_MS_Sites_List_Table' );
    20 $pagenum = $wp_list_table->get_pagenum();
    17 $pagenum = $wp_list_table->get_pagenum();
    21 
    18 
    22 $title = __( 'Sites' );
    19 $title = __( 'Sites' );
    33 		'<p>' . __('Hovering over each site reveals seven options (three for the primary site):') . '</p>' .
    30 		'<p>' . __('Hovering over each site reveals seven options (three for the primary site):') . '</p>' .
    34 		'<ul><li>' . __('An Edit link to a separate Edit Site screen.') . '</li>' .
    31 		'<ul><li>' . __('An Edit link to a separate Edit Site screen.') . '</li>' .
    35 		'<li>' . __('Dashboard leads to the Dashboard for that site.') . '</li>' .
    32 		'<li>' . __('Dashboard leads to the Dashboard for that site.') . '</li>' .
    36 		'<li>' . __('Deactivate, Archive, and Spam which lead to confirmation screens. These actions can be reversed later.') . '</li>' .
    33 		'<li>' . __('Deactivate, Archive, and Spam which lead to confirmation screens. These actions can be reversed later.') . '</li>' .
    37 		'<li>' . __('Delete which is a permanent action after the confirmation screens.') . '</li>' .
    34 		'<li>' . __('Delete which is a permanent action after the confirmation screens.') . '</li>' .
    38 		'<li>' . __('Visit to go to the frontend site live.') . '</li></ul>' .
    35 		'<li>' . __('Visit to go to the front-end site live.') . '</li></ul>' .
    39 		'<p>' . __('The site ID is used internally, and is not shown on the front end of the site or to users/viewers.') . '</p>' .
    36 		'<p>' . __('The site ID is used internally, and is not shown on the front end of the site or to users/viewers.') . '</p>' .
    40 		'<p>' . __('Clicking on bold headings can re-sort this table.') . '</p>'
    37 		'<p>' . __('Clicking on bold headings can re-sort this table.') . '</p>'
    41 ) );
    38 ) );
    42 
    39 
    43 get_current_screen()->set_help_sidebar(
    40 get_current_screen()->set_help_sidebar(
    44 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    41 	'<p><strong>' . __('For more information:') . '</strong></p>' .
    45 	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' .
    42 	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>') . '</p>' .
    46 	'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
    43 	'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>'
    47 );
    44 );
       
    45 
       
    46 get_current_screen()->set_screen_reader_content( array(
       
    47 	'heading_pagination' => __( 'Sites list navigation' ),
       
    48 	'heading_list'       => __( 'Sites list' ),
       
    49 ) );
    48 
    50 
    49 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    51 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    50 
    52 
    51 if ( isset( $_GET['action'] ) ) {
    53 if ( isset( $_GET['action'] ) ) {
    52 	/** This action is documented in wp-admin/network/edit.php */
    54 	/** This action is documented in wp-admin/network/edit.php */
    53 	do_action( 'wpmuadminedit' );
    55 	do_action( 'wpmuadminedit' );
    54 
    56 
       
    57 	// A list of valid actions and their associated messaging for confirmation output.
       
    58 	$manage_actions = array(
       
    59 		'activateblog'   => __( 'You are about to activate the site %s.' ),
       
    60 		'deactivateblog' => __( 'You are about to deactivate the site %s.' ),
       
    61 		'unarchiveblog'  => __( 'You are about to unarchive the site %s.' ),
       
    62 		'archiveblog'    => __( 'You are about to archive the site %s.' ),
       
    63 		'unspamblog'     => __( 'You are about to unspam the site %s.' ),
       
    64 		'spamblog'       => __( 'You are about to mark the site %s as spam.' ),
       
    65 		'deleteblog'     => __( 'You are about to delete the site %s.' ),
       
    66 		'unmatureblog'   => __( 'You are about to mark the site %s as mature.' ),
       
    67 		'matureblog'     => __( 'You are about to mark the site %s as not mature.' ),
       
    68 	);
       
    69 
    55 	if ( 'confirm' === $_GET['action'] ) {
    70 	if ( 'confirm' === $_GET['action'] ) {
    56 		check_admin_referer( 'confirm' );
    71 		// The action2 parameter contains the action being taken on the site.
       
    72 		$site_action = $_GET['action2'];
       
    73 
       
    74 		if ( ! array_key_exists( $site_action, $manage_actions ) ) {
       
    75 			wp_die( __( 'The requested action is not valid.' ) );
       
    76 		}
       
    77 
       
    78 		// The mature/unmature UI exists only as external code. Check the "confirm" nonce for backward compatibility.
       
    79 		if ( 'matureblog' === $site_action || 'unmatureblog' === $site_action ) {
       
    80 			check_admin_referer( 'confirm' );
       
    81 		} else {
       
    82 			check_admin_referer( $site_action . '_' . $id );
       
    83 		}
    57 
    84 
    58 		if ( ! headers_sent() ) {
    85 		if ( ! headers_sent() ) {
    59 			nocache_headers();
    86 			nocache_headers();
    60 			header( 'Content-Type: text/html; charset=utf-8' );
    87 			header( 'Content-Type: text/html; charset=utf-8' );
    61 		}
    88 		}
    62 
    89 
    63 		if ( $current_site->blog_id == $id ) {
    90 		if ( get_network()->site_id == $id ) {
    64 			wp_die( __( 'You are not allowed to change the current site.' ) );
    91 			wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
    65 		}
    92 		}
       
    93 
       
    94 		$site_details = get_site( $id );
       
    95 		$site_address = untrailingslashit( $site_details->domain . $site_details->path );
    66 
    96 
    67 		require_once( ABSPATH . 'wp-admin/admin-header.php' );
    97 		require_once( ABSPATH . 'wp-admin/admin-header.php' );
    68 		?>
    98 		?>
    69 			<div class="wrap">
    99 			<div class="wrap">
    70 				<h2><?php _e( 'Confirm your action' ); ?></h2>
   100 				<h1><?php _e( 'Confirm your action' ); ?></h1>
    71 				<form action="sites.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
   101 				<form action="sites.php?action=<?php echo esc_attr( $site_action ); ?>" method="post">
    72 					<input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
   102 					<input type="hidden" name="action" value="<?php echo esc_attr( $site_action ); ?>" />
    73 					<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
   103 					<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
    74 					<input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
   104 					<input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
    75 					<?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
   105 					<?php wp_nonce_field( $site_action . '_' . $id, '_wpnonce', false ); ?>
    76 					<p><?php echo esc_html( wp_unslash( $_GET['msg'] ) ); ?></p>
   106 					<p><?php echo sprintf( $manage_actions[ $site_action ], $site_address ); ?></p>
    77 					<?php submit_button( __( 'Confirm' ), 'button' ); ?>
   107 					<?php submit_button( __( 'Confirm' ), 'primary' ); ?>
    78 				</form>
   108 				</form>
    79 			</div>
   109 			</div>
    80 		<?php
   110 		<?php
    81 		require_once( ABSPATH . 'wp-admin/admin-footer.php' );
   111 		require_once( ABSPATH . 'wp-admin/admin-footer.php' );
    82 		exit();
   112 		exit();
       
   113 	} elseif ( array_key_exists( $_GET['action'], $manage_actions ) ) {
       
   114 		$action = $_GET['action'];
       
   115 		check_admin_referer( $action . '_' . $id );
       
   116 	} elseif ( 'allblogs' === $_GET['action'] ) {
       
   117 		check_admin_referer( 'bulk-sites' );
    83 	}
   118 	}
    84 
   119 
    85 	$updated_action = '';
   120 	$updated_action = '';
    86 
       
    87 	$manage_actions = array( 'deleteblog', 'allblogs', 'archiveblog', 'unarchiveblog', 'activateblog', 'deactivateblog', 'unspamblog', 'spamblog', 'unmatureblog', 'matureblog' );
       
    88 	if ( in_array( $_GET['action'], $manage_actions ) ) {
       
    89 		$action = $_GET['action'];
       
    90 		if ( 'allblogs' === $action )
       
    91 			$action = 'bulk-sites';
       
    92 
       
    93 		check_admin_referer( $action );
       
    94 	}
       
    95 
   121 
    96 	switch ( $_GET['action'] ) {
   122 	switch ( $_GET['action'] ) {
    97 
   123 
    98 		case 'deleteblog':
   124 		case 'deleteblog':
    99 			if ( ! current_user_can( 'delete_sites' ) )
   125 			if ( ! current_user_can( 'delete_sites' ) )
   100 				wp_die( __( 'You do not have permission to access this page.' ), '', array( 'response' => 403 ) );
   126 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), '', array( 'response' => 403 ) );
   101 
   127 
   102 			$updated_action = 'not_deleted';
   128 			$updated_action = 'not_deleted';
   103 			if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) {
   129 			if ( $id != '0' && $id != get_network()->site_id && current_user_can( 'delete_site', $id ) ) {
   104 				wpmu_delete_blog( $id, true );
   130 				wpmu_delete_blog( $id, true );
   105 				$updated_action = 'delete';
   131 				$updated_action = 'delete';
   106 			}
   132 			}
   107 		break;
   133 		break;
   108 
   134 
       
   135 		case 'delete_sites':
       
   136 			check_admin_referer( 'ms-delete-sites' );
       
   137 
       
   138 			foreach ( (array) $_POST['site_ids'] as $site_id ) {
       
   139 				$site_id = (int) $site_id;
       
   140 
       
   141 				if ( $site_id == get_network()->site_id ) {
       
   142 					continue;
       
   143 				}
       
   144 
       
   145 				if ( ! current_user_can( 'delete_site', $site_id ) ) {
       
   146 					$site = get_site( $site_id );
       
   147 					$site_address = untrailingslashit( $site->domain . $site->path );
       
   148 
       
   149 					wp_die( sprintf( __( 'Sorry, you are not allowed to delete the site %s.' ), $site_address ), 403 );
       
   150 				}
       
   151 
       
   152 				$updated_action = 'all_delete';
       
   153 				wpmu_delete_blog( $site_id, true );
       
   154 			}
       
   155 			break;
       
   156 
   109 		case 'allblogs':
   157 		case 'allblogs':
   110 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
   158 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
   111 				$doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
   159 				$doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
   112 
   160 
   113 				foreach ( (array) $_POST['allblogs'] as $key => $val ) {
   161 				foreach ( (array) $_POST['allblogs'] as $key => $val ) {
   114 					if ( $val != '0' && $val != $current_site->blog_id ) {
   162 					if ( $val != '0' && $val != get_network()->site_id ) {
   115 						switch ( $doaction ) {
   163 						switch ( $doaction ) {
   116 							case 'delete':
   164 							case 'delete':
   117 								if ( ! current_user_can( 'delete_site', $val ) )
   165 								require_once( ABSPATH . 'wp-admin/admin-header.php' );
   118 									wp_die( __( 'You are not allowed to delete the site.' ) );
   166 								?>
   119 
   167 								<div class="wrap">
   120 								$updated_action = 'all_delete';
   168 									<h1><?php _e( 'Confirm your action' ); ?></h1>
   121 								wpmu_delete_blog( $val, true );
   169 									<form action="sites.php?action=delete_sites" method="post">
       
   170 										<input type="hidden" name="action" value="delete_sites" />
       
   171 										<input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
       
   172 										<?php wp_nonce_field( 'ms-delete-sites', '_wpnonce', false ); ?>
       
   173 										<p><?php _e( 'You are about to delete the following sites:' ); ?></p>
       
   174 										<ul class="ul-disc">
       
   175 											<?php foreach ( $_POST['allblogs'] as $site_id ) :
       
   176 												$site = get_site( $site_id );
       
   177 												$site_address = untrailingslashit( $site->domain . $site->path );
       
   178 												?>
       
   179 												<li>
       
   180 													<?php echo $site_address; ?>
       
   181 													<input type="hidden" name="site_ids[]" value="<?php echo (int) $site_id; ?>" />
       
   182 												</li>
       
   183 											<?php endforeach; ?>
       
   184 										</ul>
       
   185 										<?php submit_button( __( 'Confirm' ), 'primary' ); ?>
       
   186 									</form>
       
   187 								</div>
       
   188 								<?php
       
   189 								require_once( ABSPATH . 'wp-admin/admin-footer.php' );
       
   190 								exit();
   122 							break;
   191 							break;
   123 
   192 
   124 							case 'spam':
   193 							case 'spam':
   125 							case 'notspam':
   194 							case 'notspam':
   126 								$updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
   195 								$updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
   127 								update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
   196 								update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
   128 							break;
   197 							break;
   129 						}
   198 						}
   130 					} else {
   199 					} else {
   131 						wp_die( __( 'You are not allowed to change the current site.' ) );
   200 						wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
   132 					}
   201 					}
   133 				}
   202 				}
       
   203 				if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
       
   204 					$redirect_to = wp_get_referer();
       
   205 					$blogs = (array) $_POST['allblogs'];
       
   206 					/** This action is documented in wp-admin/network/site-themes.php */
       
   207 					$redirect_to = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id );
       
   208 					wp_safe_redirect( $redirect_to );
       
   209 					exit();
       
   210 				}
   134 			} else {
   211 			} else {
   135 				wp_redirect( network_admin_url( 'sites.php' ) );
   212 				$location = network_admin_url( 'sites.php' );
       
   213 				if ( ! empty( $_REQUEST['paged'] ) ) {
       
   214 					$location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
       
   215 				}
       
   216 				wp_redirect( $location );
   136 				exit();
   217 				exit();
   137 			}
   218 			}
   138 		break;
   219 		break;
   139 
   220 
   140 		case 'archiveblog':
   221 		case 'archiveblog':
   146 			update_blog_status( $id, 'deleted', '0' );
   227 			update_blog_status( $id, 'deleted', '0' );
   147 
   228 
   148 			/**
   229 			/**
   149 			 * Fires after a network site is activated.
   230 			 * Fires after a network site is activated.
   150 			 *
   231 			 *
   151 			 * @since MU
   232 			 * @since MU (3.0.0)
   152 			 *
   233 			 *
   153 			 * @param string $id The ID of the activated site.
   234 			 * @param string $id The ID of the activated site.
   154 			 */
   235 			 */
   155 			do_action( 'activate_blog', $id );
   236 			do_action( 'activate_blog', $id );
   156 		break;
   237 		break;
   157 
   238 
   158 		case 'deactivateblog':
   239 		case 'deactivateblog':
   159 			/**
   240 			/**
   160 			 * Fires before a network site is deactivated.
   241 			 * Fires before a network site is deactivated.
   161 			 *
   242 			 *
   162 			 * @since MU
   243 			 * @since MU (3.0.0)
   163 			 *
   244 			 *
   164 			 * @param string $id The ID of the site being deactivated.
   245 			 * @param string $id The ID of the site being deactivated.
   165 			 */
   246 			 */
   166 			do_action( 'deactivate_blog', $id );
   247 			do_action( 'deactivate_blog', $id );
   167 			update_blog_status( $id, 'deleted', '1' );
   248 			update_blog_status( $id, 'deleted', '1' );
   176 		case 'matureblog':
   257 		case 'matureblog':
   177 			update_blog_status( $id, 'mature', ( 'matureblog' === $_GET['action'] ) ? '1' : '0' );
   258 			update_blog_status( $id, 'mature', ( 'matureblog' === $_GET['action'] ) ? '1' : '0' );
   178 		break;
   259 		break;
   179 	}
   260 	}
   180 
   261 
   181 	if ( empty( $updated_action ) && in_array( $_GET['action'], $manage_actions ) )
   262 	if ( empty( $updated_action ) && array_key_exists( $_GET['action'], $manage_actions ) ) {
   182 		$updated_action = $_GET['action'];
   263 		$updated_action = $_GET['action'];
       
   264 	}
   183 
   265 
   184 	if ( ! empty( $updated_action ) ) {
   266 	if ( ! empty( $updated_action ) ) {
   185 		wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
   267 		wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
   186 		exit();
   268 		exit();
   187 	}
   269 	}
   201 		break;
   283 		break;
   202 		case 'delete':
   284 		case 'delete':
   203 			$msg = __( 'Site deleted.' );
   285 			$msg = __( 'Site deleted.' );
   204 		break;
   286 		break;
   205 		case 'not_deleted':
   287 		case 'not_deleted':
   206 			$msg = __( 'You do not have permission to delete that site.' );
   288 			$msg = __( 'Sorry, you are not allowed to delete that site.' );
   207 		break;
   289 		break;
   208 		case 'archiveblog':
   290 		case 'archiveblog':
   209 			$msg = __( 'Site archived.' );
   291 			$msg = __( 'Site archived.' );
   210 		break;
   292 		break;
   211 		case 'unarchiveblog':
   293 		case 'unarchiveblog':
   223 		case 'spamblog':
   305 		case 'spamblog':
   224 			$msg = __( 'Site marked as spam.' );
   306 			$msg = __( 'Site marked as spam.' );
   225 		break;
   307 		break;
   226 		default:
   308 		default:
   227 			/**
   309 			/**
   228 			 * Filter a specific, non-default site-updated message in the Network admin.
   310 			 * Filters a specific, non-default site-updated message in the Network admin.
   229 			 *
   311 			 *
   230 			 * The dynamic portion of the hook name, `$_GET['updated']`, refers to the
   312 			 * The dynamic portion of the hook name, `$_GET['updated']`, refers to the
   231 			 * non-default site update action.
   313 			 * non-default site update action.
   232 			 *
   314 			 *
   233 			 * @since 3.1.0
   315 			 * @since 3.1.0
   237 			$msg = apply_filters( 'network_sites_updated_message_' . $_GET['updated'], __( 'Settings saved.' ) );
   319 			$msg = apply_filters( 'network_sites_updated_message_' . $_GET['updated'], __( 'Settings saved.' ) );
   238 		break;
   320 		break;
   239 	}
   321 	}
   240 
   322 
   241 	if ( ! empty( $msg ) )
   323 	if ( ! empty( $msg ) )
   242 		$msg = '<div class="updated" id="message notice is-dismissible"><p>' . $msg . '</p></div>';
   324 		$msg = '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
   243 }
   325 }
   244 
   326 
   245 $wp_list_table->prepare_items();
   327 $wp_list_table->prepare_items();
   246 
   328 
   247 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   329 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   248 ?>
   330 ?>
   249 
   331 
   250 <div class="wrap">
   332 <div class="wrap">
   251 <h2><?php _e( 'Sites' ) ?>
   333 <h1 class="wp-heading-inline"><?php _e( 'Sites' ); ?></h1>
   252 
   334 
   253 <?php if ( current_user_can( 'create_sites') ) : ?>
   335 <?php if ( current_user_can( 'create_sites') ) : ?>
   254 	<a href="<?php echo network_admin_url('site-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
   336 	<a href="<?php echo network_admin_url('site-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
   255 <?php endif; ?>
   337 <?php endif; ?>
   256 
   338 
   257 <?php if ( isset( $_REQUEST['s'] ) && $_REQUEST['s'] ) {
   339 <?php
       
   340 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
       
   341 	/* translators: %s: search keywords */
   258 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
   342 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
   259 } ?>
   343 }
   260 </h2>
   344 ?>
       
   345 
       
   346 <hr class="wp-header-end">
   261 
   347 
   262 <?php echo $msg; ?>
   348 <?php echo $msg; ?>
   263 
   349 
   264 <form method="get" id="ms-search">
   350 <form method="get" id="ms-search">
   265 <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
   351 <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>