# Bug with the plugin - conditional statements do not function correctly

**URL:** <https://www.patreondevelopers.com/t/bug-with-the-plugin-conditional-statements-do-not-function-correctly/7048>\
**Category:** Wordpress Plugin\
**Created:** [February 17, 2023, 10:25am UTC](https://www.patreondevelopers.com/t/bug-with-the-plugin-conditional-statements-do-not-function-correctly/7048 "2023-02-17T10:25:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shauny](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/shauny/32/2226_2.png) [@shauny](https://www.patreondevelopers.com/u/shauny)\
**Post date:** [February 17, 2023, 10:25am UTC](https://www.patreondevelopers.com/t/bug-with-the-plugin-conditional-statements-do-not-function-correctly/7048/1 "2023-02-17T10:25:18Z")

</div>

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:

```auto
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:

```auto
    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):

```auto
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!

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [February 20, 2023, 3:06pm UTC](https://www.patreondevelopers.com/t/bug-with-the-plugin-conditional-statements-do-not-function-correctly/7048/2 "2023-02-20T15:06:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![shauny](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/shauny/32/2226_2.png) [@shauny](https://www.patreondevelopers.com/u/shauny)\
**Post date:** [March 6, 2023, 8:49pm UTC](https://www.patreondevelopers.com/t/bug-with-the-plugin-conditional-statements-do-not-function-correctly/7048/3 "2023-03-06T20:49:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![codebard](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/codebard/32/14_2.png) [@codebard](https://www.patreondevelopers.com/u/codebard)\
**Post date:** [March 13, 2023, 10:08pm UTC](https://www.patreondevelopers.com/t/bug-with-the-plugin-conditional-statements-do-not-function-correctly/7048/4 "2023-03-13T22:08:51Z")

</div>

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.
