summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-07-24 21:12:09 +0000
committerdonncha <donncha@7be80a69-a1ef-0310-a953-fb0f7c49ff36>2007-07-24 21:12:09 +0000
commitf7904d143986a96e6f209b51b380ad1ee640cad5 (patch)
tree0e3b7618ca29e24237e97fa9af7841610ecc11bc
parentde0c3c288449a4d4418c3fcc6cde45a5af3e0d3f (diff)
downloadwordpress-mu-f7904d143986a96e6f209b51b380ad1ee640cad5.tar.gz
wordpress-mu-f7904d143986a96e6f209b51b380ad1ee640cad5.tar.xz
wordpress-mu-f7904d143986a96e6f209b51b380ad1ee640cad5.zip
Misc Updates, added "get_most_recent_post_of_user()"
git-svn-id: http://svn.automattic.com/wordpress-mu/trunk@1012 7be80a69-a1ef-0310-a953-fb0f7c49ff36
-rw-r--r--wp-includes/wpmu-functions.php67
1 files changed, 52 insertions, 15 deletions
diff --git a/wp-includes/wpmu-functions.php b/wp-includes/wpmu-functions.php
index dcbe43d..fd7c016 100644
--- a/wp-includes/wpmu-functions.php
+++ b/wp-includes/wpmu-functions.php
@@ -170,13 +170,21 @@ function get_blog_details( $id, $all = true ) {
$details = wp_cache_get( $id, 'blog-details' );
- if ( $details )
- return unserialize( $details );
+ if ( $details ) {
+ if ( $details == -1 )
+ return false;
+ elseif ( !is_object($details) ) // Clear old pre-serialized objects. Cache clients do better with that.
+ wp_cache_delete( $id, 'blog-details' );
+ else
+ return $details;
+ }
$details = $wpdb->get_row( "SELECT * FROM $wpdb->blogs WHERE blog_id = '$id' /* get_blog_details */" );
- if ( !$details )
+ if ( !$details ) {
+ wp_cache_set( $id, -1, 'blog-details' );
return false;
+ }
if( $all == true ) {
$wpdb->hide_errors();
@@ -287,7 +295,7 @@ function update_site_option( $key, $value ) {
$value = serialize($value);
$value = $wpdb->escape( $value );
- if ( get_site_option( $key, false, false ) == false )
+ if ( get_site_option( $key, false, false ) === false )
add_site_option( $key, $value );
$wpdb->query( "UPDATE $wpdb->sitemeta SET meta_value = '".$wpdb->escape( $value )."' WHERE site_id='{$wpdb->siteid}' AND meta_key = '$key'" );
@@ -374,9 +382,6 @@ function switch_to_blog( $new_blog ) {
$switched_stack[] = $blog_id;
- if ( $new_blog == $blog_id )
- return;
-
// backup
$tmpoldblogdetails[ 'blogid' ] = $wpdb->blogid;
$tmpoldblogdetails[ 'posts' ] = $wpdb->posts;
@@ -483,6 +488,7 @@ function get_blogs_of_user( $id, $all = false ) {
$blogs[$match[1]]->domain = $blog->domain;
$blogs[$match[1]]->path = $blog->path;
$blogs[$match[1]]->site_id = $blog->site_id;
+ $blogs[$match[1]]->siteurl = $blog->siteurl;
}
}
}
@@ -703,14 +709,6 @@ function add_user_to_blog( $blog_id, $user_id, $role ) {
update_usermeta($user_id, 'source_domain', $details->domain);
}
- if ( empty($user->user_url) ) {
- $userdata = array();
- $userdata['ID'] = $user->id;
- $userdata['user_url'] = get_blogaddress_by_id($blog_id);
- $userdata['user_login'] = $user->user_login;
- wp_update_user($userdata);
- }
-
$user->set_role($role);
do_action('add_user_to_blog', $user_id, $role, $blog_id);
@@ -1147,6 +1145,7 @@ function wpmu_activate_signup($key) {
$meta = unserialize($signup->meta);
$user_login = $wpdb->escape($signup->user_login);
$user_email = $wpdb->escape($signup->user_email);
+ wpmu_validate_user_signup($user_login, $user_email);
$password = generate_random_password();
$user_id = username_exists($user_login);
@@ -1171,6 +1170,7 @@ function wpmu_activate_signup($key) {
return array('user_id' => $user_id, 'password' => $password, 'meta' => $meta);
}
+ wpmu_validate_blog_signup($signup->domain, $signup->title);
$blog_id = wpmu_create_blog($signup->domain, $signup->path, $signup->title, $user_id, $meta);
// TODO: What to do if we create a user but cannot create a blog?
@@ -1467,4 +1467,41 @@ function get_user_id_from_string( $string ) {
return $user_id;
}
+function get_most_recent_post_of_user( $user_id ) {
+ global $wpdb, $wpmuBaseTablePrefix;
+
+ $user_id = (int) $user_id;
+
+ $user_blogs = get_blogs_of_user($user_id);
+ $most_recent_post = array();
+
+ // Walk through each blog and get the most recent post
+ // published by $user_id
+ foreach ( $user_blogs as $blog ) {
+ $recent_post = $wpdb->get_row("SELECT ID, post_date_gmt FROM {$wpmuBaseTablePrefix}{$blog->userblog_id}_posts WHERE post_author = '{$user_id}' AND post_type = 'post' AND post_status = 'publish' ORDER BY post_date_gmt DESC LIMIT 1", ARRAY_A);
+
+ // Make sure we found a post
+ if ( isset($recent_post['ID']) ) {
+ $post_gmt_ts = strtotime($recent_post['post_date_gmt']);
+
+ // If this is the first post checked or if this post is
+ // newer than the current recent post, make it the new
+ // most recent post.
+ if (
+ !isset($most_recent_post['post_gmt_ts'])
+ || ($post_gmt_ts > $most_recent_post['post_gmt_ts'])
+ ) {
+ $most_recent_post = array(
+ 'blog_id' => $blog->userblog_id,
+ 'post_id' => $recent_post['ID'],
+ 'post_date_gmt' => $recent_post['post_date_gmt'],
+ 'post_gmt_ts' => $post_gmt_ts
+ );
+ }
+ }
+ }
+
+ return $most_recent_post;
+}
+
?>