getUserPatronage defaults to current user even when passed a user object

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 .

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.

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.

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.

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?

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.