Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] BP multisite shared users but segregated groups, activity, forums

  • Avatar of juanlopez4691
    juanlopez4691
    Member

    @juanlopez4691

    I have this project to create a multi-site buddypress network.

    Users table should be shared and common to all sites in the network (same user profile for all sites in the network) but each site should have its own activity flow, groups and forums.

    Any ideas? Suggestions?

Viewing 10 replies - 1 through 10 (of 10 total)
  • Avatar of Paul Gibbs
    Paul Gibbs
    Keymaster

    @djpaul

    Only way is to set up a multi-network WordPress site (not multi-site). Google, and/or look at http://wpmututorials.com/news/new-features/multiple-buddypress-social-networks/ for more information.

    It’s still pretty new, so mightn’t be bullet proof.

    Avatar of @mercime
    @mercime
    Keymaster

    @mercime

    Avatar of juanlopez4691
    juanlopez4691
    Member

    @juanlopez4691

    Thank you very much for your suggestions. I will explore both solutions and try to decide wich one suits me best.

    Avatar of ultimateuser
    ultimateuser
    Participant

    @ultimateuser

    @juanlopez4691 @mercime

    I am using the plugin http://buddydev.com/plugins/buddypress-multi-network/ together with BP 1.6 (trunk). Would you know how to share user across the different networks (shared user table) but have separate groups, forums etc?

    Avatar of juanlopez4691
    juanlopez4691
    Member

    @juanlopez4691

    I finally made up a solution adding some meta fields (blog_id, blog_path, blog_name) to groups on creation:

    `function bp_group_meta_save ( $group_id ) {
    $blog = get_blog_details( get_current_blog_id(), true );

    $fields = array(
    ‘blog_id’ => $blog->blog_id,
    ‘blog_path’ => $blog->path,
    ‘blog_name’ => $blog->blogname
    );

    foreach ( $fields as $field => $value ) {
    groups_update_groupmeta( $group_id, $field, $value );
    }
    }
    add_action( ‘groups_created_group’, ‘bp_group_meta_save’ )`

    When showing the list of groups for the current blog, I build a list with the groups with the blog_id value that matches the blog:

    `function get_groups_by_meta ( $field, $meta_key, $meta_value ) {
    global $wpdb;

    if ( is_string( $meta_value) ) $meta_value = “‘” . $meta_value . “‘”;

    $sql = $wpdb->prepare( “SELECT $field from {$wpdb->base_prefix}bp_groups_groupmeta WHERE meta_key=’$meta_key’ AND meta_value=$meta_value”, OBJECT );
    $res = $wpdb->get_results( $sql );

    return $res;
    }

    function get_groups_by_blogid ( $blog_id = 1 ) {
    $list = get_groups_by_meta( ‘group_id’, ‘blog_id’, $blog_id );

    if ( count( $list ) ) {
    $res = ”;
    foreach ( $list as $item ) {
    $res .= $item->group_id . ‘,’;
    }
    return substr( $res, 0, -1);
    } else {
    return FALSE;
    }
    }`

    And finally, in the groups-loop.php template:

    `$current_blogid = get_current_blog_id();
    if ( $current_blogid > 1) {
    $groups_set = get_groups_by_blogid( $current_blogid );
    ( $groups_set !== FALSE ) ? $extra_args = ‘&include=’ . $groups_set : $extra_args = ‘&include=-1′;
    }

    if ( bp_has_groups( bp_ajax_querystring( ‘groups’ ) . $extra_args ) ) : ?>`

    In my wp-config.php, I have defined BP_ENABLE_MULTIBLOG as true, and also a common place to upload user avatars:

    `//Buddypress multi-sitio
    define( ‘BP_ENABLE_MULTIBLOG’, true );

    //Avatares de usuario comunes a toda la red multisitio
    define( ‘BP_AVATAR_URL’, “http://mainblog/wp-content/uploads” );
    define( ‘BP_AVATAR_UPLOAD_PATH’, ‘F:/xampp/www/mainblog/wp-content/uploads’ );`

    I don’t know if this is a overly complicated solution. I suspect Buddypess 1.6 can deal with this situation (segregated groups, activity, forums but common user base) in a far more simple way, but I have no idea how.

    Any clues?

    Avatar of rickkumar
    rickkumar
    Participant

    @rickkumar

    @ juanlopez4691

    Have you found any other solution or plugin dealing with this issue?

    Can you share your network or websites’ url?

    I am also looking for similar answers?

    Thanks.

    Avatar of zacclay
    zacclay
    Participant

    @zacclay

    I would also like to do something like this and I am wondering if there’s an easier way to do it.

    Avatar of sapna1809
    sapna1809
    Participant

    @sapna1809

    i did it one time but when i update buddypress and other plugins and wordpress then it is not working.
    I try again all which i did but not working.

    please help me.

    Avatar of takinglife2themax
    takinglife2themax
    Participant

    @takinglife2themax

    Hey guys,
    I just wanted to post an update to this.

    @juanlopez4691 You’re a genius, the code still works! I’m running BuddyPress 1.9.1 now and it’s working smoothly. I think that you had some minor errors in your syntax though. Here’s the updated version:

    bp-custom

    // Add meta fields upon group creation
    function bp_group_meta_save ( $group_id ) {
    	$blog = get_blog_details( get_current_blog_id(), true );
    	
    	$fields = array(
    	'blog_id' => $blog->blog_id,
    	'blog_path' => $blog->path,
    	'blog_name' => $blog->blogname
    	);
    	
    	foreach ( $fields as $field => $value ) {
    	groups_update_groupmeta( $group_id, $field, $value );
    	}
    }
    add_action( 'groups_created_group', 'bp_group_meta_save' );
    
    function get_groups_by_meta ( $field, $meta_key, $meta_value ) {
    	global $wpdb;
    	
    	if ( is_string( $meta_value) ) $meta_value = "'" . $meta_value . "'";
    	
    	$sql = $wpdb->prepare( "SELECT $field from {$wpdb->base_prefix}bp_groups_groupmeta WHERE meta_key='$meta_key' AND meta_value=$meta_value", OBJECT );
    	$res = $wpdb->get_results( $sql );
    	
    	return $res;
    }
    
    // Build a list of groups with the matching blog_id value
    function get_groups_by_blogid ( $blog_id = 1 ) {
    	$list = get_groups_by_meta( 'group_id', 'blog_id', $blog_id );
    	
    	if ( count( $list ) ) {
    	$res = "";
    	foreach ( $list as $item ) {
    	$res .= $item->group_id . ',';
    	}
    	return substr( $res, 0, -1);
    	} else {
    	return FALSE;
    	}
    }

    groups-loop

    <?php 
    $current_blogid = get_current_blog_id();
    
    if ( $current_blogid > 1) {
    $groups_set = get_groups_by_blogid( $current_blogid );
    ( $groups_set !== FALSE ) ? $extra_args = '&include=' . $groups_set : $extra_args = '&include=-1';
    }
    
    if ( bp_has_groups( bp_ajax_querystring( 'groups' ) . $extra_args ) ) : ?>
    Avatar of strangerstudios
    strangerstudios
    Participant

    @strangerstudios

    Hi, guys. Thanks for the thoughts and code around this idea. We are doing something similar for our setup at SchoolPress.me and I used some of the code here, tweaked it, and started a GitHub repo for the plugin.

    https://github.com/strangerstudios/bp-site-groups

    Instead of editing the loop in a template, I’m using the groups_get_groups filter to filter out non-site groups. I also have a couple checks in case people navigate directly to a non-site group in the frontend or dashboard.

    If you have any suggestions, please open an issue at GitHub. Thanks.

    As this firms up, I will probably move it into the WordPress.org repo.

Viewing 10 replies - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.