Bug with the plugin - conditional statements do not function correctly

Hi,

Starting a new thread about this because it was getting confused.

There is a bug in the plugin, if I pass a User object to Patreon_Wordpress::getUserPatronage($userObject) and the output is on a user’s profile page (I’m using Ultimate Member) then instead of returning the patronage of the user passed into the function, it always returns the patronage of the current user.

What I want to happen: I want to be able to show on a user profile page whether or not they are a patron. I added this code to Ultimate Member to display a little “Patron” badge next to their name whenever it is shown:

function tardis_add_patron_badge( $name, $user_id, $html ) {
	if ( ! $html )
		return $name;

	$pUser = new User($user_id);

	if ( $pUser->is_patron() ) {
		$name = $name . " <span class='badge rounded-pill text-bg-success patron-badge'>Patron</span>";
	}

	return $name;
}
add_filter( 'um_user_display_name_filter', 'tardis_add_patron_badge', 50, 3 );

You can see this is using a function is_patron in the User class, this is the function I added:

    public function is_patron() {
      $userid = $this->userid;
  
      if(class_exists('Patreon_Wordpress')) {
  
        $pUser = get_user_by("id", $userid);
    
        // Check how much patronage the user has
        $user_patronage = Patreon_Wordpress::getUserPatronage( $pUser );
    
        // Check if user is a patron whose payment is declined
        $declined = Patreon_Wordpress::checkDeclinedPatronage( $pUser );
    
        if ( ( $user_patronage < ( 1 ) OR $declined ) /*AND !current_user_can( 'manage_options' )*/ ) {
          return false;
        } else {
          return true;
        }
      } else {
        return false;
      }
    }

So this should check if the User (which is constructed using the userid sent to it) is a patron or not.

What actually happens: This works fine if you’re looking at the user from any other context, or if the current user is not a patron but if you’re looking at the user’s profile page, and the logged in user is a patron, it always returns true so it makes it look like everyone is a patron.

I think I have found the culprit: This line in the plugin (patreon_wordpress.php line 566):

if ( self::$current_user_pledge_amount != -1 ) {
    return self::$current_user_pledge_amount;
}

As you can see, even though we are sending a user object to this function, it immediately cancels that and sends the current user pledge amount if there is one. This undermines the whole point of being able to send a $user object to this function! Commenting this out fixes my problem!

Please can the plugin developers take a look at this, see why that code is in there in the first place, and remove it or change it please?

Thanks!

Yes, that bit of code may cache the last user that was checked for pledge and return it regardless of what user object is fed to it. This will be looked in a later version. For the time being, try to get around it however you can - ie by using your own custom pledge check function etc.

Hi, is there an ETA of when this will get fixed please? I’d rather not write my own function if it’s going to be fixed soon.

The last version should have addressed this. Check it out in the development log at WP org or in the plugin info in WP admin.