Sean Tarantino 2020-11-17T10:28:14-05:00

Forum Replies Created

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • Sean Tarantino
    Participant
    Post count: 8

    Thought I was nuts there for a second 🙂

    Works perfectly now!

    Thanks so much Michael, you really have helped me out here!

    Sean Tarantino
    Participant
    Post count: 8

    Apparently, I am not doing this right, I thought I was but must have some leaderboards not updated as they should have fooling me into the fact that I had it working. I put in your array snippet and the whole pice of code looks like this, however it does not seem to be working at all, like it’s not even being looked at–

    <?php
    
    /**
     * Filter the update leaders function and conditionally undo addition of admins.
     * 
     * @param $leaders          Array of current leaders for the leaderboard
     * @param $leaderboard_id   Leaderboard ID we are updating.
     * @param $original_leaders Array of original leaders before most recent addition.
     *
     * @return array
     */
    function custom_exclude_corp_from_leaderboard( $leaders, $leaderboard_id, $original_leaders ) {
    
    	// Set leaderboards to exclude from.
    	$leaderboard_to_exclude_from = array( 19660, 19661, 19662, 19663, 19664, 19665, 19666, 19667 );
    
    	if ( ! in_array( $leaderboard_to_exclude_from, $leaderboard_id ) ) {
    		return $leaders;
    	}
    
    	// Grab all of our current site admins.
    	$admins = new WP_User_Query( array( 'role' => 'north-west' ) );
    
    	$admin_users = $admins->get_results();
    	$admin_ids = array();
    	// Loop over the admins to get an array of just their IDs.
    	foreach ( $admin_users as $user ) {
    		$admin_ids[] = $user->ID;
    	}
    	// Placeholder boolean to hold whether or not to update the leaderboard data.
    	$should_update = false;
    	foreach ( $leaders as $key => $leader ) {
    		if ( in_array( $leader['user_id'], $admin_ids ) ) {
    			// We found an admin being added to the leaderboard data.
    			$should_update = true;
    		}
    	}
    	if ( $should_update ) {
    		// Since we just added an administrator, we need to re-set the leaderboard data to
    		// the state it was previously at.
    		update_post_meta( $leaderboard_id, '_badgeos_leaderboard_leaders', $original_leaders );
    		return $original_leaders;
    	}
    	return $leaders;
    }
    add_filter( 'badgeos_leaderboard_update_leaders', 'custom_exclude_corp_from_leaderboard', 10, 3 );
    
    Sean Tarantino
    Participant
    Post count: 8

    nvmd, think I’m all good, thanks so much for your assistance!!

    Sean Tarantino
    Participant
    Post count: 8

    Ahhh, ok, thanks–this is VERY hepful!

    I had the filter set to my newly named function:

    add_filter( ‘badgeos_leaderboard_update_leaders’, ‘custom_exclude_northWest_from_leaderboard’, 10, 3 );

    If I have multiple functions ie, northwest, southwest etc can I call this filter just once at the end making sure to include all functions and all should be well or no?

    Sean Tarantino
    Participant
    Post count: 8

    Hey Michael, I can see this coming together, however, I am having a problem with the $leaderboard id var…I can set this to 1 id and it works fine, however, when I try multiple it’s not working and its probably because Im not putting in the proper code as I am not a seasoned developer its probably something small.

    I tried creating a new variable:

    $northWestFilter = ($leaderboard_id=19661, $leaderboard_id=19662, $leaderboard_id=19663, $leaderboard_id=19664, $leaderboard_id=19665, $leaderboard_id=19666, $leaderboard_id=19667, $leaderboard_id=19668);

    Then calling that within my function:

    function custom_exclude_northWest_from_leaderboard( $leaders, $northWestFilter, $original_leaders )

    I must be doing something wrong, and it’s probably how Im calling the multiple leaderboards is my guess–any hlp would be appreciated, Im getting very close to what I want.

    Sean Tarantino
    Participant
    Post count: 8

    Thank you for the quick reply Michael! I will have a go at it and see how it goes and let you know.

    Agreed, definitely not set it and forget it 🙂

    But hopefully a temporary solution until BadgeOS develops something like this as an option that I see a lot of users asking for.

    Thanks again!

    Sean Tarantino
    Participant
    Post count: 8

    Is there a way we could modify this so that we can add other roles and only exclude them for select leaderboards?

Viewing 7 posts - 1 through 7 (of 7 total)