web/wp-admin/network/sites.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    14 	wp_die( __( 'Multisite support is not enabled.' ) );
    14 	wp_die( __( 'Multisite support is not enabled.' ) );
    15 
    15 
    16 if ( ! current_user_can( 'manage_sites' ) )
    16 if ( ! current_user_can( 'manage_sites' ) )
    17 	wp_die( __( 'You do not have permission to access this page.' ) );
    17 	wp_die( __( 'You do not have permission to access this page.' ) );
    18 
    18 
    19 $wp_list_table = _get_list_table('WP_MS_Sites_List_Table');
    19 $wp_list_table = _get_list_table( 'WP_MS_Sites_List_Table' );
    20 $pagenum = $wp_list_table->get_pagenum();
    20 $pagenum = $wp_list_table->get_pagenum();
    21 
    21 
    22 $title = __( 'Sites' );
    22 $title = __( 'Sites' );
    23 $parent_file = 'sites.php';
    23 $parent_file = 'sites.php';
    24 
    24 
    25 add_screen_option( 'per_page', array('label' => _x( 'Sites', 'sites per page (screen options)' )) );
    25 add_screen_option( 'per_page', array( 'label' => _x( 'Sites', 'sites per page (screen options)' ) ) );
    26 
    26 
    27 get_current_screen()->add_help_tab( array(
    27 get_current_screen()->add_help_tab( array(
    28 	'id'      => 'overview',
    28 	'id'      => 'overview',
    29 	'title'   => __('Overview'),
    29 	'title'   => __('Overview'),
    30 	'content' =>
    30 	'content' =>
    49 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    49 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    50 
    50 
    51 if ( isset( $_GET['action'] ) ) {
    51 if ( isset( $_GET['action'] ) ) {
    52 	do_action( 'wpmuadminedit' , '' );
    52 	do_action( 'wpmuadminedit' , '' );
    53 
    53 
       
    54 	if ( 'confirm' === $_GET['action'] ) {
       
    55 		check_admin_referer( 'confirm' );
       
    56 
       
    57 		if ( ! headers_sent() ) {
       
    58 			nocache_headers();
       
    59 			header( 'Content-Type: text/html; charset=utf-8' );
       
    60 		}
       
    61 		if ( $current_site->blog_id == $id )
       
    62 			wp_die( __( 'You are not allowed to change the current site.' ) );
       
    63 		?>
       
    64 		<!DOCTYPE html>
       
    65 		<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
       
    66 			<head>
       
    67 				<title><?php _e( 'WordPress &rsaquo; Confirm your action' ); ?></title>
       
    68 
       
    69 				<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       
    70 				<?php
       
    71 				wp_admin_css( 'install', true );
       
    72 				wp_admin_css( 'ie', true );
       
    73 				?>
       
    74 			</head>
       
    75 			<body class="wp-core-ui">
       
    76 				<h1 id="logo"><a href="<?php esc_attr_e( 'http://wordpress.org/' ); ?>"><?php _e( 'WordPress' ); ?></a></h1>
       
    77 				<form action="sites.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
       
    78 					<input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
       
    79 					<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
       
    80 					<input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
       
    81 					<?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
       
    82 					<p><?php echo esc_html( stripslashes( $_GET['msg'] ) ); ?></p>
       
    83 					<?php submit_button( __('Confirm'), 'button' ); ?>
       
    84 				</form>
       
    85 			</body>
       
    86 		</html>
       
    87 		<?php
       
    88 		exit();
       
    89 	}
       
    90 
       
    91 	$updated_action = '';
       
    92 
       
    93 	$manage_actions = array( 'deleteblog', 'allblogs', 'archiveblog', 'unarchiveblog', 'activateblog', 'deactivateblog', 'unspamblog', 'spamblog', 'unmatureblog', 'matureblog' );
       
    94 	if ( in_array( $_GET['action'], $manage_actions ) ) {
       
    95 		$action = $_GET['action'];
       
    96 		if ( 'allblogs' === $action )
       
    97 			$action = 'bulk-sites';
       
    98 
       
    99 		check_admin_referer( $action );
       
   100 	}
       
   101 
    54 	switch ( $_GET['action'] ) {
   102 	switch ( $_GET['action'] ) {
    55 		case 'updateblog':
       
    56 			// No longer used.
       
    57 		break;
       
    58 
   103 
    59 		case 'deleteblog':
   104 		case 'deleteblog':
    60 			check_admin_referer('deleteblog');
   105 			if ( ! current_user_can( 'delete_sites' ) )
    61 			if ( ! ( current_user_can( 'manage_sites' ) && current_user_can( 'delete_sites' ) ) )
       
    62 				wp_die( __( 'You do not have permission to access this page.' ) );
   106 				wp_die( __( 'You do not have permission to access this page.' ) );
    63 
   107 
       
   108 			$updated_action = 'not_deleted';
    64 			if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) {
   109 			if ( $id != '0' && $id != $current_site->blog_id && current_user_can( 'delete_site', $id ) ) {
    65 				wpmu_delete_blog( $id, true );
   110 				wpmu_delete_blog( $id, true );
    66 				wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
   111 				$updated_action = 'delete';
    67 			} else {
       
    68 				wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'not_deleted' ), wp_get_referer() ) );
       
    69 			}
   112 			}
    70 
       
    71 			exit();
       
    72 		break;
   113 		break;
    73 
   114 
    74 		case 'allblogs':
   115 		case 'allblogs':
    75 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
   116 			if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allblogs'] ) ) {
    76 				check_admin_referer( 'bulk-sites' );
       
    77 
       
    78 				if ( ! current_user_can( 'manage_sites' ) )
       
    79 					wp_die( __( 'You do not have permission to access this page.' ) );
       
    80 
       
    81 				$doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
   117 				$doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
    82 				$blogfunction = '';
       
    83 
   118 
    84 				foreach ( (array) $_POST['allblogs'] as $key => $val ) {
   119 				foreach ( (array) $_POST['allblogs'] as $key => $val ) {
    85 					if ( $val != '0' && $val != $current_site->blog_id ) {
   120 					if ( $val != '0' && $val != $current_site->blog_id ) {
    86 						switch ( $doaction ) {
   121 						switch ( $doaction ) {
    87 							case 'delete':
   122 							case 'delete':
    88 								if ( ! current_user_can( 'delete_site', $val ) )
   123 								if ( ! current_user_can( 'delete_site', $val ) )
    89 									wp_die( __( 'You are not allowed to delete the site.' ) );
   124 									wp_die( __( 'You are not allowed to delete the site.' ) );
    90 								$blogfunction = 'all_delete';
   125 
       
   126 								$updated_action = 'all_delete';
    91 								wpmu_delete_blog( $val, true );
   127 								wpmu_delete_blog( $val, true );
    92 							break;
   128 							break;
    93 
   129 
    94 							case 'spam':
   130 							case 'spam':
    95 								$blogfunction = 'all_spam';
       
    96 								update_blog_status( $val, 'spam', '1' );
       
    97 								set_time_limit( 60 );
       
    98 							break;
       
    99 
       
   100 							case 'notspam':
   131 							case 'notspam':
   101 								$blogfunction = 'all_notspam';
   132 								$updated_action = ( 'spam' === $doaction ) ? 'all_spam' : 'all_notspam';
   102 								update_blog_status( $val, 'spam', '0' );
   133 								update_blog_status( $val, 'spam', ( 'spam' === $doaction ) ? '1' : '0' );
   103 								set_time_limit( 60 );
       
   104 							break;
   134 							break;
   105 						}
   135 						}
   106 					} else {
   136 					} else {
   107 						wp_die( __( 'You are not allowed to change the current site.' ) );
   137 						wp_die( __( 'You are not allowed to change the current site.' ) );
   108 					}
   138 					}
   109 				}
   139 				}
   110 
       
   111 				wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $blogfunction ), wp_get_referer() ) );
       
   112 			} else {
   140 			} else {
   113 				wp_redirect( network_admin_url( 'sites.php' ) );
   141 				wp_redirect( network_admin_url( 'sites.php' ) );
       
   142 				exit();
   114 			}
   143 			}
   115 			exit();
       
   116 		break;
   144 		break;
   117 
   145 
   118 		case 'archiveblog':
   146 		case 'archiveblog':
   119 			check_admin_referer( 'archiveblog' );
       
   120 			if ( ! current_user_can( 'manage_sites' ) )
       
   121 				wp_die( __( 'You do not have permission to access this page.' ) );
       
   122 
       
   123 			update_blog_status( $id, 'archived', '1' );
       
   124 			wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'archive' ), wp_get_referer() ) );
       
   125 			exit();
       
   126 		break;
       
   127 
       
   128 		case 'unarchiveblog':
   147 		case 'unarchiveblog':
   129 			check_admin_referer( 'unarchiveblog' );
   148 			update_blog_status( $id, 'archived', ( 'archiveblog' === $_GET['action'] ) ? '1' : '0' );
   130 			if ( ! current_user_can( 'manage_sites' ) )
       
   131 				wp_die( __( 'You do not have permission to access this page.' ) );
       
   132 
       
   133 			update_blog_status( $id, 'archived', '0' );
       
   134 			wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unarchive' ), wp_get_referer() ) );
       
   135 			exit();
       
   136 		break;
   149 		break;
   137 
   150 
   138 		case 'activateblog':
   151 		case 'activateblog':
   139 			check_admin_referer( 'activateblog' );
       
   140 			if ( ! current_user_can( 'manage_sites' ) )
       
   141 				wp_die( __( 'You do not have permission to access this page.' ) );
       
   142 
       
   143 			update_blog_status( $id, 'deleted', '0' );
   152 			update_blog_status( $id, 'deleted', '0' );
   144 			do_action( 'activate_blog', $id );
   153 			do_action( 'activate_blog', $id );
   145 			wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'activate' ), wp_get_referer() ) );
       
   146 			exit();
       
   147 		break;
   154 		break;
   148 
   155 
   149 		case 'deactivateblog':
   156 		case 'deactivateblog':
   150 			check_admin_referer( 'deactivateblog' );
       
   151 			if ( ! current_user_can( 'manage_sites' ) )
       
   152 				wp_die( __( 'You do not have permission to access this page.' ) );
       
   153 
       
   154 			do_action( 'deactivate_blog', $id );
   157 			do_action( 'deactivate_blog', $id );
   155 			update_blog_status( $id, 'deleted', '1' );
   158 			update_blog_status( $id, 'deleted', '1' );
   156 			wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'deactivate' ), wp_get_referer() ) );
       
   157 			exit();
       
   158 		break;
   159 		break;
   159 
   160 
   160 		case 'unspamblog':
   161 		case 'unspamblog':
   161 			check_admin_referer( 'unspamblog' );
       
   162 			if ( ! current_user_can( 'manage_sites' ) )
       
   163 				wp_die( __( 'You do not have permission to access this page.' ) );
       
   164 
       
   165 			update_blog_status( $id, 'spam', '0' );
       
   166 			wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unspam' ), wp_get_referer() ) );
       
   167 			exit();
       
   168 		break;
       
   169 
       
   170 		case 'spamblog':
   162 		case 'spamblog':
   171 			check_admin_referer( 'spamblog' );
   163 			update_blog_status( $id, 'spam', ( 'spamblog' === $_GET['action'] ) ? '1' : '0' );
   172 			if ( ! current_user_can( 'manage_sites' ) )
       
   173 				wp_die( __( 'You do not have permission to access this page.' ) );
       
   174 
       
   175 			update_blog_status( $id, 'spam', '1' );
       
   176 			wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'spam' ), wp_get_referer() ) );
       
   177 			exit();
       
   178 		break;
   164 		break;
   179 
   165 
   180 		case 'unmatureblog':
   166 		case 'unmatureblog':
   181 			check_admin_referer( 'unmatureblog' );
       
   182 			if ( ! current_user_can( 'manage_sites' ) )
       
   183 				wp_die( __( 'You do not have permission to access this page.' ) );
       
   184 
       
   185 			update_blog_status( $id, 'mature', '0' );
       
   186 			wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unmature' ), wp_get_referer() ) );
       
   187 			exit();
       
   188 		break;
       
   189 
       
   190 		case 'matureblog':
   167 		case 'matureblog':
   191 			check_admin_referer( 'matureblog' );
   168 			update_blog_status( $id, 'mature', ( 'matureblog' === $_GET['action'] ) ? '1' : '0' );
   192 			if ( ! current_user_can( 'manage_sites' ) )
   169 		break;
   193 				wp_die( __( 'You do not have permission to access this page.' ) );
   170 	}
   194 
   171 
   195 			update_blog_status( $id, 'mature', '1' );
   172 	if ( empty( $updated_action ) && in_array( $_GET['action'], $manage_actions ) )
   196 			wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'mature' ), wp_get_referer() ) );
   173 		$updated_action = $_GET['action'];
   197 			exit();
   174 
   198 		break;
   175 	if ( ! empty( $updated_action ) ) {
   199 
   176 		wp_safe_redirect( add_query_arg( array( 'updated' => $updated_action ), wp_get_referer() ) );
   200 		// Common
   177 		exit();
   201 		case 'confirm':
       
   202 			check_admin_referer( 'confirm' );
       
   203 			if ( !headers_sent() ) {
       
   204 				nocache_headers();
       
   205 				header( 'Content-Type: text/html; charset=utf-8' );
       
   206 			}
       
   207 			if ( $current_site->blog_id == $id )
       
   208 				wp_die( __( 'You are not allowed to change the current site.' ) );
       
   209 			?>
       
   210 			<!DOCTYPE html>
       
   211 			<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>
       
   212 				<head>
       
   213 					<title><?php _e( 'WordPress &rsaquo; Confirm your action' ); ?></title>
       
   214 
       
   215 					<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       
   216 					<?php
       
   217 					wp_admin_css( 'install', true );
       
   218 					wp_admin_css( 'ie', true );
       
   219 					?>
       
   220 				</head>
       
   221 				<body>
       
   222 					<h1 id="logo"><img alt="WordPress" src="<?php echo esc_attr( admin_url( 'images/wordpress-logo.png?ver=20120216' ) ); ?>" /></h1>
       
   223 					<form action="sites.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
       
   224 						<input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
       
   225 						<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
       
   226 						<input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
       
   227 						<?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
       
   228 						<p><?php echo esc_html( stripslashes( $_GET['msg'] ) ); ?></p>
       
   229 						<?php submit_button( __('Confirm'), 'button' ); ?>
       
   230 					</form>
       
   231 				</body>
       
   232 			</html>
       
   233 			<?php
       
   234 			exit();
       
   235 		break;
       
   236 	}
   178 	}
   237 }
   179 }
   238 
   180 
   239 $msg = '';
   181 $msg = '';
   240 if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
   182 if ( isset( $_GET['updated'] ) ) {
   241 	switch ( $_REQUEST['action'] ) {
   183 	switch ( $_GET['updated'] ) {
   242 		case 'all_notspam':
   184 		case 'all_notspam':
   243 			$msg = __( 'Sites removed from spam.' );
   185 			$msg = __( 'Sites removed from spam.' );
   244 		break;
   186 		break;
   245 		case 'all_spam':
   187 		case 'all_spam':
   246 			$msg = __( 'Sites marked as spam.' );
   188 			$msg = __( 'Sites marked as spam.' );
   252 			$msg = __( 'Site deleted.' );
   194 			$msg = __( 'Site deleted.' );
   253 		break;
   195 		break;
   254 		case 'not_deleted':
   196 		case 'not_deleted':
   255 			$msg = __( 'You do not have permission to delete that site.' );
   197 			$msg = __( 'You do not have permission to delete that site.' );
   256 		break;
   198 		break;
   257 		case 'archive':
   199 		case 'archiveblog':
   258 			$msg = __( 'Site archived.' );
   200 			$msg = __( 'Site archived.' );
   259 		break;
   201 		break;
   260 		case 'unarchive':
   202 		case 'unarchiveblog':
   261 			$msg = __( 'Site unarchived.' );
   203 			$msg = __( 'Site unarchived.' );
   262 		break;
   204 		break;
   263 		case 'activate':
   205 		case 'activateblog':
   264 			$msg = __( 'Site activated.' );
   206 			$msg = __( 'Site activated.' );
   265 		break;
   207 		break;
   266 		case 'deactivate':
   208 		case 'deactivateblog':
   267 			$msg = __( 'Site deactivated.' );
   209 			$msg = __( 'Site deactivated.' );
   268 		break;
   210 		break;
   269 		case 'unspam':
   211 		case 'unspamblog':
   270 			$msg = __( 'Site removed from spam.' );
   212 			$msg = __( 'Site removed from spam.' );
   271 		break;
   213 		break;
   272 		case 'spam':
   214 		case 'spamblog':
   273 			$msg = __( 'Site marked as spam.' );
   215 			$msg = __( 'Site marked as spam.' );
   274 		break;
   216 		break;
   275 		default:
   217 		default:
   276 			$msg = apply_filters( 'network_sites_updated_message_' . $_REQUEST['action'] , __( 'Settings saved.' ) );
   218 			$msg = apply_filters( 'network_sites_updated_message_' . $_GET['updated'], __( 'Settings saved.' ) );
   277 		break;
   219 		break;
   278 	}
   220 	}
   279 	if ( $msg )
   221 
       
   222 	if ( ! empty( $msg ) )
   280 		$msg = '<div class="updated" id="message"><p>' . $msg . '</p></div>';
   223 		$msg = '<div class="updated" id="message"><p>' . $msg . '</p></div>';
   281 }
   224 }
   282 
   225 
   283 $wp_list_table->prepare_items();
   226 $wp_list_table->prepare_items();
   284 
   227 
   285 require_once( '../admin-header.php' );
   228 require_once( '../admin-header.php' );
   286 ?>
   229 ?>
   287 
   230 
   288 <div class="wrap">
   231 <div class="wrap">
   289 <?php screen_icon('ms-admin'); ?>
   232 <?php screen_icon( 'ms-admin' ); ?>
   290 <h2><?php _e('Sites') ?>
   233 <h2><?php _e( 'Sites' ) ?>
   291 <?php echo $msg; ?>
   234 
   292 <?php if ( current_user_can( 'create_sites') ) : ?>
   235 <?php if ( current_user_can( 'create_sites') ) : ?>
   293         <a href="<?php echo network_admin_url('site-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
   236 	<a href="<?php echo network_admin_url('site-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'site' ); ?></a>
   294 <?php endif; ?>
   237 <?php endif; ?>
   295 
   238 
   296 <?php if ( isset( $_REQUEST['s'] ) && $_REQUEST['s'] ) {
   239 <?php if ( isset( $_REQUEST['s'] ) && $_REQUEST['s'] ) {
   297 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
   240 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $s ) );
   298 } ?>
   241 } ?>
   299 </h2>
   242 </h2>
       
   243 
       
   244 <?php echo $msg; ?>
   300 
   245 
   301 <form action="" method="get" id="ms-search">
   246 <form action="" method="get" id="ms-search">
   302 <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
   247 <?php $wp_list_table->search_box( __( 'Search Sites' ), 'site' ); ?>
   303 <input type="hidden" name="action" value="blogs" />
   248 <input type="hidden" name="action" value="blogs" />
   304 </form>
   249 </form>