• Resolved thecorkboard

    (@thecorkboard)


    Hello-

    On line 1951 of achievements-templatetags.php, can this be adjusted to allow super admins & a user of username “badgesadmin” to get grant privileges?

    /**
     * Does the user have the capability to grant Achievements to other users?
     *
     * @since 2.0
     * @global object $bp BuddyPress global settings
     * @return bool
     */
    function dpa_permission_can_user_grant() {
    	global $bp;
    
    	if ( !$bp->loggedin_user->id )
    		return false;
    
    	if ( $bp->loggedin_user->is_super_admin )
    		return true;
    
    	return apply_filters( 'dpa_permission_can_user_grant', current_user_can( 'achievements_grant' ) );
    }

    Tried a few things without any success, probably because my php skills need significant upgrades :/

    https://www.ads-software.com/plugins/achievements/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Paul Wong-Gibbs

    (@djpaul)

    Filtering dpa_permission_can_user_grant should do it. What have you tried? Happy to help debug it but I’m unable to build it for you from scratch.

    Thread Starter thecorkboard

    (@thecorkboard)

    I thought that there might be a way to add another if or elseif statement that basically said if the user matched login “badgesadmin” return true.

    So, maybe something like this:

    $badgesadmin=get_user_by('login', 'badgesadmin');
    elseif ( $bp->loggedin_user->$badgesadmin)
    		return true;

    I don’t know…That’s all I’ve got.

    Plugin Author Paul Wong-Gibbs

    (@djpaul)

    Using your code as a base, something like this maybe

    function tcb_filter_caps( $grant_permission ) {
      if ( $grant_permission )
        return true;
    
      global $bp;
      $badgesadmin_id = get_user_by( 'ID', 'badgesadmin' );
      return ( $bp->loggedin_user->id == $badgesadmin_id );
    }
    add_filter( 'dpa_permission_can_user_grant', 'tcb_filter_caps' );
    Thread Starter thecorkboard

    (@thecorkboard)

    Nice! Made some edits to get it to work:

    function tcb_filter_caps( $grant_permission ) {
      if ( $grant_permission )
        return true;
    
    	global $bp;
    	$badgesadmin_id = get_user_by( 'user_login', 'badgesadmin' );
      	if ( $bp->loggedin_user->user_login == $badgesadmin_id )
    	    return true;
    }
    add_filter( 'dpa_permission_can_user_grant', 'tcb_filter_caps' );
    Thread Starter thecorkboard

    (@thecorkboard)

    Scratch that. It was granting privileges to everyone…

    Thread Starter thecorkboard

    (@thecorkboard)

    Take two seems to be working. Any concerns?

    function badgesadminpriv() {
    	global $bp;
    
    	$current_user = wp_get_current_user();
    		if ( 47 == $current_user->ID ) {
    			return true;
    		}
    		else {
        		return false;
    		}
    }
    add_filter( 'dpa_permission_can_user_grant', 'badgesadminpriv');
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘2.4: change dpa_permission_can_user_grant’ is closed to new replies.