"Your Patron level is $X" function for WordPress

Hi, I would like to add a small banner on my site that notifies users what their current pledge level is. This would be useful for a number of purposes, including the creation of customized messages (“This content is locked, you can access it for only X dollars more!”), as well as troubleshooting (e.g. the recent OAuth stumble).

Currently I am trying the following, just to get a dump of the user data so I know what I’m working with. I cribbed this code from the plugin files, and plopped it into header.php just to see what would happen.

$api_client = new Patreon_API($user_meta['patreon_access_token'][0]);
$patreon_user = $api_client->fetch_user();

However, I get the error message

The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.

Can anyone get me pointed in the right direction? Do I need to call this from functions.php? Is there some authorization function I have to call first?

Your tokens may have expired. You can visit the clients list at Patreon at the page you created the client, refresh it and then copy over new keys.


$user_patronage = Patreon_Wordpress::getUserPatronage();

…would get you user patronage in cents. You can just plug this function instead of calling the api directly and getting the details from the api return. This function does it already.

1 Like

Perfect! Thank you so much!

1 Like