wp/wp-admin/network/site-info.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() )
    13 if ( ! current_user_can( 'manage_sites' ) ) {
    14 	wp_die( __( 'Multisite support is not enabled.' ) );
    14 	wp_die( __( 'Sorry, you are not allowed to edit this site.' ) );
       
    15 }
    15 
    16 
    16 if ( ! current_user_can( 'manage_sites' ) )
    17 get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
    17 	wp_die( __( 'You do not have sufficient permissions to edit this site.' ) );
    18 get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
    18 
       
    19 	get_current_screen()->add_help_tab( array(
       
    20 		'id'      => 'overview',
       
    21 		'title'   => __('Overview'),
       
    22 		'content' =>
       
    23 			'<p>' . __('The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.') . '</p>' .
       
    24 			'<p>' . __('<strong>Info</strong> - The domain and path are rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.') . '</p>' .
       
    25 			'<p>' . __('<strong>Users</strong> - This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.') . '</p>' .
       
    26 			'<p>' . sprintf( __('<strong>Themes</strong> - This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site&#8217;s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' .
       
    27 			'<p>' . __('<strong>Settings</strong> - This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.') . '</p>'
       
    28 ) );
       
    29 
       
    30 get_current_screen()->set_help_sidebar(
       
    31 	'<p><strong>' . __('For more information:') . '</strong></p>' .
       
    32 	'<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' .
       
    33 	'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
       
    34 );
       
    35 
    19 
    36 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    20 $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
    37 
    21 
    38 if ( ! $id )
    22 if ( ! $id ) {
    39 	wp_die( __('Invalid site ID.') );
    23 	wp_die( __('Invalid site ID.') );
       
    24 }
    40 
    25 
    41 $details = get_blog_details( $id );
    26 $details = get_site( $id );
    42 if ( !can_edit_network( $details->site_id ) )
    27 if ( ! $details ) {
    43 	wp_die( __( 'You do not have permission to access this page.' ), 403 );
    28 	wp_die( __( 'The requested site does not exist.' ) );
       
    29 }
    44 
    30 
    45 $parsed = parse_url( $details->siteurl );
    31 if ( ! can_edit_network( $details->site_id ) ) {
       
    32 	wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
       
    33 }
       
    34 
       
    35 $parsed_scheme = parse_url( $details->siteurl, PHP_URL_SCHEME );
    46 $is_main_site = is_main_site( $id );
    36 $is_main_site = is_main_site( $id );
    47 
    37 
    48 if ( isset($_REQUEST['action']) && 'update-site' == $_REQUEST['action'] ) {
    38 if ( isset( $_REQUEST['action'] ) && 'update-site' == $_REQUEST['action'] ) {
    49 	check_admin_referer( 'edit-site' );
    39 	check_admin_referer( 'edit-site' );
    50 
    40 
    51 	switch_to_blog( $id );
    41 	switch_to_blog( $id );
    52 
    42 
    53 	// Rewrite rules can't be flushed during switch to blog.
    43 	// Rewrite rules can't be flushed during switch to blog.
    54 	delete_option( 'rewrite_rules' );
    44 	delete_option( 'rewrite_rules' );
    55 
    45 
    56 	// Update blogs table.
       
    57 	$blog_data = wp_unslash( $_POST['blog'] );
    46 	$blog_data = wp_unslash( $_POST['blog'] );
    58 	$existing_details = get_blog_details( $id, false );
    47 	$blog_data['scheme'] = $parsed_scheme;
       
    48 
       
    49 	if ( $is_main_site ) {
       
    50 		// On the network's main site, don't allow the domain or path to change.
       
    51 		$blog_data['domain'] = $details->domain;
       
    52 		$blog_data['path'] = $details->path;
       
    53 	} else {
       
    54 		// For any other site, the scheme, domain, and path can all be changed. We first
       
    55 		// need to ensure a scheme has been provided, otherwise fallback to the existing.
       
    56 		$new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME );
       
    57 
       
    58 		if ( ! $new_url_scheme ) {
       
    59 			$blog_data['url'] = esc_url( $parsed_scheme . '://' . $blog_data['url'] );
       
    60 		}
       
    61 		$update_parsed_url = parse_url( $blog_data['url'] );
       
    62 
       
    63 		// If a path is not provided, use the default of `/`.
       
    64 		if ( ! isset( $update_parsed_url['path'] ) ) {
       
    65 			$update_parsed_url['path'] = '/';
       
    66 		}
       
    67 
       
    68 		$blog_data['scheme'] = $update_parsed_url['scheme'];
       
    69 		$blog_data['domain'] = $update_parsed_url['host'];
       
    70 		$blog_data['path'] = $update_parsed_url['path'];
       
    71 	}
       
    72 
       
    73 	$existing_details = get_site( $id );
    59 	$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
    74 	$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
    60 	foreach ( $blog_data_checkboxes as $c ) {
    75 	foreach ( $blog_data_checkboxes as $c ) {
    61 		if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) )
    76 		if ( ! in_array( $existing_details->$c, array( 0, 1 ) ) ) {
    62 			$blog_data[ $c ] = $existing_details->$c;
    77 			$blog_data[ $c ] = $existing_details->$c;
    63 		else
    78 		} else {
    64 			$blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0;
    79 			$blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0;
    65 	}
       
    66 	update_blog_details( $id, $blog_data );
       
    67 
       
    68 	if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
       
    69 		$new_details = get_blog_details( $id, false );
       
    70 		$blog_address = esc_url_raw( $new_details->domain . $new_details->path );
       
    71 		if ( get_option( 'siteurl' ) != $blog_address ) {
       
    72 			update_option( 'siteurl', $blog_address );
       
    73 		}
       
    74 		if ( get_option( 'home' ) != $blog_address ) {
       
    75 			update_option( 'home', $blog_address );
       
    76 		}
    80 		}
    77 	}
    81 	}
    78 
    82 
       
    83 	update_blog_details( $id, $blog_data );
       
    84 
       
    85 	// Maybe update home and siteurl options.
       
    86 	$new_details = get_site( $id );
       
    87 
       
    88 	$old_home_url = trailingslashit( esc_url( get_option( 'home' ) ) );
       
    89 	$old_home_parsed = parse_url( $old_home_url );
       
    90 
       
    91 	if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
       
    92 		$new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
       
    93 		update_option( 'home', $new_home_url );
       
    94 	}
       
    95 
       
    96 	$old_site_url = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
       
    97 	$old_site_parsed = parse_url( $old_site_url );
       
    98 
       
    99 	if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
       
   100 		$new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
       
   101 		update_option( 'siteurl', $new_site_url );
       
   102 	}
       
   103 
    79 	restore_current_blog();
   104 	restore_current_blog();
    80 	wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-info.php') );
   105 	wp_redirect( add_query_arg( array( 'update' => 'updated', 'id' => $id ), 'site-info.php' ) );
    81 	exit;
   106 	exit;
    82 }
   107 }
    83 
   108 
    84 if ( isset($_GET['update']) ) {
   109 if ( isset( $_GET['update'] ) ) {
    85 	$messages = array();
   110 	$messages = array();
    86 	if ( 'updated' == $_GET['update'] )
   111 	if ( 'updated' == $_GET['update'] ) {
    87 		$messages[] = __('Site info updated.');
   112 		$messages[] = __( 'Site info updated.' );
       
   113 	}
    88 }
   114 }
    89 
   115 
    90 $site_url_no_http = preg_replace( '#^http(s)?://#', '', get_blogaddress_by_id( $id ) );
   116 /* translators: %s: site name */
    91 $title_site_url_linked = sprintf( __( 'Edit Site: %s' ), '<a href="' . get_blogaddress_by_id( $id ) . '">' . $site_url_no_http . '</a>' );
   117 $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
    92 $title = sprintf( __( 'Edit Site: %s' ), $site_url_no_http );
       
    93 
   118 
    94 $parent_file = 'sites.php';
   119 $parent_file = 'sites.php';
    95 $submenu_file = 'sites.php';
   120 $submenu_file = 'sites.php';
    96 
   121 
    97 require( ABSPATH . 'wp-admin/admin-header.php' );
   122 require( ABSPATH . 'wp-admin/admin-header.php' );
    98 
   123 
    99 ?>
   124 ?>
   100 
   125 
   101 <div class="wrap">
   126 <div class="wrap">
   102 <h2 id="edit-site"><?php echo $title_site_url_linked ?></h2>
   127 <h1 id="edit-site"><?php echo $title; ?></h1>
   103 <h3 class="nav-tab-wrapper">
   128 <p class="edit-site-actions"><a href="<?php echo esc_url( get_home_url( $id, '/' ) ); ?>"><?php _e( 'Visit' ); ?></a> | <a href="<?php echo esc_url( get_admin_url( $id ) ); ?>"><?php _e( 'Dashboard' ); ?></a></p>
   104 <?php
   129 <?php
   105 $tabs = array(
   130 
   106 	'site-info'     => array( 'label' => __( 'Info' ),     'url' => 'site-info.php'     ),
   131 network_edit_site_nav( array(
   107 	'site-users'    => array( 'label' => __( 'Users' ),    'url' => 'site-users.php'    ),
   132 	'blog_id'  => $id,
   108 	'site-themes'   => array( 'label' => __( 'Themes' ),   'url' => 'site-themes.php'   ),
   133 	'selected' => 'site-info'
   109 	'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
   134 ) );
   110 );
   135 
   111 foreach ( $tabs as $tab_id => $tab ) {
   136 if ( ! empty( $messages ) ) {
   112 	$class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
   137 	foreach ( $messages as $msg ) {
   113 	echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
   138 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
       
   139 	}
   114 }
   140 }
   115 ?>
   141 ?>
   116 </h3>
       
   117 <?php
       
   118 if ( ! empty( $messages ) ) {
       
   119 	foreach ( $messages as $msg )
       
   120 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
       
   121 } ?>
       
   122 <form method="post" action="site-info.php?action=update-site">
   142 <form method="post" action="site-info.php?action=update-site">
   123 	<?php wp_nonce_field( 'edit-site' ); ?>
   143 	<?php wp_nonce_field( 'edit-site' ); ?>
   124 	<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
   144 	<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
   125 	<table class="form-table">
   145 	<table class="form-table">
       
   146 		<?php
       
   147 		// The main site of the network should not be updated on this page.
       
   148 		if ( $is_main_site ) : ?>
       
   149 		<tr class="form-field">
       
   150 			<th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
       
   151 			<td><?php echo esc_url( $parsed_scheme . '://' . $details->domain . $details->path ); ?></td>
       
   152 		</tr>
       
   153 		<?php
       
   154 		// For any other site, the scheme, domain, and path can all be changed.
       
   155 		else : ?>
   126 		<tr class="form-field form-required">
   156 		<tr class="form-field form-required">
   127 			<?php if ( $is_main_site ) { ?>
   157 			<th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
   128 				<th scope="row"><?php _e( 'Domain' ) ?></th>
   158 			<td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
   129 				<td><code><?php echo $parsed['scheme'] . '://' . esc_attr( $details->domain ) ?></code></td>
       
   130 			<?php } else { ?>
       
   131 				<th scope="row"><label for="domain"><?php _e( 'Domain' ) ?></label></th>
       
   132 				<td><?php echo $parsed['scheme'] . '://'; ?><input name="blog[domain]" type="text" id="domain" value="<?php echo esc_attr( $details->domain ) ?>" /></td>
       
   133 			<?php } ?>
       
   134 		</tr>
   159 		</tr>
   135 		<tr class="form-field form-required">
   160 		<?php endif; ?>
   136 			<?php if ( $is_main_site ) { ?>
   161 
   137 			<th scope="row"><?php _e( 'Path' ) ?></th>
       
   138 			<td><code><?php echo esc_attr( $details->path ) ?></code></td>
       
   139 			<?php
       
   140 			} else {
       
   141 				switch_to_blog( $id );
       
   142 			?>
       
   143 			<th scope="row"><label for="path"><?php _e( 'Path' ) ?></label></th>
       
   144 			<td>
       
   145 				<input name="blog[path]" type="text" id="path" value="<?php echo esc_attr( $details->path ) ?>" /><br />
       
   146 				<input type="checkbox" name="update_home_url" id="update_home_url" value="update" <?php if ( get_option( 'siteurl' ) == untrailingslashit( get_blogaddress_by_id ($id ) ) || get_option( 'home' ) == untrailingslashit( get_blogaddress_by_id( $id ) ) ) echo 'checked="checked"'; ?> /> <label for="update_home_url"><?php _e( 'Update <code>siteurl</code> and <code>home</code> as well.' ); ?></label>
       
   147 			</td>
       
   148 			<?php
       
   149 				restore_current_blog();
       
   150 			} ?>
       
   151 		</tr>
       
   152 		<tr class="form-field">
   162 		<tr class="form-field">
   153 			<th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
   163 			<th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ) ?></label></th>
   154 			<td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" /></td>
   164 			<td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ) ?>" /></td>
   155 		</tr>
   165 		</tr>
   156 		<tr class="form-field">
   166 		<tr class="form-field">