angelovcom.net

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

site-info.php (7215B)


      1 <?php
      2 /**
      3  * Edit Site Info Administration Screen
      4  *
      5  * @package WordPress
      6  * @subpackage Multisite
      7  * @since 3.1.0
      8  */
      9 
     10 /** Load WordPress Administration Bootstrap */
     11 require_once __DIR__ . '/admin.php';
     12 
     13 if ( ! current_user_can( 'manage_sites' ) ) {
     14 	wp_die( __( 'Sorry, you are not allowed to edit this site.' ) );
     15 }
     16 
     17 get_current_screen()->add_help_tab( get_site_screen_help_tab_args() );
     18 get_current_screen()->set_help_sidebar( get_site_screen_help_sidebar_content() );
     19 
     20 $id = isset( $_REQUEST['id'] ) ? (int) $_REQUEST['id'] : 0;
     21 
     22 if ( ! $id ) {
     23 	wp_die( __( 'Invalid site ID.' ) );
     24 }
     25 
     26 $details = get_site( $id );
     27 if ( ! $details ) {
     28 	wp_die( __( 'The requested site does not exist.' ) );
     29 }
     30 
     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 );
     36 $is_main_site  = is_main_site( $id );
     37 
     38 if ( isset( $_REQUEST['action'] ) && 'update-site' === $_REQUEST['action'] ) {
     39 	check_admin_referer( 'edit-site' );
     40 
     41 	switch_to_blog( $id );
     42 
     43 	// Rewrite rules can't be flushed during switch to blog.
     44 	delete_option( 'rewrite_rules' );
     45 
     46 	$blog_data           = wp_unslash( $_POST['blog'] );
     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 );
     74 	$blog_data_checkboxes = array( 'public', 'archived', 'spam', 'mature', 'deleted' );
     75 
     76 	foreach ( $blog_data_checkboxes as $c ) {
     77 		if ( ! in_array( (int) $existing_details->$c, array( 0, 1 ), true ) ) {
     78 			$blog_data[ $c ] = $existing_details->$c;
     79 		} else {
     80 			$blog_data[ $c ] = isset( $_POST['blog'][ $c ] ) ? 1 : 0;
     81 		}
     82 	}
     83 
     84 	update_blog_details( $id, $blog_data );
     85 
     86 	// Maybe update home and siteurl options.
     87 	$new_details = get_site( $id );
     88 
     89 	$old_home_url    = trailingslashit( esc_url( get_option( 'home' ) ) );
     90 	$old_home_parsed = parse_url( $old_home_url );
     91 
     92 	if ( $old_home_parsed['host'] === $existing_details->domain && $old_home_parsed['path'] === $existing_details->path ) {
     93 		$new_home_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
     94 		update_option( 'home', $new_home_url );
     95 	}
     96 
     97 	$old_site_url    = trailingslashit( esc_url( get_option( 'siteurl' ) ) );
     98 	$old_site_parsed = parse_url( $old_site_url );
     99 
    100 	if ( $old_site_parsed['host'] === $existing_details->domain && $old_site_parsed['path'] === $existing_details->path ) {
    101 		$new_site_url = untrailingslashit( esc_url_raw( $blog_data['scheme'] . '://' . $new_details->domain . $new_details->path ) );
    102 		update_option( 'siteurl', $new_site_url );
    103 	}
    104 
    105 	restore_current_blog();
    106 	wp_redirect(
    107 		add_query_arg(
    108 			array(
    109 				'update' => 'updated',
    110 				'id'     => $id,
    111 			),
    112 			'site-info.php'
    113 		)
    114 	);
    115 	exit;
    116 }
    117 
    118 if ( isset( $_GET['update'] ) ) {
    119 	$messages = array();
    120 	if ( 'updated' === $_GET['update'] ) {
    121 		$messages[] = __( 'Site info updated.' );
    122 	}
    123 }
    124 
    125 /* translators: %s: Site title. */
    126 $title = sprintf( __( 'Edit Site: %s' ), esc_html( $details->blogname ) );
    127 
    128 $parent_file  = 'sites.php';
    129 $submenu_file = 'sites.php';
    130 
    131 require_once ABSPATH . 'wp-admin/admin-header.php';
    132 
    133 ?>
    134 
    135 <div class="wrap">
    136 <h1 id="edit-site"><?php echo $title; ?></h1>
    137 <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>
    138 <?php
    139 
    140 network_edit_site_nav(
    141 	array(
    142 		'blog_id'  => $id,
    143 		'selected' => 'site-info',
    144 	)
    145 );
    146 
    147 if ( ! empty( $messages ) ) {
    148 	foreach ( $messages as $msg ) {
    149 		echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>';
    150 	}
    151 }
    152 ?>
    153 <form method="post" action="site-info.php?action=update-site">
    154 	<?php wp_nonce_field( 'edit-site' ); ?>
    155 	<input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
    156 	<table class="form-table" role="presentation">
    157 		<?php
    158 		// The main site of the network should not be updated on this page.
    159 		if ( $is_main_site ) :
    160 			?>
    161 		<tr class="form-field">
    162 			<th scope="row"><?php _e( 'Site Address (URL)' ); ?></th>
    163 			<td><?php echo esc_url( $parsed_scheme . '://' . $details->domain . $details->path ); ?></td>
    164 		</tr>
    165 			<?php
    166 			// For any other site, the scheme, domain, and path can all be changed.
    167 		else :
    168 			?>
    169 		<tr class="form-field form-required">
    170 			<th scope="row"><label for="url"><?php _e( 'Site Address (URL)' ); ?></label></th>
    171 			<td><input name="blog[url]" type="text" id="url" value="<?php echo $parsed_scheme . '://' . esc_attr( $details->domain ) . esc_attr( $details->path ); ?>" /></td>
    172 		</tr>
    173 		<?php endif; ?>
    174 
    175 		<tr class="form-field">
    176 			<th scope="row"><label for="blog_registered"><?php _ex( 'Registered', 'site' ); ?></label></th>
    177 			<td><input name="blog[registered]" type="text" id="blog_registered" value="<?php echo esc_attr( $details->registered ); ?>" /></td>
    178 		</tr>
    179 		<tr class="form-field">
    180 			<th scope="row"><label for="blog_last_updated"><?php _e( 'Last Updated' ); ?></label></th>
    181 			<td><input name="blog[last_updated]" type="text" id="blog_last_updated" value="<?php echo esc_attr( $details->last_updated ); ?>" /></td>
    182 		</tr>
    183 		<?php
    184 		$attribute_fields = array( 'public' => _x( 'Public', 'site' ) );
    185 		if ( ! $is_main_site ) {
    186 			$attribute_fields['archived'] = __( 'Archived' );
    187 			$attribute_fields['spam']     = _x( 'Spam', 'site' );
    188 			$attribute_fields['deleted']  = __( 'Deleted' );
    189 		}
    190 		$attribute_fields['mature'] = __( 'Mature' );
    191 		?>
    192 		<tr>
    193 			<th scope="row"><?php _e( 'Attributes' ); ?></th>
    194 			<td>
    195 			<fieldset>
    196 			<legend class="screen-reader-text"><?php _e( 'Set site attributes' ); ?></legend>
    197 			<?php foreach ( $attribute_fields as $field_key => $field_label ) : ?>
    198 				<label><input type="checkbox" name="blog[<?php echo $field_key; ?>]" value="1" <?php checked( (bool) $details->$field_key, true ); ?> <?php disabled( ! in_array( (int) $details->$field_key, array( 0, 1 ), true ) ); ?> />
    199 				<?php echo $field_label; ?></label><br/>
    200 			<?php endforeach; ?>
    201 			<fieldset>
    202 			</td>
    203 		</tr>
    204 	</table>
    205 
    206 	<?php
    207 	/**
    208 	 * Fires at the end of the site info form in network admin.
    209 	 *
    210 	 * @since 5.6.0
    211 	 *
    212 	 * @param int $id The site ID.
    213 	 */
    214 	do_action( 'network_site_info_form', $id );
    215 
    216 	submit_button();
    217 	?>
    218 </form>
    219 
    220 </div>
    221 <?php
    222 require_once ABSPATH . 'wp-admin/admin-footer.php';