wp/wp-admin/includes/ms.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     6  * @subpackage Multisite
     6  * @subpackage Multisite
     7  * @since 3.0.0
     7  * @since 3.0.0
     8  */
     8  */
     9 
     9 
    10 /**
    10 /**
    11  * Determine if uploaded file exceeds space quota.
    11  * Determines whether uploaded file exceeds space quota.
    12  *
    12  *
    13  * @since 3.0.0
    13  * @since 3.0.0
    14  *
    14  *
    15  * @param array $file An element from the `$_FILES` array for a given file.
    15  * @param array $file An element from the `$_FILES` array for a given file.
    16  * @return array The `$_FILES` array element with 'error' key set if file exceeds quota. 'error' is empty otherwise.
    16  * @return array The `$_FILES` array element with 'error' key set if file exceeds quota. 'error' is empty otherwise.
    51 
    51 
    52 	return $file;
    52 	return $file;
    53 }
    53 }
    54 
    54 
    55 /**
    55 /**
    56  * Delete a site.
    56  * Deletes a site.
    57  *
    57  *
    58  * @since 3.0.0
    58  * @since 3.0.0
    59  * @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database.
    59  * @since 5.1.0 Use wp_delete_site() internally to delete the site row from the database.
    60  *
    60  *
    61  * @global wpdb $wpdb WordPress database abstraction object.
       
    62  *
       
    63  * @param int  $blog_id Site ID.
    61  * @param int  $blog_id Site ID.
    64  * @param bool $drop    True if site's database tables should be dropped. Default false.
    62  * @param bool $drop    True if site's database tables should be dropped. Default false.
    65  */
    63  */
    66 function wpmu_delete_blog( $blog_id, $drop = false ) {
    64 function wpmu_delete_blog( $blog_id, $drop = false ) {
    67 	global $wpdb;
       
    68 
       
    69 	$blog_id = (int) $blog_id;
    65 	$blog_id = (int) $blog_id;
    70 
    66 
    71 	$switch = false;
    67 	$switch = false;
    72 	if ( get_current_blog_id() !== $blog_id ) {
    68 	if ( get_current_blog_id() !== $blog_id ) {
    73 		$switch = true;
    69 		$switch = true;
   128 		restore_current_blog();
   124 		restore_current_blog();
   129 	}
   125 	}
   130 }
   126 }
   131 
   127 
   132 /**
   128 /**
   133  * Delete a user from the network and remove from all sites.
   129  * Deletes a user and all of their posts from the network.
       
   130  *
       
   131  * This function:
       
   132  *
       
   133  * - Deletes all posts (of all post types) authored by the user on all sites on the network
       
   134  * - Deletes all links owned by the user on all sites on the network
       
   135  * - Removes the user from all sites on the network
       
   136  * - Deletes the user from the database
   134  *
   137  *
   135  * @since 3.0.0
   138  * @since 3.0.0
   136  *
   139  *
   137  * @todo Merge with wp_delete_user()?
       
   138  *
       
   139  * @global wpdb $wpdb WordPress database abstraction object.
   140  * @global wpdb $wpdb WordPress database abstraction object.
   140  *
   141  *
   141  * @param int $id The user ID.
   142  * @param int $id The user ID.
   142  * @return bool True if the user was deleted, otherwise false.
   143  * @return bool True if the user was deleted, false otherwise.
   143  */
   144  */
   144 function wpmu_delete_user( $id ) {
   145 function wpmu_delete_user( $id ) {
   145 	global $wpdb;
   146 	global $wpdb;
   146 
   147 
   147 	if ( ! is_numeric( $id ) ) {
   148 	if ( ! is_numeric( $id ) ) {
   211 
   212 
   212 	return true;
   213 	return true;
   213 }
   214 }
   214 
   215 
   215 /**
   216 /**
   216  * Check whether a site has used its allotted upload space.
   217  * Checks whether a site has used its allotted upload space.
   217  *
   218  *
   218  * @since MU (3.0.0)
   219  * @since MU (3.0.0)
   219  *
   220  *
   220  * @param bool $display_message Optional. If set to true and the quota is exceeded,
   221  * @param bool $display_message Optional. If set to true and the quota is exceeded,
   221  *                              a warning message is displayed. Default true.
   222  *                              a warning message is displayed. Default true.
   267 	</strong>
   268 	</strong>
   268 	<?php
   269 	<?php
   269 }
   270 }
   270 
   271 
   271 /**
   272 /**
   272  * Get the remaining upload space for this site.
   273  * Gets the remaining upload space for this site.
   273  *
   274  *
   274  * @since MU (3.0.0)
   275  * @since MU (3.0.0)
   275  *
   276  *
   276  * @param int $size Current max size in bytes
   277  * @param int $size Current max size in bytes.
   277  * @return int Max size in bytes
   278  * @return int Max size in bytes.
   278  */
   279  */
   279 function fix_import_form_size( $size ) {
   280 function fix_import_form_size( $size ) {
   280 	if ( upload_is_user_over_quota( false ) ) {
   281 	if ( upload_is_user_over_quota( false ) ) {
   281 		return 0;
   282 		return 0;
   282 	}
   283 	}
   302 
   303 
   303 	?>
   304 	?>
   304 	<tr>
   305 	<tr>
   305 		<th><label for="blog-upload-space-number"><?php _e( 'Site Upload Space Quota' ); ?></label></th>
   306 		<th><label for="blog-upload-space-number"><?php _e( 'Site Upload Space Quota' ); ?></label></th>
   306 		<td>
   307 		<td>
   307 			<input type="number" step="1" min="0" style="width: 100px" name="option[blog_upload_space]" id="blog-upload-space-number" aria-describedby="blog-upload-space-desc" value="<?php echo $quota; ?>" />
   308 			<input type="number" step="1" min="0" style="width: 100px"
   308 			<span id="blog-upload-space-desc"><span class="screen-reader-text"><?php _e( 'Size in megabytes' ); ?></span> <?php _e( 'MB (Leave blank for network default)' ); ?></span>
   309 				name="option[blog_upload_space]" id="blog-upload-space-number"
       
   310 				aria-describedby="blog-upload-space-desc" value="<?php echo esc_attr( $quota ); ?>" />
       
   311 			<span id="blog-upload-space-desc"><span class="screen-reader-text">
       
   312 				<?php
       
   313 				/* translators: Hidden accessibility text. */
       
   314 				_e( 'Size in megabytes' );
       
   315 				?>
       
   316 			</span> <?php _e( 'MB (Leave blank for network default)' ); ?></span>
   309 		</td>
   317 		</td>
   310 	</tr>
   318 	</tr>
   311 	<?php
   319 	<?php
   312 }
   320 }
   313 
   321 
   542 	$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
   550 	$lang_codes = apply_filters( 'lang_codes', $lang_codes, $code );
   543 	return strtr( $code, $lang_codes );
   551 	return strtr( $code, $lang_codes );
   544 }
   552 }
   545 
   553 
   546 /**
   554 /**
   547  * Synchronizes category and post tag slugs when global terms are enabled.
       
   548  *
       
   549  * @since 3.0.0
       
   550  *
       
   551  * @param WP_Term|array $term     The term.
       
   552  * @param string        $taxonomy The taxonomy for `$term`. Should be 'category' or 'post_tag', as these are
       
   553  *                                the only taxonomies which are processed by this function; anything else
       
   554  *                                will be returned untouched.
       
   555  * @return WP_Term|array Returns `$term`, after filtering the 'slug' field with `sanitize_title()`
       
   556  *                       if `$taxonomy` is 'category' or 'post_tag'.
       
   557  */
       
   558 function sync_category_tag_slugs( $term, $taxonomy ) {
       
   559 	if ( global_terms_enabled() && ( 'category' === $taxonomy || 'post_tag' === $taxonomy ) ) {
       
   560 		if ( is_object( $term ) ) {
       
   561 			$term->slug = sanitize_title( $term->name );
       
   562 		} else {
       
   563 			$term['slug'] = sanitize_title( $term['name'] );
       
   564 		}
       
   565 	}
       
   566 	return $term;
       
   567 }
       
   568 
       
   569 /**
       
   570  * Displays an access denied message when a user tries to view a site's dashboard they
   555  * Displays an access denied message when a user tries to view a site's dashboard they
   571  * do not have access to.
   556  * do not have access to.
   572  *
   557  *
   573  * @since 3.2.0
   558  * @since 3.2.0
   574  * @access private
   559  * @access private
   707 	if ( 'upgrade.php' === $pagenow ) {
   692 	if ( 'upgrade.php' === $pagenow ) {
   708 		return;
   693 		return;
   709 	}
   694 	}
   710 
   695 
   711 	if ( (int) get_site_option( 'wpmu_upgrade_site' ) !== $wp_db_version ) {
   696 	if ( (int) get_site_option( 'wpmu_upgrade_site' ) !== $wp_db_version ) {
   712 		echo "<div class='update-nag notice notice-warning inline'>" . sprintf(
   697 		$upgrade_network_message = sprintf(
   713 			/* translators: %s: URL to Upgrade Network screen. */
   698 			/* translators: %s: URL to Upgrade Network screen. */
   714 			__( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ),
   699 			__( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ),
   715 			esc_url( network_admin_url( 'upgrade.php' ) )
   700 			esc_url( network_admin_url( 'upgrade.php' ) )
   716 		) . '</div>';
   701 		);
       
   702 
       
   703 		wp_admin_notice(
       
   704 			$upgrade_network_message,
       
   705 			array(
       
   706 				'type'               => 'warning',
       
   707 				'additional_classes' => array( 'update-nag', 'inline' ),
       
   708 				'paragraph_wrap'     => false,
       
   709 			)
       
   710 		);
   717 	}
   711 	}
   718 }
   712 }
   719 
   713 
   720 /**
   714 /**
   721  * Avoids a collision between a site slug and a permalink slug.
   715  * Avoids a collision between a site slug and a permalink slug.
   749 	$post_name = $data['post_name'];
   743 	$post_name = $data['post_name'];
   750 	$c         = 0;
   744 	$c         = 0;
   751 
   745 
   752 	while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
   746 	while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
   753 		$post_name .= mt_rand( 1, 10 );
   747 		$post_name .= mt_rand( 1, 10 );
   754 		$c++;
   748 		++$c;
   755 	}
   749 	}
   756 
   750 
   757 	if ( $post_name !== $data['post_name'] ) {
   751 	if ( $post_name !== $data['post_name'] ) {
   758 		$data['post_name'] = $post_name;
   752 		$data['post_name'] = $post_name;
   759 	}
   753 	}
   804 			echo esc_url( get_home_url( $blog->userblog_id ) );
   798 			echo esc_url( get_home_url( $blog->userblog_id ) );
   805 			if ( $blog->userblog_id !== $primary_blog ) { // Set the primary blog again if it's out of sync with blog list.
   799 			if ( $blog->userblog_id !== $primary_blog ) { // Set the primary blog again if it's out of sync with blog list.
   806 				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
   800 				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
   807 			}
   801 			}
   808 		} else {
   802 		} else {
   809 			echo 'N/A';
   803 			_e( 'Not available' );
   810 		}
   804 		}
   811 		?>
   805 		?>
   812 		</td>
   806 		</td>
   813 	</tr>
   807 	</tr>
   814 	</table>
   808 	</table>
   815 	<?php
   809 	<?php
   816 }
   810 }
   817 
   811 
   818 /**
   812 /**
   819  * Whether or not we can edit this network from this page.
   813  * Determines whether or not this network from this page can be edited.
   820  *
   814  *
   821  * By default editing of network is restricted to the Network Admin for that `$network_id`.
   815  * By default editing of network is restricted to the Network Admin for that `$network_id`.
   822  * This function allows for this to be overridden.
   816  * This function allows for this to be overridden.
   823  *
   817  *
   824  * @since 3.1.0
   818  * @since 3.1.0
   825  *
   819  *
   826  * @param int $network_id The network ID to check.
   820  * @param int $network_id The network ID to check.
   827  * @return bool True if network can be edited, otherwise false.
   821  * @return bool True if network can be edited, false otherwise.
   828  */
   822  */
   829 function can_edit_network( $network_id ) {
   823 function can_edit_network( $network_id ) {
   830 	if ( get_current_network_id() === (int) $network_id ) {
   824 	if ( get_current_network_id() === (int) $network_id ) {
   831 		$result = true;
   825 		$result = true;
   832 	} else {
   826 	} else {
   843 	 */
   837 	 */
   844 	return apply_filters( 'can_edit_network', $result, $network_id );
   838 	return apply_filters( 'can_edit_network', $result, $network_id );
   845 }
   839 }
   846 
   840 
   847 /**
   841 /**
   848  * Thickbox image paths for Network Admin.
   842  * Prints thickbox image paths for Network Admin.
   849  *
   843  *
   850  * @since 3.1.0
   844  * @since 3.1.0
   851  *
   845  *
   852  * @access private
   846  * @access private
   853  */
   847  */
   859 	<?php
   853 	<?php
   860 }
   854 }
   861 
   855 
   862 /**
   856 /**
   863  * @param array $users
   857  * @param array $users
       
   858  * @return bool
   864  */
   859  */
   865 function confirm_delete_users( $users ) {
   860 function confirm_delete_users( $users ) {
   866 	$current_user = wp_get_current_user();
   861 	$current_user = wp_get_current_user();
   867 	if ( ! is_array( $users ) || empty( $users ) ) {
   862 	if ( ! is_array( $users ) || empty( $users ) ) {
   868 		return false;
   863 		return false;
   936 							'fields'  => array( 'ID', 'user_login' ),
   931 							'fields'  => array( 'ID', 'user_login' ),
   937 						)
   932 						)
   938 					);
   933 					);
   939 
   934 
   940 					if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
   935 					if ( is_array( $blog_users ) && ! empty( $blog_users ) ) {
   941 						$user_site      = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
   936 						$user_site     = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
   942 						$user_dropdown  = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
   937 						$user_dropdown = '<label for="reassign_user" class="screen-reader-text">' .
       
   938 								/* translators: Hidden accessibility text. */
       
   939 								__( 'Select a user' ) .
       
   940 							'</label>';
   943 						$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
   941 						$user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
   944 						$user_list      = '';
   942 						$user_list      = '';
   945 
   943 
   946 						foreach ( $blog_users as $user ) {
   944 						foreach ( $blog_users as $user ) {
   947 							if ( ! in_array( (int) $user->ID, $allusers, true ) ) {
   945 							if ( ! in_array( (int) $user->ID, $allusers, true ) ) {
  1002 	<?php
  1000 	<?php
  1003 	return true;
  1001 	return true;
  1004 }
  1002 }
  1005 
  1003 
  1006 /**
  1004 /**
  1007  * Print JavaScript in the header on the Network Settings screen.
  1005  * Prints JavaScript in the header on the Network Settings screen.
  1008  *
  1006  *
  1009  * @since 4.1.0
  1007  * @since 4.1.0
  1010  */
  1008  */
  1011 function network_settings_add_js() {
  1009 function network_settings_add_js() {
  1012 	?>
  1010 	?>
  1013 <script type="text/javascript">
  1011 <script type="text/javascript">
  1014 jQuery( function($) {
  1012 jQuery( function($) {
  1015 	var languageSelect = $( '#WPLANG' );
  1013 	var languageSelect = $( '#WPLANG' );
  1016 	$( 'form' ).on( 'submit', function() {
  1014 	$( 'form' ).on( 'submit', function() {
  1017 		// Don't show a spinner for English and installed languages,
  1015 		/*
  1018 		// as there is nothing to download.
  1016 		 * Don't show a spinner for English and installed languages,
       
  1017 		 * as there is nothing to download.
       
  1018 		 */
  1019 		if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
  1019 		if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
  1020 			$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
  1020 			$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
  1021 		}
  1021 		}
  1022 	});
  1022 	});
  1023 } );
  1023 } );
  1167  *
  1167  *
  1168  * @return string Help sidebar content.
  1168  * @return string Help sidebar content.
  1169  */
  1169  */
  1170 function get_site_screen_help_sidebar_content() {
  1170 function get_site_screen_help_sidebar_content() {
  1171 	return '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  1171 	return '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
  1172 		'<p>' . __( '<a href="https://wordpress.org/support/article/network-admin-sites-screen/">Documentation on Site Management</a>' ) . '</p>' .
  1172 		'<p>' . __( '<a href="https://developer.wordpress.org/advanced-administration/multisite/admin/#network-admin-sites-screen">Documentation on Site Management</a>' ) . '</p>' .
  1173 		'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>';
  1173 		'<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support forums</a>' ) . '</p>';
  1174 }
  1174 }