Skip to:
Content

BuddyPress.org

Changeset 528


Ignore:
Timestamp:
11/10/2008 01:53:30 PM (18 years ago)
Author:
apeatling
Message:

Added functions to allow BuddyPress to detect existing blogs and register them in the BuddyPress tables. BuddyPress will now list blogs for users created before BuddyPress was installed.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r518 r528  
    6969        $wpdb->query( $wpdb->prepare( "ALTER TABLE " . $bp['blogs']['table_name_blog_posts'] . " DEFAULT CHARACTER SET %s", $wpdb->charset ) );
    7070        $wpdb->query( $wpdb->prepare( "ALTER TABLE " . $bp['blogs']['table_name_blog_comments'] . " DEFAULT CHARACTER SET %s", $wpdb->charset ) );
     71       
     72        // On first installation - record all existing blogs in the system.
     73        if ( !(int)get_site_option( 'bp-blogs-first-install') ) {
     74                bp_blogs_record_existing_blogs();
     75                add_site_option( 'bp-blogs-first-install', 1 );
     76        }
    7177       
    7278        add_site_option( 'bp-blogs-version', $version );
    … …  
    248254}
    249255
     256function bp_blogs_record_existing_blogs() {
     257        global $wpdb;
     258
     259        $blog_ids = $wpdb->get_col( $wpdb->prepare( "SELECT blog_id FROM {$wpdb->base_prefix}blogs WHERE public = 1 AND mature = 0 AND spam = 0 AND deleted = 0" ) );
     260       
     261        if ( $blog_ids ) {
     262                foreach( $blog_ids as $blog_id ) {
     263                        $users = get_users_of_blog( $blog_id );
     264
     265                        if ( $users ) {
     266                                foreach ( $users as $user ) {
     267                                        $role = unserialize( $user->meta_value );
     268
     269                                        if ( !isset( $role['subscriber'] ) )
     270                                                bp_blogs_record_blog( $blog_id, $user->user_id );
     271                                }
     272                        }
     273                }
     274        }
     275}
     276
    250277
    251278function bp_blogs_record_blog( $blog_id, $user_id ) {
  • trunk/bp-blogs/bp-blogs-classes.php

    r511 r528  
    3030                global $wpdb, $bp;
    3131               
    32                 if ( !$this->user_id )
     32                // Don't try and save if there is no user ID or blog ID set.
     33                if ( !$this->user_id || !$this->blog_id )
    3334                        return false;
    3435                       
     36                // Don't save if this blog has already been recorded for the user.
     37                if ( !$this->id && $this->exists() )
     38                        return false;
     39               
    3540                if ( $this->id ) {
    3641                        // Update
    … …  
    4853                else
    4954                        return $wpdb->insert_id;
     55        }
     56       
     57        function exists() {
     58                global $bp, $wpdb;
     59               
     60                return $wpdb->get_var( $wpdb->prepare( "SELECT count(id) FROM " . $bp['blogs']['table_name'] . " WHERE user_id = %d AND blog_id = %d", $this->user_id, $this->blog_id ) );
    5061        }
    5162       
Note: See TracChangeset for help on using the changeset viewer.