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 );
}
*/
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, '.' ) );
*/
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;
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 );
}
/**
* @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.
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 );
* @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;
}
/**
*
* @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;
}
/**
* @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;
_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;
}
/**
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();
+}
+