4 * Site/blog functions that work with the blogs table and related data.
7 * @subpackage Multisite
12 * Update the last_updated field for the current blog.
16 * @global wpdb $wpdb WordPress database abstraction object.
18 function wpmu_update_blogs_date() {
21 update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) );
23 * Fires after the blog details are updated.
27 * @param int $blog_id Blog ID.
29 do_action( 'wpmu_blog_updated', $wpdb->blogid );
33 * Get a full blog URL, given a blog id.
37 * @param int $blog_id Blog ID
38 * @return string Full URL of the blog if found. Empty string if not.
40 function get_blogaddress_by_id( $blog_id ) {
41 $bloginfo = get_blog_details( (int) $blog_id );
43 if ( empty( $bloginfo ) ) {
47 $scheme = parse_url( $bloginfo->home, PHP_URL_SCHEME );
48 $scheme = empty( $scheme ) ? 'http' : $scheme;
50 return esc_url( $scheme . '://' . $bloginfo->domain . $bloginfo->path );
54 * Get a full blog URL, given a blog name.
58 * @param string $blogname The (subdomain or directory) name
61 function get_blogaddress_by_name( $blogname ) {
62 if ( is_subdomain_install() ) {
63 if ( $blogname == 'main' )
65 $url = rtrim( network_home_url(), '/' );
66 if ( !empty( $blogname ) )
67 $url = preg_replace( '|^([^\.]+://)|', "\${1}" . $blogname . '.', $url );
69 $url = network_home_url( $blogname );
71 return esc_url( $url . '/' );
75 * Given a blog's (subdomain or directory) slug, retrieve its id.
79 * @global wpdb $wpdb WordPress database abstraction object.
82 * @return int A blog id
84 function get_id_from_blogname( $slug ) {
87 $current_site = get_current_site();
88 $slug = trim( $slug, '/' );
90 $blog_id = wp_cache_get( 'get_id_from_blogname_' . $slug, 'blog-details' );
94 if ( is_subdomain_install() ) {
95 $domain = $slug . '.' . $current_site->domain;
96 $path = $current_site->path;
98 $domain = $current_site->domain;
99 $path = $current_site->path . $slug . '/';
102 $blog_id = $wpdb->get_var( $wpdb->prepare("SELECT blog_id FROM {$wpdb->blogs} WHERE domain = %s AND path = %s", $domain, $path) );
103 wp_cache_set( 'get_id_from_blogname_' . $slug, $blog_id, 'blog-details' );
108 * Retrieve the details for a blog from the blogs table and blog options.
112 * @global wpdb $wpdb WordPress database abstraction object.
114 * @param int|string|array $fields Optional. A blog ID, a blog slug, or an array of fields to query against.
115 * If not specified the current blog ID is used.
116 * @param bool $get_all Whether to retrieve all details or only the details in the blogs table.
118 * @return object|false Blog details on success. False on failure.
120 function get_blog_details( $fields = null, $get_all = true ) {
123 if ( is_array($fields ) ) {
124 if ( isset($fields['blog_id']) ) {
125 $blog_id = $fields['blog_id'];
126 } elseif ( isset($fields['domain']) && isset($fields['path']) ) {
127 $key = md5( $fields['domain'] . $fields['path'] );
128 $blog = wp_cache_get($key, 'blog-lookup');
129 if ( false !== $blog )
131 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
132 $nowww = substr( $fields['domain'], 4 );
133 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) AND path = %s ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'], $fields['path'] ) );
135 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s AND path = %s", $fields['domain'], $fields['path'] ) );
138 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
139 $blog_id = $blog->blog_id;
143 } elseif ( isset($fields['domain']) && is_subdomain_install() ) {
144 $key = md5( $fields['domain'] );
145 $blog = wp_cache_get($key, 'blog-lookup');
146 if ( false !== $blog )
148 if ( substr( $fields['domain'], 0, 4 ) == 'www.' ) {
149 $nowww = substr( $fields['domain'], 4 );
150 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain IN (%s,%s) ORDER BY CHAR_LENGTH(domain) DESC", $nowww, $fields['domain'] ) );
152 $blog = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE domain = %s", $fields['domain'] ) );
155 wp_cache_set($blog->blog_id . 'short', $blog, 'blog-details');
156 $blog_id = $blog->blog_id;
165 $blog_id = get_current_blog_id();
166 elseif ( ! is_numeric( $fields ) )
167 $blog_id = get_id_from_blogname( $fields );
172 $blog_id = (int) $blog_id;
174 $all = $get_all == true ? '' : 'short';
175 $details = wp_cache_get( $blog_id . $all, 'blog-details' );
178 if ( ! is_object( $details ) ) {
179 if ( $details == -1 ) {
182 // Clear old pre-serialized objects. Cache clients do better with that.
183 wp_cache_delete( $blog_id . $all, 'blog-details' );
191 // Try the other cache.
193 $details = wp_cache_get( $blog_id . 'short', 'blog-details' );
195 $details = wp_cache_get( $blog_id, 'blog-details' );
196 // If short was requested and full cache is set, we can return.
198 if ( ! is_object( $details ) ) {
199 if ( $details == -1 ) {
202 // Clear old pre-serialized objects. Cache clients do better with that.
203 wp_cache_delete( $blog_id, 'blog-details' );
212 if ( empty($details) ) {
213 $details = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->blogs WHERE blog_id = %d /* get_blog_details */", $blog_id ) );
215 // Set the full cache.
216 wp_cache_set( $blog_id, -1, 'blog-details' );
222 wp_cache_set( $blog_id . $all, $details, 'blog-details' );
226 switch_to_blog( $blog_id );
227 $details->blogname = get_option( 'blogname' );
228 $details->siteurl = get_option( 'siteurl' );
229 $details->post_count = get_option( 'post_count' );
230 $details->home = get_option( 'home' );
231 restore_current_blog();
234 * Filter a blog's details.
238 * @param object $details The blog details.
240 $details = apply_filters( 'blog_details', $details );
242 wp_cache_set( $blog_id . $all, $details, 'blog-details' );
244 $key = md5( $details->domain . $details->path );
245 wp_cache_set( $key, $details, 'blog-lookup' );
251 * Clear the blog details cache.
255 * @param int $blog_id Optional. Blog ID. Defaults to current blog.
257 function refresh_blog_details( $blog_id = 0 ) {
258 $blog_id = (int) $blog_id;
260 $blog_id = get_current_blog_id();
263 $details = get_blog_details( $blog_id, false );
265 // Make sure clean_blog_cache() gets the blog ID
266 // when the blog has been previously cached as
268 $details = (object) array(
269 'blog_id' => $blog_id,
275 clean_blog_cache( $details );
278 * Fires after the blog details cache is cleared.
282 * @param int $blog_id Blog ID.
284 do_action( 'refresh_blog_details', $blog_id );
288 * Update the details for a blog. Updates the blogs table for a given blog id.
292 * @global wpdb $wpdb WordPress database abstraction object.
294 * @param int $blog_id Blog ID
295 * @param array $details Array of details keyed by blogs table field names.
296 * @return bool True if update succeeds, false otherwise.
298 function update_blog_details( $blog_id, $details = array() ) {
301 if ( empty($details) )
304 if ( is_object($details) )
305 $details = get_object_vars($details);
307 $current_details = get_blog_details($blog_id, false);
308 if ( empty($current_details) )
311 $current_details = get_object_vars($current_details);
313 $details = array_merge($current_details, $details);
314 $details['last_updated'] = current_time('mysql', true);
316 $update_details = array();
317 $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
318 foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) {
319 if ( 'path' === $field ) {
320 $details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) );
323 $update_details[ $field ] = $details[ $field ];
326 $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
328 if ( false === $result )
331 // If spam status changed, issue actions.
332 if ( $details['spam'] != $current_details['spam'] ) {
333 if ( $details['spam'] == 1 ) {
335 * Fires when the blog status is changed to 'spam'.
339 * @param int $blog_id Blog ID.
341 do_action( 'make_spam_blog', $blog_id );
344 * Fires when the blog status is changed to 'ham'.
348 * @param int $blog_id Blog ID.
350 do_action( 'make_ham_blog', $blog_id );
354 // If mature status changed, issue actions.
355 if ( $details['mature'] != $current_details['mature'] ) {
356 if ( $details['mature'] == 1 ) {
358 * Fires when the blog status is changed to 'mature'.
362 * @param int $blog_id Blog ID.
364 do_action( 'mature_blog', $blog_id );
367 * Fires when the blog status is changed to 'unmature'.
371 * @param int $blog_id Blog ID.
373 do_action( 'unmature_blog', $blog_id );
377 // If archived status changed, issue actions.
378 if ( $details['archived'] != $current_details['archived'] ) {
379 if ( $details['archived'] == 1 ) {
381 * Fires when the blog status is changed to 'archived'.
385 * @param int $blog_id Blog ID.
387 do_action( 'archive_blog', $blog_id );
390 * Fires when the blog status is changed to 'unarchived'.
394 * @param int $blog_id Blog ID.
396 do_action( 'unarchive_blog', $blog_id );
400 // If deleted status changed, issue actions.
401 if ( $details['deleted'] != $current_details['deleted'] ) {
402 if ( $details['deleted'] == 1 ) {
404 * Fires when the blog status is changed to 'deleted'.
408 * @param int $blog_id Blog ID.
410 do_action( 'make_delete_blog', $blog_id );
413 * Fires when the blog status is changed to 'undeleted'.
417 * @param int $blog_id Blog ID.
419 do_action( 'make_undelete_blog', $blog_id );
423 if ( isset( $details['public'] ) ) {
424 switch_to_blog( $blog_id );
425 update_option( 'blog_public', $details['public'] );
426 restore_current_blog();
429 refresh_blog_details($blog_id);
435 * Clean the blog cache
439 * @param stdClass $blog The blog details as returned from get_blog_details()
441 function clean_blog_cache( $blog ) {
442 $blog_id = $blog->blog_id;
443 $domain_path_key = md5( $blog->domain . $blog->path );
445 wp_cache_delete( $blog_id , 'blog-details' );
446 wp_cache_delete( $blog_id . 'short' , 'blog-details' );
447 wp_cache_delete( $domain_path_key, 'blog-lookup' );
448 wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
449 wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
450 wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' );
451 wp_cache_delete( $domain_path_key, 'blog-id-cache' );
455 * Retrieve option value for a given blog id based on name of option.
457 * If the option does not exist or does not have a value, then the return value
458 * will be false. This is useful to check whether you need to install an option
459 * and is commonly used during installation of plugin options and to test
460 * whether upgrading is required.
462 * If the option was serialized then it will be unserialized when it is returned.
466 * @param int $id A blog ID. Can be null to refer to the current blog.
467 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
468 * @param mixed $default Optional. Default value to return if the option does not exist.
469 * @return mixed Value set for the option.
471 function get_blog_option( $id, $option, $default = false ) {
475 $id = get_current_blog_id();
477 if ( get_current_blog_id() == $id )
478 return get_option( $option, $default );
480 switch_to_blog( $id );
481 $value = get_option( $option, $default );
482 restore_current_blog();
485 * Filter a blog option value.
487 * The dynamic portion of the hook name, `$option`, refers to the blog option name.
491 * @param string $value The option value.
492 * @param int $id Blog ID.
494 return apply_filters( "blog_option_{$option}", $value, $id );
498 * Add a new option for a given blog id.
500 * You do not need to serialize values. If the value needs to be serialized, then
501 * it will be serialized before it is inserted into the database. Remember,
502 * resources can not be serialized or added as an option.
504 * You can create options without values and then update the values later.
505 * Existing options will not be updated and checks are performed to ensure that you
506 * aren't adding a protected WordPress option. Care should be taken to not name
507 * options the same as the ones which are protected.
511 * @param int $id A blog ID. Can be null to refer to the current blog.
512 * @param string $option Name of option to add. Expected to not be SQL-escaped.
513 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
514 * @return bool False if option was not added and true if option was added.
516 function add_blog_option( $id, $option, $value ) {
520 $id = get_current_blog_id();
522 if ( get_current_blog_id() == $id )
523 return add_option( $option, $value );
525 switch_to_blog( $id );
526 $return = add_option( $option, $value );
527 restore_current_blog();
533 * Removes option by name for a given blog id. Prevents removal of protected WordPress options.
537 * @param int $id A blog ID. Can be null to refer to the current blog.
538 * @param string $option Name of option to remove. Expected to not be SQL-escaped.
539 * @return bool True, if option is successfully deleted. False on failure.
541 function delete_blog_option( $id, $option ) {
545 $id = get_current_blog_id();
547 if ( get_current_blog_id() == $id )
548 return delete_option( $option );
550 switch_to_blog( $id );
551 $return = delete_option( $option );
552 restore_current_blog();
558 * Update an option for a particular blog.
562 * @param int $id The blog id
563 * @param string $option The option key
564 * @param mixed $value The option value
565 * @return bool True on success, false on failure.
567 function update_blog_option( $id, $option, $value, $deprecated = null ) {
570 if ( null !== $deprecated )
571 _deprecated_argument( __FUNCTION__, '3.1' );
573 if ( get_current_blog_id() == $id )
574 return update_option( $option, $value );
576 switch_to_blog( $id );
577 $return = update_option( $option, $value );
578 restore_current_blog();
580 refresh_blog_details( $id );
586 * Switch the current blog.
588 * This function is useful if you need to pull posts, or other information,
589 * from other blogs. You can switch back afterwards using restore_current_blog().
591 * Things that aren't switched:
592 * - autoloaded options. See #14992
593 * - plugins. See #14941
595 * @see restore_current_blog()
599 * @global int $blog_id
600 * @global array $_wp_switched_stack
601 * @global bool $switched
602 * @global string $table_prefix
603 * @global WP_Object_Cache $wp_object_cache
605 * @param int $new_blog The id of the blog you want to switch to. Default: current blog
606 * @param bool $deprecated Deprecated argument
607 * @return true Always returns True.
609 function switch_to_blog( $new_blog, $deprecated = null ) {
612 if ( empty( $new_blog ) )
613 $new_blog = $GLOBALS['blog_id'];
615 $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id'];
618 * If we're switching to the same blog id that we're on,
619 * set the right vars, do the associated actions, but skip
620 * the extra unnecessary work
622 if ( $new_blog == $GLOBALS['blog_id'] ) {
624 * Fires when the blog is switched.
628 * @param int $new_blog New blog ID.
629 * @param int $new_blog Blog ID.
631 do_action( 'switch_blog', $new_blog, $new_blog );
632 $GLOBALS['switched'] = true;
636 $wpdb->set_blog_id( $new_blog );
637 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
638 $prev_blog_id = $GLOBALS['blog_id'];
639 $GLOBALS['blog_id'] = $new_blog;
641 if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
642 wp_cache_switch_to_blog( $new_blog );
644 global $wp_object_cache;
646 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
647 $global_groups = $wp_object_cache->global_groups;
649 $global_groups = false;
653 if ( function_exists( 'wp_cache_add_global_groups' ) ) {
654 if ( is_array( $global_groups ) ) {
655 wp_cache_add_global_groups( $global_groups );
657 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' ) );
659 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
663 if ( did_action( 'init' ) ) {
664 wp_roles()->reinit();
665 $current_user = wp_get_current_user();
666 $current_user->for_blog( $new_blog );
669 /** This filter is documented in wp-includes/ms-blogs.php */
670 do_action( 'switch_blog', $new_blog, $prev_blog_id );
671 $GLOBALS['switched'] = true;
677 * Restore the current blog, after calling switch_to_blog()
679 * @see switch_to_blog()
683 * @global array $_wp_switched_stack
684 * @global int $blog_id
685 * @global bool $switched
686 * @global string $table_prefix
687 * @global WP_Object_Cache $wp_object_cache
689 * @return bool True on success, false if we're already on the current blog
691 function restore_current_blog() {
694 if ( empty( $GLOBALS['_wp_switched_stack'] ) )
697 $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
699 if ( $GLOBALS['blog_id'] == $blog ) {
700 /** This filter is documented in wp-includes/ms-blogs.php */
701 do_action( 'switch_blog', $blog, $blog );
702 // If we still have items in the switched stack, consider ourselves still 'switched'
703 $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
707 $wpdb->set_blog_id( $blog );
708 $prev_blog_id = $GLOBALS['blog_id'];
709 $GLOBALS['blog_id'] = $blog;
710 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
712 if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
713 wp_cache_switch_to_blog( $blog );
715 global $wp_object_cache;
717 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
718 $global_groups = $wp_object_cache->global_groups;
720 $global_groups = false;
724 if ( function_exists( 'wp_cache_add_global_groups' ) ) {
725 if ( is_array( $global_groups ) ) {
726 wp_cache_add_global_groups( $global_groups );
728 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' ) );
730 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
734 if ( did_action( 'init' ) ) {
735 wp_roles()->reinit();
736 $current_user = wp_get_current_user();
737 $current_user->for_blog( $blog );
740 /** This filter is documented in wp-includes/ms-blogs.php */
741 do_action( 'switch_blog', $blog, $prev_blog_id );
743 // If we still have items in the switched stack, consider ourselves still 'switched'
744 $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
750 * Determines if switch_to_blog() is in effect
754 * @global array $_wp_switched_stack
756 * @return bool True if switched, false otherwise.
758 function ms_is_switched() {
759 return ! empty( $GLOBALS['_wp_switched_stack'] );
763 * Check if a particular blog is archived.
767 * @param int $id The blog id
768 * @return string Whether the blog is archived or not
770 function is_archived( $id ) {
771 return get_blog_status($id, 'archived');
775 * Update the 'archived' status of a particular blog.
779 * @param int $id The blog id
780 * @param string $archived The new status
781 * @return string $archived
783 function update_archived( $id, $archived ) {
784 update_blog_status($id, 'archived', $archived);
789 * Update a blog details field.
793 * @global wpdb $wpdb WordPress database abstraction object.
795 * @param int $blog_id BLog ID
796 * @param string $pref A field name
797 * @param string $value Value for $pref
798 * @param null $deprecated
799 * @return string|false $value
801 function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) {
804 if ( null !== $deprecated )
805 _deprecated_argument( __FUNCTION__, '3.1' );
807 if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
810 $result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
812 if ( false === $result )
815 refresh_blog_details( $blog_id );
817 if ( 'spam' == $pref ) {
819 /** This filter is documented in wp-includes/ms-blogs.php */
820 do_action( 'make_spam_blog', $blog_id );
822 /** This filter is documented in wp-includes/ms-blogs.php */
823 do_action( 'make_ham_blog', $blog_id );
825 } elseif ( 'mature' == $pref ) {
827 /** This filter is documented in wp-includes/ms-blogs.php */
828 do_action( 'mature_blog', $blog_id );
830 /** This filter is documented in wp-includes/ms-blogs.php */
831 do_action( 'unmature_blog', $blog_id );
833 } elseif ( 'archived' == $pref ) {
835 /** This filter is documented in wp-includes/ms-blogs.php */
836 do_action( 'archive_blog', $blog_id );
838 /** This filter is documented in wp-includes/ms-blogs.php */
839 do_action( 'unarchive_blog', $blog_id );
841 } elseif ( 'deleted' == $pref ) {
843 /** This filter is documented in wp-includes/ms-blogs.php */
844 do_action( 'make_delete_blog', $blog_id );
846 /** This filter is documented in wp-includes/ms-blogs.php */
847 do_action( 'make_undelete_blog', $blog_id );
849 } elseif ( 'public' == $pref ) {
851 * Fires after the current blog's 'public' setting is updated.
855 * @param int $blog_id Blog ID.
856 * @param string $value The value of blog status.
858 do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public().
865 * Get a blog details field.
869 * @global wpdb $wpdb WordPress database abstraction object.
871 * @param int $id The blog id
872 * @param string $pref A field name
873 * @return bool|string|null $value
875 function get_blog_status( $id, $pref ) {
878 $details = get_blog_details( $id, false );
880 return $details->$pref;
882 return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) );
886 * Get a list of most recently updated blogs.
890 * @global wpdb $wpdb WordPress database abstraction object.
892 * @param mixed $deprecated Not used
893 * @param int $start The offset
894 * @param int $quantity The maximum number of blogs to retrieve. Default is 40.
895 * @return array The list of blogs
897 function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
900 if ( ! empty( $deprecated ) )
901 _deprecated_argument( __FUNCTION__, 'MU' ); // never used
903 return $wpdb->get_results( $wpdb->prepare("SELECT blog_id, domain, path FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' ORDER BY last_updated DESC limit %d, %d", $wpdb->siteid, $start, $quantity ) , ARRAY_A );
907 * Handler for updating the blog date when a post is published or an already published post is changed.
911 * @param string $new_status The new post status
912 * @param string $old_status The old post status
913 * @param object $post Post object
915 function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) {
916 $post_type_obj = get_post_type_object( $post->post_type );
917 if ( ! $post_type_obj || ! $post_type_obj->public ) {
921 if ( 'publish' != $new_status && 'publish' != $old_status ) {
925 // Post was freshly published, published post was saved, or published post was unpublished.
927 wpmu_update_blogs_date();
931 * Handler for updating the blog date when a published post is deleted.
935 * @param int $post_id Post ID
937 function _update_blog_date_on_post_delete( $post_id ) {
938 $post = get_post( $post_id );
940 $post_type_obj = get_post_type_object( $post->post_type );
941 if ( ! $post_type_obj || ! $post_type_obj->public ) {
945 if ( 'publish' != $post->post_status ) {
949 wpmu_update_blogs_date();
953 * Handler for updating the blog posts count date when a post is deleted.
957 * @param int $post_id Post ID.
959 function _update_posts_count_on_delete( $post_id ) {
960 $post = get_post( $post_id );
962 if ( ! $post || 'publish' !== $post->post_status ) {
966 update_posts_count();
970 * Handler for updating the blog posts count date when a post status changes.
974 * @param string $new_status The status the post is changing to.
975 * @param string $old_status The status the post is changing from.
977 function _update_posts_count_on_transition_post_status( $new_status, $old_status ) {
978 if ( $new_status === $old_status ) {
982 if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
986 update_posts_count();