wp/wp-includes/ms-blogs.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
    15  */
    15  */
    16 function wpmu_update_blogs_date() {
    16 function wpmu_update_blogs_date() {
    17 	global $wpdb;
    17 	global $wpdb;
    18 
    18 
    19 	update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) );
    19 	update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) );
    20 
    20 	/**
       
    21 	 * Fires after the blog details are updated.
       
    22 	 *
       
    23 	 * @since MU
       
    24 	 *
       
    25 	 * @param int $blog_id Blog ID.
       
    26 	 */
    21 	do_action( 'wpmu_blog_updated', $wpdb->blogid );
    27 	do_action( 'wpmu_blog_updated', $wpdb->blogid );
    22 }
    28 }
    23 
    29 
    24 /**
    30 /**
    25  * Get a full blog URL, given a blog id.
    31  * Get a full blog URL, given a blog id.
    26  *
    32  *
    27  * @since MU
    33  * @since MU
    28  *
    34  *
    29  * @param int $blog_id Blog ID
    35  * @param int $blog_id Blog ID
    30  * @return string
    36  * @return string Full URL of the blog if found. Empty string if not.
    31  */
    37  */
    32 function get_blogaddress_by_id( $blog_id ) {
    38 function get_blogaddress_by_id( $blog_id ) {
    33 	$bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
    39 	$bloginfo = get_blog_details( (int) $blog_id, false ); // only get bare details!
    34 	return esc_url( 'http://' . $bloginfo->domain . $bloginfo->path );
    40 	return ( $bloginfo ) ? esc_url( 'http://' . $bloginfo->domain . $bloginfo->path ) : '';
    35 }
    41 }
    36 
    42 
    37 /**
    43 /**
    38  * Get a full blog URL, given a blog name.
    44  * Get a full blog URL, given a blog name.
    39  *
    45  *
    62  *
    68  *
    63  * @param string $slug
    69  * @param string $slug
    64  * @return int A blog id
    70  * @return int A blog id
    65  */
    71  */
    66 function get_id_from_blogname( $slug ) {
    72 function get_id_from_blogname( $slug ) {
    67 	global $wpdb, $current_site;
    73 	global $wpdb;
    68 
    74 
       
    75 	$current_site = get_current_site();
    69 	$slug = trim( $slug, '/' );
    76 	$slug = trim( $slug, '/' );
    70 
    77 
    71 	$blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' );
    78 	$blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' );
    72 	if ( $blog_id )
    79 	if ( $blog_id )
    73 		return $blog_id;
    80 		return $blog_id;
    90  *
    97  *
    91  * @since MU
    98  * @since MU
    92  *
    99  *
    93  * @param int|string|array $fields A blog ID, a blog slug, or an array of fields to query against. Optional. If not specified the current blog ID is used.
   100  * @param int|string|array $fields A blog ID, a blog slug, or an array of fields to query against. Optional. If not specified the current blog ID is used.
    94  * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
   101  * @param bool $get_all Whether to retrieve all details or only the details in the blogs table. Default is true.
    95  * @return object Blog details.
   102  * @return object|false Blog details on success. False on failure.
    96  */
   103  */
    97 function get_blog_details( $fields = null, $get_all = true ) {
   104 function get_blog_details( $fields = null, $get_all = true ) {
    98 	global $wpdb;
   105 	global $wpdb;
    99 
   106 
   100 	if ( is_array($fields ) ) {
   107 	if ( is_array($fields ) ) {
   204 	$details->blogname		= get_option( 'blogname' );
   211 	$details->blogname		= get_option( 'blogname' );
   205 	$details->siteurl		= get_option( 'siteurl' );
   212 	$details->siteurl		= get_option( 'siteurl' );
   206 	$details->post_count	= get_option( 'post_count' );
   213 	$details->post_count	= get_option( 'post_count' );
   207 	restore_current_blog();
   214 	restore_current_blog();
   208 
   215 
       
   216 	/**
       
   217 	 * Filter a blog's details.
       
   218 	 *
       
   219 	 * @since MU
       
   220 	 *
       
   221 	 * @param object $details The blog details.
       
   222 	 */
   209 	$details = apply_filters( 'blog_details', $details );
   223 	$details = apply_filters( 'blog_details', $details );
   210 
   224 
   211 	wp_cache_set( $blog_id . $all, $details, 'blog-details' );
   225 	wp_cache_set( $blog_id . $all, $details, 'blog-details' );
   212 
   226 
   213 	$key = md5( $details->domain . $details->path );
   227 	$key = md5( $details->domain . $details->path );
   219 /**
   233 /**
   220  * Clear the blog details cache.
   234  * Clear the blog details cache.
   221  *
   235  *
   222  * @since MU
   236  * @since MU
   223  *
   237  *
   224  * @param int $blog_id Blog ID
   238  * @param int $blog_id Optional. Blog ID. Defaults to current blog.
   225  */
   239  */
   226 function refresh_blog_details( $blog_id ) {
   240 function refresh_blog_details( $blog_id = 0 ) {
   227 	$blog_id = (int) $blog_id;
   241 	$blog_id = (int) $blog_id;
       
   242 	if ( ! $blog_id ) {
       
   243 		$blog_id = get_current_blog_id();
       
   244 	}
       
   245 
   228 	$details = get_blog_details( $blog_id, false );
   246 	$details = get_blog_details( $blog_id, false );
   229 	if ( ! $details ) {
   247 	if ( ! $details ) {
   230 		// Make sure clean_blog_cache() gets the blog ID
   248 		// Make sure clean_blog_cache() gets the blog ID
   231 		// when the blog has been previously cached as
   249 		// when the blog has been previously cached as
   232 		// non-existent.
   250 		// non-existent.
   237 		);
   255 		);
   238 	}
   256 	}
   239 
   257 
   240 	clean_blog_cache( $details );
   258 	clean_blog_cache( $details );
   241 
   259 
       
   260 	/**
       
   261 	 * Fires after the blog details cache is cleared.
       
   262 	 *
       
   263 	 * @since 3.4.0
       
   264 	 *
       
   265 	 * @param int $blog_id Blog ID.
       
   266 	 */
   242 	do_action( 'refresh_blog_details', $blog_id );
   267 	do_action( 'refresh_blog_details', $blog_id );
   243 }
   268 }
   244 
   269 
   245 /**
   270 /**
   246  * Update the details for a blog. Updates the blogs table for a given blog id.
   271  * Update the details for a blog. Updates the blogs table for a given blog id.
   269 	$details = array_merge($current_details, $details);
   294 	$details = array_merge($current_details, $details);
   270 	$details['last_updated'] = current_time('mysql', true);
   295 	$details['last_updated'] = current_time('mysql', true);
   271 
   296 
   272 	$update_details = array();
   297 	$update_details = array();
   273 	$fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
   298 	$fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
   274 	foreach ( array_intersect( array_keys( $details ), $fields ) as $field )
   299 	foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) {
   275 		$update_details[$field] = $details[$field];
   300 		if ( 'path' === $field ) {
       
   301 			$details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) );
       
   302 		}
       
   303 
       
   304 		$update_details[ $field ] = $details[ $field ];
       
   305 	}
   276 
   306 
   277 	$result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
   307 	$result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
   278 
   308 
   279 	if ( false === $result )
   309 	if ( false === $result )
   280 		return false;
   310 		return false;
   281 
   311 
   282 	// If spam status changed, issue actions.
   312 	// If spam status changed, issue actions.
   283 	if ( $details[ 'spam' ] != $current_details[ 'spam' ] ) {
   313 	if ( $details['spam'] != $current_details['spam'] ) {
   284 		if ( $details[ 'spam' ] == 1 )
   314 		if ( $details['spam'] == 1 ) {
       
   315 			/**
       
   316 			 * Fires when the blog status is changed to 'spam'.
       
   317 			 *
       
   318 			 * @since MU
       
   319 			 *
       
   320 			 * @param int $blog_id Blog ID.
       
   321 			 */
   285 			do_action( 'make_spam_blog', $blog_id );
   322 			do_action( 'make_spam_blog', $blog_id );
   286 		else
   323 		} else {
       
   324 			/**
       
   325 			 * Fires when the blog status is changed to 'ham'.
       
   326 			 *
       
   327 			 * @since MU
       
   328 			 *
       
   329 			 * @param int $blog_id Blog ID.
       
   330 			 */
   287 			do_action( 'make_ham_blog', $blog_id );
   331 			do_action( 'make_ham_blog', $blog_id );
       
   332 		}
   288 	}
   333 	}
   289 
   334 
   290 	// If mature status changed, issue actions.
   335 	// If mature status changed, issue actions.
   291 	if ( $details[ 'mature' ] != $current_details[ 'mature' ] ) {
   336 	if ( $details['mature'] != $current_details['mature'] ) {
   292 		if ( $details[ 'mature' ] == 1 )
   337 		if ( $details['mature'] == 1 ) {
       
   338 			/**
       
   339 			 * Fires when the blog status is changed to 'mature'.
       
   340 			 *
       
   341 			 * @since 3.1.0
       
   342 			 *
       
   343 			 * @param int $blog_id Blog ID.
       
   344 			 */
   293 			do_action( 'mature_blog', $blog_id );
   345 			do_action( 'mature_blog', $blog_id );
   294 		else
   346 		} else {
       
   347 			/**
       
   348 			 * Fires when the blog status is changed to 'unmature'.
       
   349 			 *
       
   350 			 * @since 3.1.0
       
   351 			 *
       
   352 			 * @param int $blog_id Blog ID.
       
   353 			 */
   295 			do_action( 'unmature_blog', $blog_id );
   354 			do_action( 'unmature_blog', $blog_id );
       
   355 		}
   296 	}
   356 	}
   297 
   357 
   298 	// If archived status changed, issue actions.
   358 	// If archived status changed, issue actions.
   299 	if ( $details[ 'archived' ] != $current_details[ 'archived' ] ) {
   359 	if ( $details['archived'] != $current_details['archived'] ) {
   300 		if ( $details[ 'archived' ] == 1 )
   360 		if ( $details['archived'] == 1 ) {
       
   361 			/**
       
   362 			 * Fires when the blog status is changed to 'archived'.
       
   363 			 *
       
   364 			 * @since MU
       
   365 			 *
       
   366 			 * @param int $blog_id Blog ID.
       
   367 			 */
   301 			do_action( 'archive_blog', $blog_id );
   368 			do_action( 'archive_blog', $blog_id );
   302 		else
   369 		} else {
       
   370 			/**
       
   371 			 * Fires when the blog status is changed to 'unarchived'.
       
   372 			 *
       
   373 			 * @since MU
       
   374 			 *
       
   375 			 * @param int $blog_id Blog ID.
       
   376 			 */
   303 			do_action( 'unarchive_blog', $blog_id );
   377 			do_action( 'unarchive_blog', $blog_id );
       
   378 		}
   304 	}
   379 	}
   305 
   380 
   306 	// If deleted status changed, issue actions.
   381 	// If deleted status changed, issue actions.
   307 	if ( $details[ 'deleted' ] != $current_details[ 'deleted' ] ) {
   382 	if ( $details['deleted'] != $current_details['deleted'] ) {
   308 		if ( $details[ 'deleted' ] == 1 )
   383 		if ( $details['deleted'] == 1 ) {
       
   384 			/**
       
   385 			 * Fires when the blog status is changed to 'deleted'.
       
   386 			 *
       
   387 			 * @since 3.5.0
       
   388 			 *
       
   389 			 * @param int $blog_id Blog ID.
       
   390 			 */
   309 			do_action( 'make_delete_blog', $blog_id );
   391 			do_action( 'make_delete_blog', $blog_id );
   310 		else
   392 		} else {
       
   393 			/**
       
   394 			 * Fires when the blog status is changed to 'undeleted'.
       
   395 			 *
       
   396 			 * @since 3.5.0
       
   397 			 *
       
   398 			 * @param int $blog_id Blog ID.
       
   399 			 */
   311 			do_action( 'make_undelete_blog', $blog_id );
   400 			do_action( 'make_undelete_blog', $blog_id );
   312 	}
   401 		}
   313 
   402 	}
   314 	if ( isset( $details[ 'public' ] ) ) {
   403 
       
   404 	if ( isset( $details['public'] ) ) {
   315 		switch_to_blog( $blog_id );
   405 		switch_to_blog( $blog_id );
   316 		update_option( 'blog_public', $details[ 'public' ] );
   406 		update_option( 'blog_public', $details['public'] );
   317 		restore_current_blog();
   407 		restore_current_blog();
   318 	}
   408 	}
   319 
   409 
   320 	refresh_blog_details($blog_id);
   410 	refresh_blog_details($blog_id);
   321 
   411 
   370 
   460 
   371 	switch_to_blog( $id );
   461 	switch_to_blog( $id );
   372 	$value = get_option( $option, $default );
   462 	$value = get_option( $option, $default );
   373 	restore_current_blog();
   463 	restore_current_blog();
   374 
   464 
   375 	return apply_filters( 'blog_option_' . $option, $value, $id );
   465 	/**
       
   466 	 * Filter a blog option value.
       
   467 	 *
       
   468 	 * The dynamic portion of the hook name, `$option`, refers to the blog option name.
       
   469 	 *
       
   470 	 * @since 3.5.0
       
   471 	 *
       
   472 	 * @param string  $value The option value.
       
   473 	 * @param int     $id    Blog ID.
       
   474 	 */
       
   475 	return apply_filters( "blog_option_{$option}", $value, $id );
   376 }
   476 }
   377 
   477 
   378 /**
   478 /**
   379  * Add a new option for a given blog id.
   479  * Add a new option for a given blog id.
   380  *
   480  *
   476  * @see restore_current_blog()
   576  * @see restore_current_blog()
   477  * @since MU
   577  * @since MU
   478  *
   578  *
   479  * @param int $new_blog The id of the blog you want to switch to. Default: current blog
   579  * @param int $new_blog The id of the blog you want to switch to. Default: current blog
   480  * @param bool $deprecated Deprecated argument
   580  * @param bool $deprecated Deprecated argument
   481  * @return bool True on success, false if the validation failed
   581  * @return bool Always returns True.
   482  */
   582  */
   483 function switch_to_blog( $new_blog, $deprecated = null ) {
   583 function switch_to_blog( $new_blog, $deprecated = null ) {
   484 	global $wpdb, $wp_roles;
   584 	global $wpdb, $wp_roles;
   485 
   585 
   486 	if ( empty( $new_blog ) )
   586 	if ( empty( $new_blog ) )
   487 		$new_blog = $GLOBALS['blog_id'];
   587 		$new_blog = $GLOBALS['blog_id'];
   488 
   588 
   489 	$GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id'];
   589 	$GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id'];
   490 
   590 
   491 	/* If we're switching to the same blog id that we're on,
   591 	/*
   492 	* set the right vars, do the associated actions, but skip
   592 	 * If we're switching to the same blog id that we're on,
   493 	* the extra unnecessary work */
   593 	 * set the right vars, do the associated actions, but skip
       
   594 	 * the extra unnecessary work
       
   595 	 */
   494 	if ( $new_blog == $GLOBALS['blog_id'] ) {
   596 	if ( $new_blog == $GLOBALS['blog_id'] ) {
       
   597 		/**
       
   598 		 * Fires when the blog is switched.
       
   599 		 *
       
   600 		 * @since MU
       
   601 		 *
       
   602 		 * @param int $new_blog New blog ID.
       
   603 		 * @param int $new_blog Blog ID.
       
   604 		 */
   495 		do_action( 'switch_blog', $new_blog, $new_blog );
   605 		do_action( 'switch_blog', $new_blog, $new_blog );
   496 		$GLOBALS['switched'] = true;
   606 		$GLOBALS['switched'] = true;
   497 		return true;
   607 		return true;
   498 	}
   608 	}
   499 
   609 
   513 			$global_groups = false;
   623 			$global_groups = false;
   514 
   624 
   515 		wp_cache_init();
   625 		wp_cache_init();
   516 
   626 
   517 		if ( function_exists( 'wp_cache_add_global_groups' ) ) {
   627 		if ( function_exists( 'wp_cache_add_global_groups' ) ) {
   518 			if ( is_array( $global_groups ) )
   628 			if ( is_array( $global_groups ) ) {
   519 				wp_cache_add_global_groups( $global_groups );
   629 				wp_cache_add_global_groups( $global_groups );
   520 			else
   630 			} else {
   521 				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache' ) );
   631 				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) );
       
   632 			}
   522 			wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
   633 			wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
   523 		}
   634 		}
   524 	}
   635 	}
   525 
   636 
   526 	if ( did_action( 'init' ) ) {
   637 	if ( did_action( 'init' ) ) {
   527 		$wp_roles->reinit();
   638 		$wp_roles->reinit();
   528 		$current_user = wp_get_current_user();
   639 		$current_user = wp_get_current_user();
   529 		$current_user->for_blog( $new_blog );
   640 		$current_user->for_blog( $new_blog );
   530 	}
   641 	}
   531 
   642 
       
   643 	/** This filter is documented in wp-includes/ms-blogs.php */
   532 	do_action( 'switch_blog', $new_blog, $prev_blog_id );
   644 	do_action( 'switch_blog', $new_blog, $prev_blog_id );
   533 	$GLOBALS['switched'] = true;
   645 	$GLOBALS['switched'] = true;
   534 
   646 
   535 	return true;
   647 	return true;
   536 }
   648 }
   550 		return false;
   662 		return false;
   551 
   663 
   552 	$blog = array_pop( $GLOBALS['_wp_switched_stack'] );
   664 	$blog = array_pop( $GLOBALS['_wp_switched_stack'] );
   553 
   665 
   554 	if ( $GLOBALS['blog_id'] == $blog ) {
   666 	if ( $GLOBALS['blog_id'] == $blog ) {
       
   667 		/** This filter is documented in wp-includes/ms-blogs.php */
   555 		do_action( 'switch_blog', $blog, $blog );
   668 		do_action( 'switch_blog', $blog, $blog );
   556 		// If we still have items in the switched stack, consider ourselves still 'switched'
   669 		// If we still have items in the switched stack, consider ourselves still 'switched'
   557 		$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
   670 		$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
   558 		return true;
   671 		return true;
   559 	}
   672 	}
   574 			$global_groups = false;
   687 			$global_groups = false;
   575 
   688 
   576 		wp_cache_init();
   689 		wp_cache_init();
   577 
   690 
   578 		if ( function_exists( 'wp_cache_add_global_groups' ) ) {
   691 		if ( function_exists( 'wp_cache_add_global_groups' ) ) {
   579 			if ( is_array( $global_groups ) )
   692 			if ( is_array( $global_groups ) ) {
   580 				wp_cache_add_global_groups( $global_groups );
   693 				wp_cache_add_global_groups( $global_groups );
   581 			else
   694 			} else {
   582 				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', ' blog-id-cache' ) );
   695 				wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'useremail', 'userslugs', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts', 'blog-id-cache' ) );
       
   696 			}
   583 			wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
   697 			wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
   584 		}
   698 		}
   585 	}
   699 	}
   586 
   700 
   587 	if ( did_action( 'init' ) ) {
   701 	if ( did_action( 'init' ) ) {
   588 		$wp_roles->reinit();
   702 		$wp_roles->reinit();
   589 		$current_user = wp_get_current_user();
   703 		$current_user = wp_get_current_user();
   590 		$current_user->for_blog( $blog );
   704 		$current_user->for_blog( $blog );
   591 	}
   705 	}
   592 
   706 
       
   707 	/** This filter is documented in wp-includes/ms-blogs.php */
   593 	do_action( 'switch_blog', $blog, $prev_blog_id );
   708 	do_action( 'switch_blog', $blog, $prev_blog_id );
   594 
   709 
   595 	// If we still have items in the switched stack, consider ourselves still 'switched'
   710 	// If we still have items in the switched stack, consider ourselves still 'switched'
   596 	$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
   711 	$GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
   597 
   712 
   659 	if ( false === $result )
   774 	if ( false === $result )
   660 		return false;
   775 		return false;
   661 
   776 
   662 	refresh_blog_details( $blog_id );
   777 	refresh_blog_details( $blog_id );
   663 
   778 
   664 	if ( 'spam' == $pref )
   779 	if ( 'spam' == $pref ) {
   665 		( $value == 1 ) ? do_action( 'make_spam_blog', $blog_id ) :	do_action( 'make_ham_blog', $blog_id );
   780 		if ( $value == 1 ) {
   666 	elseif ( 'mature' == $pref )
   781 			/** This filter is documented in wp-includes/ms-blogs.php */
   667 		( $value == 1 ) ? do_action( 'mature_blog', $blog_id ) : do_action( 'unmature_blog', $blog_id );
   782 			do_action( 'make_spam_blog', $blog_id );
   668 	elseif ( 'archived' == $pref )
   783 		} else {
   669 		( $value == 1 ) ? do_action( 'archive_blog', $blog_id ) : do_action( 'unarchive_blog', $blog_id );
   784 			/** This filter is documented in wp-includes/ms-blogs.php */
   670 	elseif ( 'deleted' == $pref )
   785 			do_action( 'make_ham_blog', $blog_id );
   671 		( $value == 1 ) ? do_action( 'make_delete_blog', $blog_id ) : do_action( 'make_undelete_blog', $blog_id );
   786 		}
   672 	elseif ( 'public' == $pref )
   787 	} elseif ( 'mature' == $pref ) {
       
   788 		if ( $value == 1 ) {
       
   789 			/** This filter is documented in wp-includes/ms-blogs.php */
       
   790 			do_action( 'mature_blog', $blog_id );
       
   791 		} else {
       
   792 			/** This filter is documented in wp-includes/ms-blogs.php */
       
   793 			do_action( 'unmature_blog', $blog_id );
       
   794 		}
       
   795 	} elseif ( 'archived' == $pref ) {
       
   796 		if ( $value == 1 ) {
       
   797 			/** This filter is documented in wp-includes/ms-blogs.php */
       
   798 			do_action( 'archive_blog', $blog_id );
       
   799 		} else {
       
   800 			/** This filter is documented in wp-includes/ms-blogs.php */
       
   801 			do_action( 'unarchive_blog', $blog_id );
       
   802 		}
       
   803 	} elseif ( 'deleted' == $pref ) {
       
   804 		if ( $value == 1 ) {
       
   805 			/** This filter is documented in wp-includes/ms-blogs.php */
       
   806 			do_action( 'make_delete_blog', $blog_id );
       
   807 		} else {
       
   808 			/** This filter is documented in wp-includes/ms-blogs.php */
       
   809 			do_action( 'make_undelete_blog', $blog_id );
       
   810 		}
       
   811 	} elseif ( 'public' == $pref ) {
       
   812 		/**
       
   813 		 * Fires after the current blog's 'public' setting is updated.
       
   814 		 *
       
   815 		 * @since MU
       
   816 		 *
       
   817 		 * @param int    $blog_id Blog ID.
       
   818 		 * @param string $value   The value of blog status.
       
   819  		 */
   673 		do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public().
   820 		do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public().
       
   821 	}
   674 
   822 
   675 	return $value;
   823 	return $value;
   676 }
   824 }
   677 
   825 
   678 /**
   826 /**
   722  * @param string $old_status The old post status
   870  * @param string $old_status The old post status
   723  * @param object $post Post object
   871  * @param object $post Post object
   724  */
   872  */
   725 function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) {
   873 function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) {
   726 	$post_type_obj = get_post_type_object( $post->post_type );
   874 	$post_type_obj = get_post_type_object( $post->post_type );
   727 	if ( ! $post_type_obj->public )
   875 	if ( ! $post_type_obj || ! $post_type_obj->public ) {
   728 		return;
   876 		return;
   729 
   877 	}
   730 	if ( 'publish' != $new_status && 'publish' != $old_status )
   878 
       
   879 	if ( 'publish' != $new_status && 'publish' != $old_status ) {
   731 		return;
   880 		return;
       
   881 	}
   732 
   882 
   733 	// Post was freshly published, published post was saved, or published post was unpublished.
   883 	// Post was freshly published, published post was saved, or published post was unpublished.
   734 
   884 
   735 	wpmu_update_blogs_date();
   885 	wpmu_update_blogs_date();
   736 }
   886 }
   744  */
   894  */
   745 function _update_blog_date_on_post_delete( $post_id ) {
   895 function _update_blog_date_on_post_delete( $post_id ) {
   746 	$post = get_post( $post_id );
   896 	$post = get_post( $post_id );
   747 
   897 
   748 	$post_type_obj = get_post_type_object( $post->post_type );
   898 	$post_type_obj = get_post_type_object( $post->post_type );
   749 	if ( ! $post_type_obj->public )
   899 	if ( ! $post_type_obj || ! $post_type_obj->public ) {
   750 		return;
   900 		return;
   751 
   901 	}
   752 	if ( 'publish' != $post->post_status )
   902 
       
   903 	if ( 'publish' != $post->post_status ) {
   753 		return;
   904 		return;
       
   905 	}
   754 
   906 
   755 	wpmu_update_blogs_date();
   907 	wpmu_update_blogs_date();
   756 }
   908 }
   757 
   909 
       
   910 /**
       
   911  * Handler for updating the blog posts count date when a post is deleted.
       
   912  *
       
   913  * @since 4.0.0
       
   914  *
       
   915  * @param int $post_id Post ID.
       
   916  */
       
   917 function _update_posts_count_on_delete( $post_id ) {
       
   918 	$post = get_post( $post_id );
       
   919 
       
   920 	if ( ! $post || 'publish' !== $post->post_status ) {
       
   921 		return;
       
   922 	}
       
   923 
       
   924 	update_posts_count();
       
   925 }
       
   926 
       
   927 /**
       
   928  * Handler for updating the blog posts count date when a post status changes.
       
   929  *
       
   930  * @since 4.0.0
       
   931  *
       
   932  * @param string $new_status The status the post is changing to.
       
   933  * @param string $old_status The status the post is changing from.
       
   934  */
       
   935 function _update_posts_count_on_transition_post_status( $new_status, $old_status ) {
       
   936 	if ( $new_status === $old_status ) {
       
   937 		return;
       
   938 	}
       
   939 
       
   940 	if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
       
   941 		return;
       
   942 	}
       
   943 
       
   944 	update_posts_count();
       
   945 }
       
   946