Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
07/11/2014 09:25:08 PM (12 years ago)
Author:
johnjamesjacoby
Message:

More clean up in bp_blogs_record_existing_blogs():

  • Do not touch the $bp global directly.
  • Remove user/subscriber intersection and use bp_blogs_add_user_to_blog() instead of bp_blogs_record_blog(). This reduces complexity and leans on a function purpose-built for doing this comparison rather than duplicating part of that logic.

See #5749.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-blogs/bp-blogs-functions.php

    r8598 r8599  
    7474 * Populate the BP blogs table with existing blogs.
    7575 *
    76  * @global object $bp BuddyPress global settings
     76 * @since BuddyPress (1.0.0)
     77 *
    7778 * @global object $wpdb WordPress database object
    7879 * @uses get_users()
     
    8081 */
    8182function bp_blogs_record_existing_blogs() {
    82         global $bp, $wpdb;
     83        global $wpdb;
    8384
    8485        // Query for all sites in network
     
    109110        }
    110111
     112        // Get BuddyPress
     113        $bp = buddypress();
     114
    111115        // Truncate user blogs table
    112116        $truncate = $wpdb->query( "TRUNCATE {$bp->blogs->table_name}" );
     
    128132
    129133                // Get all users
    130                 $all_users = get_users( array(
    131                         'blog_id' => $blog_id,
    132                         'fields'  => 'ID'
     134                $users = get_users( array(
     135                        'blog_id' => $blog_id
    133136                ) );
    134                
    135                 // Get subscribers
    136                 $subscribers = get_users( array(
    137                         'blog_id' => $blog_id,
    138                         'fields'  => 'ID',
    139                         'role'    => 'subscriber'
    140                 ) );
    141 
    142                 // Remove subscribers from users (for some legacy/wpcom reason?)
    143                 $users = array_values( array_diff( $all_users, $subscribers ) );
    144 
    145                 // Reclaim some memory in the event there are many users
    146                 unset( $all_users, $subscribers );
    147137
    148138                // Continue on if no users exist for this site (how did this happen?)
     
    153143                // Loop through users and record their relationship to this blog
    154144                foreach ( (array) $users as $user ) {
    155                         bp_blogs_record_blog( $blog_id, $user, true );
     145                        bp_blogs_add_user_to_blog( $user->ID, false, $blog_id );
    156146                }
    157147        }
Note: See TracChangeset for help on using the changeset viewer.