• Had an issue where the broadcast post meta box isn’t showing on the main blog of our WPMU but is on the others. I’m logged in as super admin.

    I took a look and the create_meta_box() method in ThreeWP_Broadcast.php calls $this->role_at_least( 'author' ) which is returning false.

    The role_at_least() method in ThreeWP_Broadcast_Base.php gets all the way to the bottom then fails on isset( $current_user->allcaps[ $role_cap ] ) which returns false – remember that I’m logged in as super admin.

    The method only calls is_super_user() (which returns true btw) if the role passed is ‘super_admin’. IMO this should be called if the function exists regardless of the role passed. Here is my updated version of the method:

    public function role_at_least($role)
    {
    	global $current_user;
    	wp_get_current_user();
    
    	if ( $current_user === null )
    	    return false;
    
    	if ($role == '')
    		return true;
    
    	if ( function_exists('is_super_admin') && is_super_admin() )
    		return true;
    
    	if ($role == 'super_admin')
    		return false;
    
    	// This was previously done by current_user_can, but for some reason it doesn't work all the time in WP3.5.
    	// So now I have to check "manually", which probably means that filters are rendered ineffective.
    	$role_cap = $this->roles[$role]['current_user_can'];
    
    	return isset( $current_user->allcaps[ $role_cap ] ) && $current_user->allcaps[ $role_cap ] == true;
    }

    https://www.ads-software.com/extend/plugins/threewp-broadcast/

Viewing 3 replies - 1 through 3 (of 3 total)
  • edward mindreantre

    (@edward-mindreantre)

    Fixed.

    Thread Starter flynsarmy

    (@flynsarmy)

    Indeed this has been fixed but the changes you made can result in is_super_admin() being called twice.

    if (function_exists('is_super_admin') && is_super_admin() )
    	return true;
    
    if ( $role == 'super_admin' )
    	if (function_exists('is_super_admin'))
    		return is_super_admin();
    	else
    		return false;

    As you can see here (your latest changes) if the is_super_admin() method exists you’ll already have checked if the user is a super admin. You dont’ need to recheck below.

    It should look like this:

    if (function_exists('is_super_admin') && is_super_admin() )
    	return true;
    
    if ( $role == 'super_admin' )
    	return false;

    edward mindreantre

    (@edward-mindreantre)

    Since your solution is smarter than mine, I’ll use yours. ??

    Will be available in next version.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘role_at_least() false for super admin’ is closed to new replies.