# getUserPatronage defaults to current user even when passed a user object

**URL:** <https://www.patreondevelopers.com/t/getuserpatronage-defaults-to-current-user-even-when-passed-a-user-object/4421>\
**Category:** Wordpress Plugin\
**Created:** [April 20, 2021, 8:22am UTC](https://www.patreondevelopers.com/t/getuserpatronage-defaults-to-current-user-even-when-passed-a-user-object/4421 "2021-04-20T08:22:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mimiga](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/mimiga/32/1652_2.png) [@Mimiga](https://www.patreondevelopers.com/u/Mimiga)\
**Post date:** [April 20, 2021, 8:22am UTC](https://www.patreondevelopers.com/t/getuserpatronage-defaults-to-current-user-even-when-passed-a-user-object/4421/1 "2021-04-20T08:22:07Z")

</div>

I’m finding that getUserPatronage seems to be ignoring my user object I’m passing it and defaulting to the current logged-in user which is causing troubles.

Here is what I have:

My function is passed **$userID** , it displays an image based on user’s patronage.

I get the WP\_User object by: **$user = get\_user\_by(‘ID’,$userID);**

which successfully returns me the WP\_User .  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/patreondevelopers/original/2X/f/f90a10091b20be75b1a7533ec2be89509e1e6f65.png)

However, upon doing this:  
**$currentPledge = Patreon\_Wordpress::getUserPatronage($user);**

It ignores the user that was passed and defaults to the current user.

I know this is happening because upon checking $currentPledge, it displays the image for the CURRENT user’s patronage, NOT the user that was passed.

I am using a Multisite and all my users are in a specific blog ID, which I thought was the issue at first, but even using my usual tactic of swtching the blog ID to the main one still makes it have the current user’s info and not the one passed.

---

<div class="post-metadata">

**Author:** ![Mimiga](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/mimiga/32/1652_2.png) [@Mimiga](https://www.patreondevelopers.com/u/Mimiga)\
**Post date:** [April 20, 2021, 8:09pm UTC](https://www.patreondevelopers.com/t/getuserpatronage-defaults-to-current-user-even-when-passed-a-user-object/4421/2 "2021-04-20T20:09:35Z")

</div>

Also I just found this odd behaviour while testing the solution for the problem in the first post and I’d figure I’d just ask if it’s correct?

Using **Patreon\_Wordpress::isPatron($user)** by itself causes the function to fail, but if I include **Patreon\_Wordpress::getUserPatronage($user)** before it, it will succeed.

 ![Untitled](https://canada1.discourse-cdn.com/flex036/uploads/patreondevelopers/original/2X/6/65fe7f2e771651be2ea565238f72612d67bf78cf.png)

---

<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:** [April 21, 2021, 12:48am UTC](https://www.patreondevelopers.com/t/getuserpatronage-defaults-to-current-user-even-when-passed-a-user-object/4421/3 "2021-04-21T00:48:29Z")

</div>

The code logic and sequence in there does not look like it will cause that behavior. However there is short term (for length of script run) internal caching of patronage. That may be interfering. Also any code or plugin that modifies user object or filters it may be interfering.

---

<div class="post-metadata">

**Author:** ![Mimiga](https://yyz2.discourse-cdn.com/flex036/user_avatar/www.patreondevelopers.com/mimiga/32/1652_2.png) [@Mimiga](https://www.patreondevelopers.com/u/Mimiga)\
**Post date:** [August 31, 2021, 11:23pm UTC](https://www.patreondevelopers.com/t/getuserpatronage-defaults-to-current-user-even-when-passed-a-user-object/4421/4 "2021-08-31T23:23:03Z")

</div>

Thanks for your reply, is there some way to bypass the cacheing?

I guess I should state my problem too. When I run a foreach on each user and use getUserPatronage(), the first user’s getUserPatronage() amount does indeed cache through the entire loop (e.g. first user’s pledge is 1000 and all users after that come up with 1000 as well).

Is there a different way to go about this?

---

<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:** [September 1, 2021, 11:12pm UTC](https://www.patreondevelopers.com/t/getuserpatronage-defaults-to-current-user-even-when-passed-a-user-object/4421/5 "2021-09-01T23:12:03Z")

</div>

There is no need to bypass that caching since it just effects the existing script’s run. When you reload the page, it is refreshed.

However, there is a cache that caches patron information for up to 3 days in the backend. If your site lost connection to Patreon and the site is getting the info from that cache, that may be a factor.

Disconnecting your site and reconnecting it to Patreon may help.
