BuddyPress Groupblog
[resolved] user role promotion don't affect user role in blog (7 posts)

  1. Project23
    Posted 3 years ago #

    When i promote a user to Admin/Moderator of the group(-blog)...
    the user role on the associated blog does'nt change.

    the roles in the group works as suspected
    and the user is correctly added to the blog...

    it's just about changing the users role in the blog by promotion/demotion.

    Has it something to do with the "bp_groupblog_upgrade_user"-hook?
    or where/how can i add/change this to work correctly?

    Am i the onlyone having this problem?

    PS: I'm running a buddypress+bbpress+WPMU connection with subdomains-option activated

    any informations are welcome - sorry for bad english

    THX - P23


  2. Project23
    Posted 3 years ago #

    changed some things in 'bp-groupblog.php':

    bp_groupblog_get_user_role() always returned 'norole'
    so i removed the globalisation of $blog_id, because it overwrites the $blog_id given as functions argument.

    => bp_groupblog_get_user_role() now returns the right value.

    then... i also changed the bp_groupblog_upgrade_user() function.
    i removed the TRUE-Path of the first if statement, only leaving the FALSE-Path so it delivers always the LIVE group-role AFTER the promote/demote
    ($bp only delivers the role before the promotion/demotion is done)

    so this is what is left of my bp_groupblog_get_user_role() function:

    function bp_groupblog_upgrade_user( $user_id, $group_id, $blog_id = false ) {
    	global $bp;
    	if ( !$blog_id )
    		$blog_id = groups_get_groupmeta ( $group_id, 'groupblog_blog_id' );
    	// If the group has no blog linked, get the heck out of here!
    	if ( !$blog_id )
    	// Set up some variables
    	$groupblog_silent_add 	       = groups_get_groupmeta ( $group_id, 'groupblog_silent_add' );
    	$groupblog_default_member_role = groups_get_groupmeta ( $group_id, 'groupblog_default_member_role' );
    	$groupblog_default_mod_role    = groups_get_groupmeta ( $group_id, 'groupblog_default_mod_role' );
    	$groupblog_default_admin_role  = groups_get_groupmeta ( $group_id, 'groupblog_default_admin_role' );
    	$groupblog_creator_role        = 'admin';
    	$user = new WP_User( $user_id );
    	$user_role = bp_groupblog_get_user_role( $user_id, $user->data->user_login, $blog_id );
    	// Get the current user's group status.
        if ( groups_is_user_admin ( $user_id, $group_id ) ) {
            $user_group_status = 'admin';
        } else if ( groups_is_user_mod ( $user_id, $group_id ) ) {
            $user_group_status = 'mod';
        } else if ( groups_is_user_member ( $user_id, $group_id ) ) {
            $user_group_status = 'member';
        } else {
            return false;
    	switch ( $user_group_status ) {
    		case 'admin' :
    			$default_role = $groupblog_default_admin_role;
    		case 'mod' :
    			$default_role = $groupblog_default_mod_role;
    		case 'member' :
    		default :
    			$default_role = $groupblog_default_member_role;
    	if ( $user_role == $default_role && $groupblog_silent_add == true ) {
    		return false;
    	if ( !$groupblog_silent_add ) {
    		$default_role = 'subscriber';
    	add_user_to_blog( $blog_id, $user_id, $default_role );
    	do_action( 'bp_groupblog_upgrade_user', $user_id, $user_role, $default_role );
  3. Project23
    Posted 3 years ago #

    so this is what is left of my bp_groupblog_get_user_role() function:

    my fault... as you see in the code-section, the secound part is about the bp_groupblog_upgrade_user() function.

  4. Boone Gorges
    Plugin Author

    Posted 3 years ago #

    Project23 - Thanks very much for doing this research. I've opened a ticket so that I don't lose track of this: https://github.com/boonebgorges/bp-groupblog/issues/13

  5. Christian Wach
    Posted 3 years ago #

    Project23 - thanks, your amends to bp_groupblog_upgrade_user() work perfectly.

    BTW, you'll find if you use a non-default $table_prefix in wp-config.php that removing the reference to the global in bp_groupblog_get_user_role() is not quite enough. See my fix on Github.

  6. Boone Gorges
    Plugin Author

    Posted 3 years ago #

    needle - Awesome, that fix should definitely go in too.

  7. warmthesoup
    Posted 3 years ago #

    This is a very helpful improvement. Thank you.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • BuddyPress Groupblog
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic