WordPress.org

Ready to get started?Download WordPress

Forums

ThreeWP Broadcast
role_at_least() false for super admin (4 posts)

  1. flynsarmy
    Member
    Posted 1 year ago #

    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;
    }

    http://wordpress.org/extend/plugins/threewp-broadcast/

  2. edward mindreantre
    Member
    Posted 1 year ago #

    Fixed.

  3. flynsarmy
    Member
    Posted 1 year ago #

    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;
  4. edward mindreantre
    Member
    Posted 1 year ago #

    Since your solution is smarter than mine, I'll use yours. :)

    Will be available in next version.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.