wp/wp-admin/includes/ms.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    10 /**
    10 /**
    11  * Determine if uploaded file exceeds space quota.
    11  * Determine if uploaded file exceeds space quota.
    12  *
    12  *
    13  * @since 3.0.0
    13  * @since 3.0.0
    14  *
    14  *
    15  * @param array $file $_FILES array for a given file.
    15  * @param array $file An element from the `$_FILES` array for a given file.
    16  * @return array $_FILES array 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.
    17  */
    17  */
    18 function check_upload_size( $file ) {
    18 function check_upload_size( $file ) {
    19 	if ( get_site_option( 'upload_space_check_disabled' ) ) {
    19 	if ( get_site_option( 'upload_space_check_disabled' ) ) {
    20 		return $file;
    20 		return $file;
    21 	}
    21 	}
    22 
    22 
    23 	if ( '0' != $file['error'] ) { // There's already an error.
    23 	if ( $file['error'] > 0 ) { // There's already an error.
    24 		return $file;
    24 		return $file;
    25 	}
    25 	}
    26 
    26 
    27 	if ( defined( 'WP_IMPORTING' ) ) {
    27 	if ( defined( 'WP_IMPORTING' ) ) {
    28 		return $file;
    28 		return $file;
    43 
    43 
    44 	if ( upload_is_user_over_quota( false ) ) {
    44 	if ( upload_is_user_over_quota( false ) ) {
    45 		$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
    45 		$file['error'] = __( 'You have used your space quota. Please delete files before uploading.' );
    46 	}
    46 	}
    47 
    47 
    48 	if ( '0' != $file['error'] && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
    48 	if ( $file['error'] > 0 && ! isset( $_POST['html-upload'] ) && ! wp_doing_ajax() ) {
    49 		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
    49 		wp_die( $file['error'] . ' <a href="javascript:history.go(-1)">' . __( 'Back' ) . '</a>' );
    50 	}
    50 	}
    51 
    51 
    52 	return $file;
    52 	return $file;
    53 }
    53 }
    64  * @param bool $drop    True if site's database tables should be dropped. Default false.
    64  * @param bool $drop    True if site's database tables should be dropped. Default false.
    65  */
    65  */
    66 function wpmu_delete_blog( $blog_id, $drop = false ) {
    66 function wpmu_delete_blog( $blog_id, $drop = false ) {
    67 	global $wpdb;
    67 	global $wpdb;
    68 
    68 
       
    69 	$blog_id = (int) $blog_id;
       
    70 
    69 	$switch = false;
    71 	$switch = false;
    70 	if ( get_current_blog_id() != $blog_id ) {
    72 	if ( get_current_blog_id() !== $blog_id ) {
    71 		$switch = true;
    73 		$switch = true;
    72 		switch_to_blog( $blog_id );
    74 		switch_to_blog( $blog_id );
    73 	}
    75 	}
    74 
    76 
    75 	$blog = get_site( $blog_id );
    77 	$blog = get_site( $blog_id );
    80 	if ( $drop && ! $blog ) {
    82 	if ( $drop && ! $blog ) {
    81 		$drop = false;
    83 		$drop = false;
    82 	}
    84 	}
    83 
    85 
    84 	// Don't destroy the initial, main, or root blog.
    86 	// Don't destroy the initial, main, or root blog.
    85 	if ( $drop && ( 1 == $blog_id || is_main_site( $blog_id ) || ( $blog->path == $current_network->path && $blog->domain == $current_network->domain ) ) ) {
    87 	if ( $drop
       
    88 		&& ( 1 === $blog_id || is_main_site( $blog_id )
       
    89 			|| ( $blog->path === $current_network->path && $blog->domain === $current_network->domain ) )
       
    90 	) {
    86 		$drop = false;
    91 		$drop = false;
    87 	}
    92 	}
    88 
    93 
    89 	$upload_path = trim( get_option( 'upload_path' ) );
    94 	$upload_path = trim( get_option( 'upload_path' ) );
    90 
    95 
   210 /**
   215 /**
   211  * Check whether a site has used its allotted upload space.
   216  * Check whether a site has used its allotted upload space.
   212  *
   217  *
   213  * @since MU (3.0.0)
   218  * @since MU (3.0.0)
   214  *
   219  *
   215  * @param bool $echo Optional. If $echo is set and the quota is exceeded, a warning message is echoed. Default is true.
   220  * @param bool $display_message Optional. If set to true and the quota is exceeded,
       
   221  *                              a warning message is displayed. Default true.
   216  * @return bool True if user is over upload space quota, otherwise false.
   222  * @return bool True if user is over upload space quota, otherwise false.
   217  */
   223  */
   218 function upload_is_user_over_quota( $echo = true ) {
   224 function upload_is_user_over_quota( $display_message = true ) {
   219 	if ( get_site_option( 'upload_space_check_disabled' ) ) {
   225 	if ( get_site_option( 'upload_space_check_disabled' ) ) {
   220 		return false;
   226 		return false;
   221 	}
   227 	}
   222 
   228 
   223 	$space_allowed = get_space_allowed();
   229 	$space_allowed = get_space_allowed();
   225 		$space_allowed = 10; // Default space allowed is 10 MB.
   231 		$space_allowed = 10; // Default space allowed is 10 MB.
   226 	}
   232 	}
   227 	$space_used = get_space_used();
   233 	$space_used = get_space_used();
   228 
   234 
   229 	if ( ( $space_allowed - $space_used ) < 0 ) {
   235 	if ( ( $space_allowed - $space_used ) < 0 ) {
   230 		if ( $echo ) {
   236 		if ( $display_message ) {
   231 			printf(
   237 			printf(
   232 				/* translators: %s: Allowed space allocation. */
   238 				/* translators: %s: Allowed space allocation. */
   233 				__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
   239 				__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
   234 				size_format( $space_allowed * MB_IN_BYTES )
   240 				size_format( $space_allowed * MB_IN_BYTES )
   235 			);
   241 			);
   685  * Displays an admin notice to upgrade all sites after a core upgrade.
   691  * Displays an admin notice to upgrade all sites after a core upgrade.
   686  *
   692  *
   687  * @since 3.0.0
   693  * @since 3.0.0
   688  *
   694  *
   689  * @global int    $wp_db_version WordPress database version.
   695  * @global int    $wp_db_version WordPress database version.
   690  * @global string $pagenow
   696  * @global string $pagenow       The filename of the current screen.
   691  *
   697  *
   692  * @return void|false Void on success. False if the current user is not a super admin.
   698  * @return void|false Void on success. False if the current user is not a super admin.
   693  */
   699  */
   694 function site_admin_notice() {
   700 function site_admin_notice() {
   695 	global $wp_db_version, $pagenow;
   701 	global $wp_db_version, $pagenow;
   700 
   706 
   701 	if ( 'upgrade.php' === $pagenow ) {
   707 	if ( 'upgrade.php' === $pagenow ) {
   702 		return;
   708 		return;
   703 	}
   709 	}
   704 
   710 
   705 	if ( get_site_option( 'wpmu_upgrade_site' ) != $wp_db_version ) {
   711 	if ( (int) get_site_option( 'wpmu_upgrade_site' ) !== $wp_db_version ) {
   706 		echo "<div class='update-nag notice notice-warning inline'>" . sprintf(
   712 		echo "<div class='update-nag notice notice-warning inline'>" . sprintf(
   707 			/* translators: %s: URL to Upgrade Network screen. */
   713 			/* translators: %s: URL to Upgrade Network screen. */
   708 			__( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ),
   714 			__( 'Thank you for Updating! Please visit the <a href="%s">Upgrade Network</a> page to update all your sites.' ),
   709 			esc_url( network_admin_url( 'upgrade.php' ) )
   715 			esc_url( network_admin_url( 'upgrade.php' ) )
   710 		) . '</div>';
   716 		) . '</div>';
   734 		return $data;
   740 		return $data;
   735 	}
   741 	}
   736 	if ( ! is_main_site() ) {
   742 	if ( ! is_main_site() ) {
   737 		return $data;
   743 		return $data;
   738 	}
   744 	}
       
   745 	if ( isset( $data['post_parent'] ) && $data['post_parent'] ) {
       
   746 		return $data;
       
   747 	}
   739 
   748 
   740 	$post_name = $data['post_name'];
   749 	$post_name = $data['post_name'];
   741 	$c         = 0;
   750 	$c         = 0;
       
   751 
   742 	while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
   752 	while ( $c < 10 && get_id_from_blogname( $post_name ) ) {
   743 		$post_name .= mt_rand( 1, 10 );
   753 		$post_name .= mt_rand( 1, 10 );
   744 		$c ++;
   754 		$c++;
   745 	}
   755 	}
   746 	if ( $post_name != $data['post_name'] ) {
   756 
       
   757 	if ( $post_name !== $data['post_name'] ) {
   747 		$data['post_name'] = $post_name;
   758 		$data['post_name'] = $post_name;
   748 	}
   759 	}
       
   760 
   749 	return $data;
   761 	return $data;
   750 }
   762 }
   751 
   763 
   752 /**
   764 /**
   753  * Handles the display of choosing a user's primary site.
   765  * Handles the display of choosing a user's primary site.
   764 	<?php /* translators: My Sites label. */ ?>
   776 	<?php /* translators: My Sites label. */ ?>
   765 		<th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th>
   777 		<th scope="row"><label for="primary_blog"><?php _e( 'Primary Site' ); ?></label></th>
   766 		<td>
   778 		<td>
   767 		<?php
   779 		<?php
   768 		$all_blogs    = get_blogs_of_user( get_current_user_id() );
   780 		$all_blogs    = get_blogs_of_user( get_current_user_id() );
   769 		$primary_blog = get_user_meta( get_current_user_id(), 'primary_blog', true );
   781 		$primary_blog = (int) get_user_meta( get_current_user_id(), 'primary_blog', true );
   770 		if ( count( $all_blogs ) > 1 ) {
   782 		if ( count( $all_blogs ) > 1 ) {
   771 			$found = false;
   783 			$found = false;
   772 			?>
   784 			?>
   773 			<select name="primary_blog" id="primary_blog">
   785 			<select name="primary_blog" id="primary_blog">
   774 				<?php
   786 				<?php
   775 				foreach ( (array) $all_blogs as $blog ) {
   787 				foreach ( (array) $all_blogs as $blog ) {
   776 					if ( $primary_blog == $blog->userblog_id ) {
   788 					if ( $blog->userblog_id === $primary_blog ) {
   777 						$found = true;
   789 						$found = true;
   778 					}
   790 					}
   779 					?>
   791 					?>
   780 					<option value="<?php echo $blog->userblog_id; ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ); ?></option>
   792 					<option value="<?php echo $blog->userblog_id; ?>"<?php selected( $primary_blog, $blog->userblog_id ); ?>><?php echo esc_url( get_home_url( $blog->userblog_id ) ); ?></option>
   781 					<?php
   793 					<?php
   785 			<?php
   797 			<?php
   786 			if ( ! $found ) {
   798 			if ( ! $found ) {
   787 				$blog = reset( $all_blogs );
   799 				$blog = reset( $all_blogs );
   788 				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 );
   789 			}
   801 			}
   790 		} elseif ( count( $all_blogs ) == 1 ) {
   802 		} elseif ( 1 === count( $all_blogs ) ) {
   791 			$blog = reset( $all_blogs );
   803 			$blog = reset( $all_blogs );
   792 			echo esc_url( get_home_url( $blog->userblog_id ) );
   804 			echo esc_url( get_home_url( $blog->userblog_id ) );
   793 			if ( $primary_blog != $blog->userblog_id ) { // Set the primary blog again if it's out of sync with blog list.
   805 			if ( $blog->userblog_id !== $primary_blog ) { // Set the primary blog again if it's out of sync with blog list.
   794 				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
   806 				update_user_meta( get_current_user_id(), 'primary_blog', $blog->userblog_id );
   795 			}
   807 			}
   796 		} else {
   808 		} else {
   797 			echo 'N/A';
   809 			echo 'N/A';
   798 		}
   810 		}
   813  *
   825  *
   814  * @param int $network_id The network ID to check.
   826  * @param int $network_id The network ID to check.
   815  * @return bool True if network can be edited, otherwise false.
   827  * @return bool True if network can be edited, otherwise false.
   816  */
   828  */
   817 function can_edit_network( $network_id ) {
   829 function can_edit_network( $network_id ) {
   818 	if ( get_current_network_id() == $network_id ) {
   830 	if ( get_current_network_id() === (int) $network_id ) {
   819 		$result = true;
   831 		$result = true;
   820 	} else {
   832 	} else {
   821 		$result = false;
   833 		$result = false;
   822 	}
   834 	}
   823 
   835 
   873 	?>
   885 	?>
   874 	<table class="form-table" role="presentation">
   886 	<table class="form-table" role="presentation">
   875 	<?php
   887 	<?php
   876 	$allusers = (array) $_POST['allusers'];
   888 	$allusers = (array) $_POST['allusers'];
   877 	foreach ( $allusers as $user_id ) {
   889 	foreach ( $allusers as $user_id ) {
   878 		if ( '' !== $user_id && '0' != $user_id ) {
   890 		if ( '' !== $user_id && '0' !== $user_id ) {
   879 			$delete_user = get_userdata( $user_id );
   891 			$delete_user = get_userdata( $user_id );
   880 
   892 
   881 			if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
   893 			if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
   882 				wp_die(
   894 				wp_die(
   883 					sprintf(
   895 					sprintf(
   997  * @since 4.1.0
  1009  * @since 4.1.0
   998  */
  1010  */
   999 function network_settings_add_js() {
  1011 function network_settings_add_js() {
  1000 	?>
  1012 	?>
  1001 <script type="text/javascript">
  1013 <script type="text/javascript">
  1002 jQuery(document).ready( function($) {
  1014 jQuery( function($) {
  1003 	var languageSelect = $( '#WPLANG' );
  1015 	var languageSelect = $( '#WPLANG' );
  1004 	$( 'form' ).on( 'submit', function() {
  1016 	$( 'form' ).on( 'submit', function() {
  1005 		// Don't show a spinner for English and installed languages,
  1017 		// Don't show a spinner for English and installed languages,
  1006 		// as there is nothing to download.
  1018 		// as there is nothing to download.
  1007 		if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
  1019 		if ( ! languageSelect.find( 'option:selected' ).data( 'installed' ) ) {
  1008 			$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
  1020 			$( '#submit', this ).after( '<span class="spinner language-install-spinner is-active" />' );
  1009 		}
  1021 		}
  1010 	});
  1022 	});
  1011 });
  1023 } );
  1012 </script>
  1024 </script>
  1013 	<?php
  1025 	<?php
  1014 }
  1026 }
  1015 
  1027 
  1016 /**
  1028 /**
  1017  * Outputs the HTML for a network's "Edit Site" tabular interface.
  1029  * Outputs the HTML for a network's "Edit Site" tabular interface.
  1018  *
  1030  *
  1019  * @since 4.6.0
  1031  * @since 4.6.0
  1020  *
  1032  *
  1021  * @global string $pagenow
  1033  * @global string $pagenow The filename of the current screen.
  1022  *
  1034  *
  1023  * @param array $args {
  1035  * @param array $args {
  1024  *     Optional. Array or string of Query parameters. Default empty array.
  1036  *     Optional. Array or string of Query parameters. Default empty array.
  1025  *
  1037  *
  1026  *     @type int    $blog_id  The site ID. Default is the current site.
  1038  *     @type int    $blog_id  The site ID. Default is the current site.