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 site.
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 Site 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 WP_Site|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 = WP_Site::get_instance( $blog_id );
215 // Set the full cache.
216 wp_cache_set( $blog_id, -1, 'blog-details' );
221 if ( ! $details instanceof WP_Site ) {
222 $details = new WP_Site( $details );
226 wp_cache_set( $blog_id . $all, $details, 'blog-details' );
230 switch_to_blog( $blog_id );
231 $details->blogname = get_option( 'blogname' );
232 $details->siteurl = get_option( 'siteurl' );
233 $details->post_count = get_option( 'post_count' );
234 $details->home = get_option( 'home' );
235 restore_current_blog();
238 * Filter a blog's details.
242 * @param object $details The blog details.
244 $details = apply_filters( 'blog_details', $details );
246 wp_cache_set( $blog_id . $all, $details, 'blog-details' );
248 $key = md5( $details->domain . $details->path );
249 wp_cache_set( $key, $details, 'blog-lookup' );
255 * Clear the blog details cache.
259 * @param int $blog_id Optional. Blog ID. Defaults to current blog.
261 function refresh_blog_details( $blog_id = 0 ) {
262 $blog_id = (int) $blog_id;
264 $blog_id = get_current_blog_id();
267 $details = get_blog_details( $blog_id, false );
269 // Make sure clean_blog_cache() gets the blog ID
270 // when the blog has been previously cached as
272 $details = (object) array(
273 'blog_id' => $blog_id,
279 clean_blog_cache( $details );
282 * Fires after the blog details cache is cleared.
286 * @param int $blog_id Blog ID.
288 do_action( 'refresh_blog_details', $blog_id );
292 * Update the details for a blog. Updates the blogs table for a given blog id.
296 * @global wpdb $wpdb WordPress database abstraction object.
298 * @param int $blog_id Blog ID
299 * @param array $details Array of details keyed by blogs table field names.
300 * @return bool True if update succeeds, false otherwise.
302 function update_blog_details( $blog_id, $details = array() ) {
305 if ( empty($details) )
308 if ( is_object($details) )
309 $details = get_object_vars($details);
311 $current_details = get_blog_details($blog_id, false);
312 if ( empty($current_details) )
315 $current_details = get_object_vars($current_details);
317 $details = array_merge($current_details, $details);
318 $details['last_updated'] = current_time('mysql', true);
320 $update_details = array();
321 $fields = array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id');
322 foreach ( array_intersect( array_keys( $details ), $fields ) as $field ) {
323 if ( 'path' === $field ) {
324 $details[ $field ] = trailingslashit( '/' . trim( $details[ $field ], '/' ) );
327 $update_details[ $field ] = $details[ $field ];
330 $result = $wpdb->update( $wpdb->blogs, $update_details, array('blog_id' => $blog_id) );
332 if ( false === $result )
335 // If spam status changed, issue actions.
336 if ( $details['spam'] != $current_details['spam'] ) {
337 if ( $details['spam'] == 1 ) {
339 * Fires when the blog status is changed to 'spam'.
343 * @param int $blog_id Blog ID.
345 do_action( 'make_spam_blog', $blog_id );
348 * Fires when the blog status is changed to 'ham'.
352 * @param int $blog_id Blog ID.
354 do_action( 'make_ham_blog', $blog_id );
358 // If mature status changed, issue actions.
359 if ( $details['mature'] != $current_details['mature'] ) {
360 if ( $details['mature'] == 1 ) {
362 * Fires when the blog status is changed to 'mature'.
366 * @param int $blog_id Blog ID.
368 do_action( 'mature_blog', $blog_id );
371 * Fires when the blog status is changed to 'unmature'.
375 * @param int $blog_id Blog ID.
377 do_action( 'unmature_blog', $blog_id );
381 // If archived status changed, issue actions.
382 if ( $details['archived'] != $current_details['archived'] ) {
383 if ( $details['archived'] == 1 ) {
385 * Fires when the blog status is changed to 'archived'.
389 * @param int $blog_id Blog ID.
391 do_action( 'archive_blog', $blog_id );
394 * Fires when the blog status is changed to 'unarchived'.
398 * @param int $blog_id Blog ID.
400 do_action( 'unarchive_blog', $blog_id );
404 // If deleted status changed, issue actions.
405 if ( $details['deleted'] != $current_details['deleted'] ) {
406 if ( $details['deleted'] == 1 ) {
408 * Fires when the blog status is changed to 'deleted'.
412 * @param int $blog_id Blog ID.
414 do_action( 'make_delete_blog', $blog_id );
417 * Fires when the blog status is changed to 'undeleted'.
421 * @param int $blog_id Blog ID.
423 do_action( 'make_undelete_blog', $blog_id );
427 if ( isset( $details['public'] ) ) {
428 switch_to_blog( $blog_id );
429 update_option( 'blog_public', $details['public'] );
430 restore_current_blog();
433 refresh_blog_details($blog_id);
439 * Clean the blog cache
443 * @param WP_Site $blog The blog details as returned from get_blog_details()
445 function clean_blog_cache( $blog ) {
446 $blog_id = $blog->blog_id;
447 $domain_path_key = md5( $blog->domain . $blog->path );
449 wp_cache_delete( $blog_id, 'sites' );
450 wp_cache_delete( $blog_id , 'blog-details' );
451 wp_cache_delete( $blog_id . 'short' , 'blog-details' );
452 wp_cache_delete( $domain_path_key, 'blog-lookup' );
453 wp_cache_delete( 'current_blog_' . $blog->domain, 'site-options' );
454 wp_cache_delete( 'current_blog_' . $blog->domain . $blog->path, 'site-options' );
455 wp_cache_delete( 'get_id_from_blogname_' . trim( $blog->path, '/' ), 'blog-details' );
456 wp_cache_delete( $domain_path_key, 'blog-id-cache' );
460 * Retrieve option value for a given blog id based on name of option.
462 * If the option does not exist or does not have a value, then the return value
463 * will be false. This is useful to check whether you need to install an option
464 * and is commonly used during installation of plugin options and to test
465 * whether upgrading is required.
467 * If the option was serialized then it will be unserialized when it is returned.
471 * @param int $id A blog ID. Can be null to refer to the current blog.
472 * @param string $option Name of option to retrieve. Expected to not be SQL-escaped.
473 * @param mixed $default Optional. Default value to return if the option does not exist.
474 * @return mixed Value set for the option.
476 function get_blog_option( $id, $option, $default = false ) {
480 $id = get_current_blog_id();
482 if ( get_current_blog_id() == $id )
483 return get_option( $option, $default );
485 switch_to_blog( $id );
486 $value = get_option( $option, $default );
487 restore_current_blog();
490 * Filter a blog option value.
492 * The dynamic portion of the hook name, `$option`, refers to the blog option name.
496 * @param string $value The option value.
497 * @param int $id Blog ID.
499 return apply_filters( "blog_option_{$option}", $value, $id );
503 * Add a new option for a given blog id.
505 * You do not need to serialize values. If the value needs to be serialized, then
506 * it will be serialized before it is inserted into the database. Remember,
507 * resources can not be serialized or added as an option.
509 * You can create options without values and then update the values later.
510 * Existing options will not be updated and checks are performed to ensure that you
511 * aren't adding a protected WordPress option. Care should be taken to not name
512 * options the same as the ones which are protected.
516 * @param int $id A blog ID. Can be null to refer to the current blog.
517 * @param string $option Name of option to add. Expected to not be SQL-escaped.
518 * @param mixed $value Optional. Option value, can be anything. Expected to not be SQL-escaped.
519 * @return bool False if option was not added and true if option was added.
521 function add_blog_option( $id, $option, $value ) {
525 $id = get_current_blog_id();
527 if ( get_current_blog_id() == $id )
528 return add_option( $option, $value );
530 switch_to_blog( $id );
531 $return = add_option( $option, $value );
532 restore_current_blog();
538 * Removes option by name for a given blog id. Prevents removal of protected WordPress options.
542 * @param int $id A blog ID. Can be null to refer to the current blog.
543 * @param string $option Name of option to remove. Expected to not be SQL-escaped.
544 * @return bool True, if option is successfully deleted. False on failure.
546 function delete_blog_option( $id, $option ) {
550 $id = get_current_blog_id();
552 if ( get_current_blog_id() == $id )
553 return delete_option( $option );
555 switch_to_blog( $id );
556 $return = delete_option( $option );
557 restore_current_blog();
563 * Update an option for a particular blog.
567 * @param int $id The blog id.
568 * @param string $option The option key.
569 * @param mixed $value The option value.
570 * @param mixed $deprecated Not used.
571 * @return bool True on success, false on failure.
573 function update_blog_option( $id, $option, $value, $deprecated = null ) {
576 if ( null !== $deprecated )
577 _deprecated_argument( __FUNCTION__, '3.1' );
579 if ( get_current_blog_id() == $id )
580 return update_option( $option, $value );
582 switch_to_blog( $id );
583 $return = update_option( $option, $value );
584 restore_current_blog();
586 refresh_blog_details( $id );
592 * Switch the current blog.
594 * This function is useful if you need to pull posts, or other information,
595 * from other blogs. You can switch back afterwards using restore_current_blog().
597 * Things that aren't switched:
598 * - autoloaded options. See #14992
599 * - plugins. See #14941
601 * @see restore_current_blog()
605 * @global int $blog_id
606 * @global array $_wp_switched_stack
607 * @global bool $switched
608 * @global string $table_prefix
609 * @global WP_Object_Cache $wp_object_cache
611 * @param int $new_blog The id of the blog you want to switch to. Default: current blog
612 * @param bool $deprecated Deprecated argument
613 * @return true Always returns True.
615 function switch_to_blog( $new_blog, $deprecated = null ) {
618 if ( empty( $new_blog ) )
619 $new_blog = $GLOBALS['blog_id'];
621 $GLOBALS['_wp_switched_stack'][] = $GLOBALS['blog_id'];
624 * If we're switching to the same blog id that we're on,
625 * set the right vars, do the associated actions, but skip
626 * the extra unnecessary work
628 if ( $new_blog == $GLOBALS['blog_id'] ) {
630 * Fires when the blog is switched.
634 * @param int $new_blog New blog ID.
635 * @param int $new_blog Blog ID.
637 do_action( 'switch_blog', $new_blog, $new_blog );
638 $GLOBALS['switched'] = true;
642 $wpdb->set_blog_id( $new_blog );
643 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
644 $prev_blog_id = $GLOBALS['blog_id'];
645 $GLOBALS['blog_id'] = $new_blog;
647 if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
648 wp_cache_switch_to_blog( $new_blog );
650 global $wp_object_cache;
652 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
653 $global_groups = $wp_object_cache->global_groups;
655 $global_groups = false;
659 if ( function_exists( 'wp_cache_add_global_groups' ) ) {
660 if ( is_array( $global_groups ) ) {
661 wp_cache_add_global_groups( $global_groups );
663 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', 'networks', 'sites' ) );
665 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
669 if ( did_action( 'init' ) ) {
670 wp_roles()->reinit();
671 $current_user = wp_get_current_user();
672 $current_user->for_blog( $new_blog );
675 /** This filter is documented in wp-includes/ms-blogs.php */
676 do_action( 'switch_blog', $new_blog, $prev_blog_id );
677 $GLOBALS['switched'] = true;
683 * Restore the current blog, after calling switch_to_blog()
685 * @see switch_to_blog()
689 * @global array $_wp_switched_stack
690 * @global int $blog_id
691 * @global bool $switched
692 * @global string $table_prefix
693 * @global WP_Object_Cache $wp_object_cache
695 * @return bool True on success, false if we're already on the current blog
697 function restore_current_blog() {
700 if ( empty( $GLOBALS['_wp_switched_stack'] ) )
703 $blog = array_pop( $GLOBALS['_wp_switched_stack'] );
705 if ( $GLOBALS['blog_id'] == $blog ) {
706 /** This filter is documented in wp-includes/ms-blogs.php */
707 do_action( 'switch_blog', $blog, $blog );
708 // If we still have items in the switched stack, consider ourselves still 'switched'
709 $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
713 $wpdb->set_blog_id( $blog );
714 $prev_blog_id = $GLOBALS['blog_id'];
715 $GLOBALS['blog_id'] = $blog;
716 $GLOBALS['table_prefix'] = $wpdb->get_blog_prefix();
718 if ( function_exists( 'wp_cache_switch_to_blog' ) ) {
719 wp_cache_switch_to_blog( $blog );
721 global $wp_object_cache;
723 if ( is_object( $wp_object_cache ) && isset( $wp_object_cache->global_groups ) )
724 $global_groups = $wp_object_cache->global_groups;
726 $global_groups = false;
730 if ( function_exists( 'wp_cache_add_global_groups' ) ) {
731 if ( is_array( $global_groups ) ) {
732 wp_cache_add_global_groups( $global_groups );
734 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', 'networks', 'sites' ) );
736 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );
740 if ( did_action( 'init' ) ) {
741 wp_roles()->reinit();
742 $current_user = wp_get_current_user();
743 $current_user->for_blog( $blog );
746 /** This filter is documented in wp-includes/ms-blogs.php */
747 do_action( 'switch_blog', $blog, $prev_blog_id );
749 // If we still have items in the switched stack, consider ourselves still 'switched'
750 $GLOBALS['switched'] = ! empty( $GLOBALS['_wp_switched_stack'] );
756 * Determines if switch_to_blog() is in effect
760 * @global array $_wp_switched_stack
762 * @return bool True if switched, false otherwise.
764 function ms_is_switched() {
765 return ! empty( $GLOBALS['_wp_switched_stack'] );
769 * Check if a particular blog is archived.
773 * @param int $id The blog id
774 * @return string Whether the blog is archived or not
776 function is_archived( $id ) {
777 return get_blog_status($id, 'archived');
781 * Update the 'archived' status of a particular blog.
785 * @param int $id The blog id
786 * @param string $archived The new status
787 * @return string $archived
789 function update_archived( $id, $archived ) {
790 update_blog_status($id, 'archived', $archived);
795 * Update a blog details field.
799 * @global wpdb $wpdb WordPress database abstraction object.
801 * @param int $blog_id BLog ID
802 * @param string $pref A field name
803 * @param string $value Value for $pref
804 * @param null $deprecated
805 * @return string|false $value
807 function update_blog_status( $blog_id, $pref, $value, $deprecated = null ) {
810 if ( null !== $deprecated )
811 _deprecated_argument( __FUNCTION__, '3.1' );
813 if ( ! in_array( $pref, array( 'site_id', 'domain', 'path', 'registered', 'last_updated', 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id') ) )
816 $result = $wpdb->update( $wpdb->blogs, array($pref => $value, 'last_updated' => current_time('mysql', true)), array('blog_id' => $blog_id) );
818 if ( false === $result )
821 refresh_blog_details( $blog_id );
823 if ( 'spam' == $pref ) {
825 /** This filter is documented in wp-includes/ms-blogs.php */
826 do_action( 'make_spam_blog', $blog_id );
828 /** This filter is documented in wp-includes/ms-blogs.php */
829 do_action( 'make_ham_blog', $blog_id );
831 } elseif ( 'mature' == $pref ) {
833 /** This filter is documented in wp-includes/ms-blogs.php */
834 do_action( 'mature_blog', $blog_id );
836 /** This filter is documented in wp-includes/ms-blogs.php */
837 do_action( 'unmature_blog', $blog_id );
839 } elseif ( 'archived' == $pref ) {
841 /** This filter is documented in wp-includes/ms-blogs.php */
842 do_action( 'archive_blog', $blog_id );
844 /** This filter is documented in wp-includes/ms-blogs.php */
845 do_action( 'unarchive_blog', $blog_id );
847 } elseif ( 'deleted' == $pref ) {
849 /** This filter is documented in wp-includes/ms-blogs.php */
850 do_action( 'make_delete_blog', $blog_id );
852 /** This filter is documented in wp-includes/ms-blogs.php */
853 do_action( 'make_undelete_blog', $blog_id );
855 } elseif ( 'public' == $pref ) {
857 * Fires after the current blog's 'public' setting is updated.
861 * @param int $blog_id Blog ID.
862 * @param string $value The value of blog status.
864 do_action( 'update_blog_public', $blog_id, $value ); // Moved here from update_blog_public().
871 * Get a blog details field.
875 * @global wpdb $wpdb WordPress database abstraction object.
877 * @param int $id The blog id
878 * @param string $pref A field name
879 * @return bool|string|null $value
881 function get_blog_status( $id, $pref ) {
884 $details = get_blog_details( $id, false );
886 return $details->$pref;
888 return $wpdb->get_var( $wpdb->prepare("SELECT %s FROM {$wpdb->blogs} WHERE blog_id = %d", $pref, $id) );
892 * Get a list of most recently updated blogs.
896 * @global wpdb $wpdb WordPress database abstraction object.
898 * @param mixed $deprecated Not used
899 * @param int $start The offset
900 * @param int $quantity The maximum number of blogs to retrieve. Default is 40.
901 * @return array The list of blogs
903 function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) {
906 if ( ! empty( $deprecated ) )
907 _deprecated_argument( __FUNCTION__, 'MU' ); // never used
909 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 );
913 * Handler for updating the blog date when a post is published or an already published post is changed.
917 * @param string $new_status The new post status
918 * @param string $old_status The old post status
919 * @param object $post Post object
921 function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) {
922 $post_type_obj = get_post_type_object( $post->post_type );
923 if ( ! $post_type_obj || ! $post_type_obj->public ) {
927 if ( 'publish' != $new_status && 'publish' != $old_status ) {
931 // Post was freshly published, published post was saved, or published post was unpublished.
933 wpmu_update_blogs_date();
937 * Handler for updating the blog date when a published post is deleted.
941 * @param int $post_id Post ID
943 function _update_blog_date_on_post_delete( $post_id ) {
944 $post = get_post( $post_id );
946 $post_type_obj = get_post_type_object( $post->post_type );
947 if ( ! $post_type_obj || ! $post_type_obj->public ) {
951 if ( 'publish' != $post->post_status ) {
955 wpmu_update_blogs_date();
959 * Handler for updating the blog posts count date when a post is deleted.
963 * @param int $post_id Post ID.
965 function _update_posts_count_on_delete( $post_id ) {
966 $post = get_post( $post_id );
968 if ( ! $post || 'publish' !== $post->post_status ) {
972 update_posts_count();
976 * Handler for updating the blog posts count date when a post status changes.
980 * @param string $new_status The status the post is changing to.
981 * @param string $old_status The status the post is changing from.
983 function _update_posts_count_on_transition_post_status( $new_status, $old_status ) {
984 if ( $new_status === $old_status ) {
988 if ( 'publish' !== $new_status && 'publish' !== $old_status ) {
992 update_posts_count();