wp/wp-admin/network/sites.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
     6  * @subpackage Multisite
     6  * @subpackage Multisite
     7  * @since 3.0.0
     7  * @since 3.0.0
     8  */
     8  */
     9 
     9 
    10 /** Load WordPress Administration Bootstrap */
    10 /** Load WordPress Administration Bootstrap */
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require_once __DIR__ . '/admin.php';
    12 
    12 
    13 if ( ! current_user_can( 'manage_sites' ) ) {
    13 if ( ! current_user_can( 'manage_sites' ) ) {
    14 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    14 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    15 }
    15 }
    16 
    16 
    40 	)
    40 	)
    41 );
    41 );
    42 
    42 
    43 get_current_screen()->set_help_sidebar(
    43 get_current_screen()->set_help_sidebar(
    44 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    44 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    45 	'<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen">Documentation on Site Management</a>' ) . '</p>' .
    45 	'<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-sites-screen/">Documentation on Site Management</a>' ) . '</p>' .
    46 	'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
    46 	'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
    47 );
    47 );
    48 
    48 
    49 get_current_screen()->set_screen_reader_content(
    49 get_current_screen()->set_screen_reader_content(
    50 	array(
    50 	array(
    59 	/** This action is documented in wp-admin/network/edit.php */
    59 	/** This action is documented in wp-admin/network/edit.php */
    60 	do_action( 'wpmuadminedit' );
    60 	do_action( 'wpmuadminedit' );
    61 
    61 
    62 	// A list of valid actions and their associated messaging for confirmation output.
    62 	// A list of valid actions and their associated messaging for confirmation output.
    63 	$manage_actions = array(
    63 	$manage_actions = array(
       
    64 		/* translators: %s: Site URL. */
    64 		'activateblog'   => __( 'You are about to activate the site %s.' ),
    65 		'activateblog'   => __( 'You are about to activate the site %s.' ),
       
    66 		/* translators: %s: Site URL. */
    65 		'deactivateblog' => __( 'You are about to deactivate the site %s.' ),
    67 		'deactivateblog' => __( 'You are about to deactivate the site %s.' ),
       
    68 		/* translators: %s: Site URL. */
    66 		'unarchiveblog'  => __( 'You are about to unarchive the site %s.' ),
    69 		'unarchiveblog'  => __( 'You are about to unarchive the site %s.' ),
       
    70 		/* translators: %s: Site URL. */
    67 		'archiveblog'    => __( 'You are about to archive the site %s.' ),
    71 		'archiveblog'    => __( 'You are about to archive the site %s.' ),
       
    72 		/* translators: %s: Site URL. */
    68 		'unspamblog'     => __( 'You are about to unspam the site %s.' ),
    73 		'unspamblog'     => __( 'You are about to unspam the site %s.' ),
       
    74 		/* translators: %s: Site URL. */
    69 		'spamblog'       => __( 'You are about to mark the site %s as spam.' ),
    75 		'spamblog'       => __( 'You are about to mark the site %s as spam.' ),
       
    76 		/* translators: %s: Site URL. */
    70 		'deleteblog'     => __( 'You are about to delete the site %s.' ),
    77 		'deleteblog'     => __( 'You are about to delete the site %s.' ),
       
    78 		/* translators: %s: Site URL. */
    71 		'unmatureblog'   => __( 'You are about to mark the site %s as mature.' ),
    79 		'unmatureblog'   => __( 'You are about to mark the site %s as mature.' ),
       
    80 		/* translators: %s: Site URL. */
    72 		'matureblog'     => __( 'You are about to mark the site %s as not mature.' ),
    81 		'matureblog'     => __( 'You are about to mark the site %s as not mature.' ),
    73 	);
    82 	);
    74 
    83 
    75 	if ( 'confirm' === $_GET['action'] ) {
    84 	if ( 'confirm' === $_GET['action'] ) {
    76 		// The action2 parameter contains the action being taken on the site.
    85 		// The action2 parameter contains the action being taken on the site.
    97 		}
   106 		}
    98 
   107 
    99 		$site_details = get_site( $id );
   108 		$site_details = get_site( $id );
   100 		$site_address = untrailingslashit( $site_details->domain . $site_details->path );
   109 		$site_address = untrailingslashit( $site_details->domain . $site_details->path );
   101 
   110 
   102 		require_once( ABSPATH . 'wp-admin/admin-header.php' );
   111 		require_once ABSPATH . 'wp-admin/admin-header.php';
   103 		?>
   112 		?>
   104 			<div class="wrap">
   113 			<div class="wrap">
   105 				<h1><?php _e( 'Confirm your action' ); ?></h1>
   114 				<h1><?php _e( 'Confirm your action' ); ?></h1>
   106 				<form action="sites.php?action=<?php echo esc_attr( $site_action ); ?>" method="post">
   115 				<form action="sites.php?action=<?php echo esc_attr( $site_action ); ?>" method="post">
   107 					<input type="hidden" name="action" value="<?php echo esc_attr( $site_action ); ?>" />
   116 					<input type="hidden" name="action" value="<?php echo esc_attr( $site_action ); ?>" />
   108 					<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
   117 					<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
   109 					<input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
   118 					<input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
   110 					<?php wp_nonce_field( $site_action . '_' . $id, '_wpnonce', false ); ?>
   119 					<?php wp_nonce_field( $site_action . '_' . $id, '_wpnonce', false ); ?>
   111 					<p><?php echo sprintf( $manage_actions[ $site_action ], $site_address ); ?></p>
   120 					<p><?php printf( $manage_actions[ $site_action ], $site_address ); ?></p>
   112 					<?php submit_button( __( 'Confirm' ), 'primary' ); ?>
   121 					<?php submit_button( __( 'Confirm' ), 'primary' ); ?>
   113 				</form>
   122 				</form>
   114 			</div>
   123 			</div>
   115 		<?php
   124 		<?php
   116 		require_once( ABSPATH . 'wp-admin/admin-footer.php' );
   125 		require_once ABSPATH . 'wp-admin/admin-footer.php';
   117 		exit();
   126 		exit;
   118 	} elseif ( array_key_exists( $_GET['action'], $manage_actions ) ) {
   127 	} elseif ( array_key_exists( $_GET['action'], $manage_actions ) ) {
   119 		$action = $_GET['action'];
   128 		$action = $_GET['action'];
   120 		check_admin_referer( $action . '_' . $id );
   129 		check_admin_referer( $action . '_' . $id );
   121 	} elseif ( 'allblogs' === $_GET['action'] ) {
   130 	} elseif ( 'allblogs' === $_GET['action'] ) {
   122 		check_admin_referer( 'bulk-sites' );
   131 		check_admin_referer( 'bulk-sites' );
   130 			if ( ! current_user_can( 'delete_sites' ) ) {
   139 			if ( ! current_user_can( 'delete_sites' ) ) {
   131 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), '', array( 'response' => 403 ) );
   140 				wp_die( __( 'Sorry, you are not allowed to access this page.' ), '', array( 'response' => 403 ) );
   132 			}
   141 			}
   133 
   142 
   134 			$updated_action = 'not_deleted';
   143 			$updated_action = 'not_deleted';
   135 			if ( $id != '0' && $id != get_network()->site_id && current_user_can( 'delete_site', $id ) ) {
   144 			if ( '0' != $id && get_network()->site_id != $id && current_user_can( 'delete_site', $id ) ) {
   136 				wpmu_delete_blog( $id, true );
   145 				wpmu_delete_blog( $id, true );
   137 				$updated_action = 'delete';
   146 				$updated_action = 'delete';
   138 			}
   147 			}
   139 			break;
   148 			break;
   140 
   149 
   142 			check_admin_referer( 'ms-delete-sites' );
   151 			check_admin_referer( 'ms-delete-sites' );
   143 
   152 
   144 			foreach ( (array) $_POST['site_ids'] as $site_id ) {
   153 			foreach ( (array) $_POST['site_ids'] as $site_id ) {
   145 				$site_id = (int) $site_id;
   154 				$site_id = (int) $site_id;
   146 
   155 
   147 				if ( $site_id == get_network()->site_id ) {
   156 				if ( get_network()->site_id == $site_id ) {
   148 					continue;
   157 					continue;
   149 				}
   158 				}
   150 
   159 
   151 				if ( ! current_user_can( 'delete_site', $site_id ) ) {
   160 				if ( ! current_user_can( 'delete_site', $site_id ) ) {
   152 					$site         = get_site( $site_id );
   161 					$site         = get_site( $site_id );
   153 					$site_address = untrailingslashit( $site->domain . $site->path );
   162 					$site_address = untrailingslashit( $site->domain . $site->path );
   154 
   163 
   155 					wp_die( sprintf( __( 'Sorry, you are not allowed to delete the site %s.' ), $site_address ), 403 );
   164 					wp_die(
       
   165 						sprintf(
       
   166 							/* translators: %s: Site URL. */
       
   167 							__( 'Sorry, you are not allowed to delete the site %s.' ),
       
   168 							$site_address
       
   169 						),
       
   170 						403
       
   171 					);
   156 				}
   172 				}
   157 
   173 
   158 				$updated_action = 'all_delete';
   174 				$updated_action = 'all_delete';
   159 				wpmu_delete_blog( $site_id, true );
   175 				wpmu_delete_blog( $site_id, true );
   160 			}
   176 			}
   161 			break;
   177 			break;
   162 
   178 
   163 		case 'allblogs':
   179 		case 'allblogs':
   164 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
   180 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
   165 				$doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
   181 				$doaction = -1 != $_POST['action'] ? $_POST['action'] : $_POST['action2'];
   166 
   182 
   167 				foreach ( (array) $_POST['allblogs'] as $key => $val ) {
   183 				foreach ( (array) $_POST['allblogs'] as $key => $val ) {
   168 					if ( $val != '0' && $val != get_network()->site_id ) {
   184 					if ( '0' != $val && get_network()->site_id != $val ) {
   169 						switch ( $doaction ) {
   185 						switch ( $doaction ) {
   170 							case 'delete':
   186 							case 'delete':
   171 								require_once( ABSPATH . 'wp-admin/admin-header.php' );
   187 								require_once ABSPATH . 'wp-admin/admin-header.php';
   172 								?>
   188 								?>
   173 								<div class="wrap">
   189 								<div class="wrap">
   174 									<h1><?php _e( 'Confirm your action' ); ?></h1>
   190 									<h1><?php _e( 'Confirm your action' ); ?></h1>
   175 									<form action="sites.php?action=delete_sites" method="post">
   191 									<form action="sites.php?action=delete_sites" method="post">
   176 										<input type="hidden" name="action" value="delete_sites" />
   192 										<input type="hidden" name="action" value="delete_sites" />
   191 										</ul>
   207 										</ul>
   192 										<?php submit_button( __( 'Confirm' ), 'primary' ); ?>
   208 										<?php submit_button( __( 'Confirm' ), 'primary' ); ?>
   193 									</form>
   209 									</form>
   194 								</div>
   210 								</div>
   195 								<?php
   211 								<?php
   196 								require_once( ABSPATH . 'wp-admin/admin-footer.php' );
   212 								require_once ABSPATH . 'wp-admin/admin-footer.php';
   197 								exit();
   213 								exit;
   198 							break;
   214 							break;
   199 
   215 
   200 							case 'spam':
   216 							case 'spam':
   201 							case 'notspam':
   217 							case 'notspam':
   202 								$updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
   218 								$updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
   205 						}
   221 						}
   206 					} else {
   222 					} else {
   207 						wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
   223 						wp_die( __( 'Sorry, you are not allowed to change the current site.' ) );
   208 					}
   224 					}
   209 				}
   225 				}
       
   226 
   210 				if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
   227 				if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
   211 					$redirect_to = wp_get_referer();
   228 					$redirect_to = wp_get_referer();
   212 					$blogs       = (array) $_POST['allblogs'];
   229 					$blogs       = (array) $_POST['allblogs'];
       
   230 
   213 					/** This action is documented in wp-admin/network/site-themes.php */
   231 					/** This action is documented in wp-admin/network/site-themes.php */
   214 					$redirect_to = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id );
   232 					$redirect_to = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $redirect_to, $doaction, $blogs, $id ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
       
   233 
   215 					wp_safe_redirect( $redirect_to );
   234 					wp_safe_redirect( $redirect_to );
   216 					exit();
   235 					exit;
   217 				}
   236 				}
   218 			} else {
   237 			} else {
   219 				$location = network_admin_url( 'sites.php' );
   238 				// Process query defined by WP_MS_Site_List_Table::extra_table_nav().
   220 				if ( ! empty( $_REQUEST['paged'] ) ) {
   239 				$location = remove_query_arg(
   221 					$location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
   240 					array( '_wp_http_referer', '_wpnonce' ),
   222 				}
   241 					add_query_arg( $_POST, network_admin_url( 'sites.php' ) )
       
   242 				);
       
   243 
   223 				wp_redirect( $location );
   244 				wp_redirect( $location );
   224 				exit();
   245 				exit;
   225 			}
   246 			}
       
   247 
   226 			break;
   248 			break;
   227 
   249 
   228 		case 'archiveblog':
   250 		case 'archiveblog':
   229 		case 'unarchiveblog':
   251 		case 'unarchiveblog':
   230 			update_blog_status( $id, 'archived', ( 'archiveblog' === $_GET['action'] ) ? '1' : '0' );
   252 			update_blog_status( $id, 'archived', ( 'archiveblog' === $_GET['action'] ) ? '1' : '0' );
   250 			 * @since MU (3.0.0)
   272 			 * @since MU (3.0.0)
   251 			 *
   273 			 *
   252 			 * @param string $id The ID of the site being deactivated.
   274 			 * @param string $id The ID of the site being deactivated.
   253 			 */
   275 			 */
   254 			do_action( 'deactivate_blog', $id );
   276 			do_action( 'deactivate_blog', $id );
       
   277 
   255 			update_blog_status( $id, 'deleted', '1' );
   278 			update_blog_status( $id, 'deleted', '1' );
   256 			break;
   279 			break;
   257 
   280 
   258 		case 'unspamblog':
   281 		case 'unspamblog':
   259 		case 'spamblog':
   282 		case 'spamblog':
   270 		$updated_action = $_GET['action'];
   293 		$updated_action = $_GET['action'];
   271 	}
   294 	}
   272 
   295 
   273 	if ( ! empty( $updated_action ) ) {
   296 	if ( ! empty( $updated_action ) ) {
   274 		wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
   297 		wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
   275 		exit();
   298 		exit;
   276 	}
   299 	}
   277 }
   300 }
   278 
   301 
   279 $msg = '';
   302 $msg = '';
   280 if ( isset( $_GET['updated'] ) ) {
   303 if ( isset( $_GET['updated'] ) ) {
   334 	}
   357 	}
   335 }
   358 }
   336 
   359 
   337 $wp_list_table->prepare_items();
   360 $wp_list_table->prepare_items();
   338 
   361 
   339 require_once( ABSPATH . 'wp-admin/admin-header.php' );
   362 require_once ABSPATH . 'wp-admin/admin-header.php';
   340 ?>
   363 ?>
   341 
   364 
   342 <div class="wrap">
   365 <div class="wrap">
   343 <h1 class="wp-heading-inline"><?php _e( 'Sites' ); ?></h1>
   366 <h1 class="wp-heading-inline"><?php _e( 'Sites' ); ?></h1>
   344 
   367 
   346 	<a href="<?php echo network_admin_url( 'site-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
   369 	<a href="<?php echo network_admin_url( 'site-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
   347 <?php endif; ?>
   370 <?php endif; ?>
   348 
   371 
   349 <?php
   372 <?php
   350 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
   373 if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
   351 	/* translators: %s: search keywords */
   374 	/* translators: %s: Search query. */
   352 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
   375 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
   353 }
   376 }
   354 ?>
   377 ?>
   355 
   378 
   356 <hr class="wp-header-end">
   379 <hr class="wp-header-end">
       
   380 
       
   381 <?php $wp_list_table->views(); ?>
   357 
   382 
   358 <?php echo $msg; ?>
   383 <?php echo $msg; ?>
   359 
   384 
   360 <form method="get" id="ms-search" class="wp-clearfix">
   385 <form method="get" id="ms-search" class="wp-clearfix">
   361 <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
   386 <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
   366 	<?php $wp_list_table->display(); ?>
   391 	<?php $wp_list_table->display(); ?>
   367 </form>
   392 </form>
   368 </div>
   393 </div>
   369 <?php
   394 <?php
   370 
   395 
   371 require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>
   396 require_once ABSPATH . 'wp-admin/admin-footer.php'; ?>