X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f9001779751f83dc8a10e478bfecb4d8dd5f964c..refs/tags/wordpress-3.4:/wp-includes/ms-blogs.php diff --git a/wp-includes/ms-blogs.php b/wp-includes/ms-blogs.php index 0deca99a..8f66aadd 100644 --- a/wp-includes/ms-blogs.php +++ b/wp-includes/ms-blogs.php @@ -16,10 +16,7 @@ function wpmu_update_blogs_date() { global $wpdb; - // TODO: use update_blog_details - - $wpdb->update( $wpdb->blogs, array('last_updated' => current_time('mysql', true)), array('blog_id' => $wpdb->blogid) ); - refresh_blog_details( $wpdb->blogid ); + update_blog_details( $wpdb->blogid, array('last_updated' => current_time('mysql', true)) ); do_action( 'wpmu_blog_updated', $wpdb->blogid ); } @@ -71,7 +68,7 @@ function get_blogaddress_by_name( $blogname ) { */ function get_blogaddress_by_domain( $domain, $path ) { if ( is_subdomain_install() ) { - $url = "http://".$domain.$path; + $url = "http://" . $domain.$path; } else { if ( $domain != $_SERVER['HTTP_HOST'] ) { $blogname = substr( $domain, 0, strpos( $domain, '.' ) ); @@ -96,7 +93,7 @@ function get_blogaddress_by_domain( $domain, $path ) { */ function get_id_from_blogname( $name ) { global $wpdb, $current_site; - $blog_id = wp_cache_get( "get_id_from_blogname_" . $name, 'blog-details' ); + $blog_id = wp_cache_get( 'get_id_from_blogname_' . $name, 'blog-details' ); if ( $blog_id ) return $blog_id; @@ -255,6 +252,8 @@ function refresh_blog_details( $blog_id ) { wp_cache_delete( md5( $details->domain . $details->path ) , 'blog-lookup' ); wp_cache_delete( 'current_blog_' . $details->domain, 'site-options' ); wp_cache_delete( 'current_blog_' . $details->domain . $details->path, 'site-options' ); + + do_action( 'refresh_blog_details', $blog_id ); } /** @@ -323,7 +322,7 @@ function update_blog_details( $blog_id, $details = array() ) { * @since MU * @uses apply_filters() Calls 'blog_option_$optionname' with the option name value. * - * @param int $blog_id is the id of the blog. + * @param int $blog_id Optional. Blog ID, can be null to refer to the current blog. * @param string $setting Name of option to retrieve. Should already be SQL-escaped. * @param string $default (optional) Default value returned if option not found. * @return mixed Value set for the option. @@ -331,8 +330,11 @@ function update_blog_details( $blog_id, $details = array() ) { function get_blog_option( $blog_id, $setting, $default = false ) { global $wpdb; - $key = $blog_id."-".$setting."-blog_option"; - $value = wp_cache_get( $key, "site-options" ); + if ( null === $blog_id ) + $blog_id = $wpdb->blogid; + + $key = $blog_id . '-' . $setting . '-blog_option'; + $value = wp_cache_get( $key, 'site-options' ); if ( $value == null ) { if ( $blog_id == $wpdb->blogid ) { $value = get_option( $setting, $default ); @@ -383,14 +385,17 @@ function get_blog_option( $blog_id, $setting, $default = false ) { * @param int $id The blog id * @param string $key The option key * @param mixed $value The option value + * @return bool True on success, false on failure. */ function add_blog_option( $id, $key, $value ) { $id = (int) $id; switch_to_blog($id); - add_option( $key, $value ); + $return = add_option( $key, $value ); restore_current_blog(); - wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options' ); + if ( $return ) + wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options' ); + return $return; } /** @@ -400,14 +405,17 @@ function add_blog_option( $id, $key, $value ) { * * @param int $id The blog id * @param string $key The option key + * @return bool True on success, false on failure. */ function delete_blog_option( $id, $key ) { $id = (int) $id; switch_to_blog($id); - delete_option( $key ); + $return = delete_option( $key ); restore_current_blog(); - wp_cache_set( $id."-".$key."-blog_option", '', 'site-options' ); + if ( $return ) + wp_cache_set( $id . '-' . $key . '-blog_option', '', 'site-options' ); + return $return; } /** @@ -418,6 +426,7 @@ function delete_blog_option( $id, $key ) { * @param int $id The blog id * @param string $key The option key * @param mixed $value The option value + * @return bool True on success, false on failrue. */ function update_blog_option( $id, $key, $value, $deprecated = null ) { $id = (int) $id; @@ -426,12 +435,14 @@ function update_blog_option( $id, $key, $value, $deprecated = null ) { _deprecated_argument( __FUNCTION__, '3.1' ); switch_to_blog($id); - update_option( $key, $value ); + $return = update_option( $key, $value ); restore_current_blog(); refresh_blog_details( $id ); - wp_cache_set( $id."-".$key."-blog_option", $value, 'site-options'); + if ( $return ) + wp_cache_set( $id . '-' . $key . '-blog_option', $value, 'site-options'); + return $return; } /** @@ -678,4 +689,45 @@ function get_last_updated( $deprecated = '', $start = 0, $quantity = 40 ) { 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 ); } -?> +/** + * Handler for updating the blog date when a post is published or an already published post is changed. + * + * @since 3.3.0 + * + * @param string $new_status The new post status + * @param string $old_status The old post status + * @param object $post Post object + */ +function _update_blog_date_on_post_publish( $new_status, $old_status, $post ) { + $post_type_obj = get_post_type_object( $post->post_type ); + if ( ! $post_type_obj->public ) + return; + + if ( 'publish' != $new_status && 'publish' != $old_status ) + return; + + // Post was freshly published, published post was saved, or published post was unpublished. + + wpmu_update_blogs_date(); +} + +/** + * Handler for updating the blog date when a published post is deleted. + * + * @since 3.4.0 + * + * @param int $post_id Post ID + */ +function _update_blog_date_on_post_delete( $post_id ) { + $post = get_post( $post_id ); + + $post_type_obj = get_post_type_object( $post->post_type ); + if ( ! $post_type_obj->public ) + return; + + if ( 'publish' != $post->post_status ) + return; + + wpmu_update_blogs_date(); +} +