I want to create a plugin to extend the Patreon Connect plugin. I found in a forum post, that I can get the Patreon user like this;
$my_user = Patreon_Wordpress::getPatreonUser( $current_user );
So I’m doing that, and I logged in with Patreon. But when I do this on an admin page:
$my_user = Patreon_Wordpress::getPatreonUser( $current_user );
echo var_dump($my_user);
In the browser I just see:
/wp-content/plugins/my-plugin/plugin.php:204:boolean false
So it seems that I haven’t successfully gotten the Patreon user. Am I doing something wrong here?
It looks like using this same code inside the content filter works as expected. I actually want this information on the admin side, since I want to give the user access to certain features in my plugin if they are a sponsor. Is it possible to get the Patreon user object from within the admin?
The presence of the Patreon user would depend on the presence of WP user. So if you use that function early in init process, you may not be able to get it.
Also the Patreon user must have connected his/her account to WP account before.
Thanks for the response. The user is definitely a Patreon user with a connected WP account. I thought maybe adding a priority parameter like this add_action( 'admin_init', 'my_func', 999 )
would work. I also tried setting the priority to 1
. Neither one worked, and I’m still getting false
. Any other ideas? Is the admin_init
hook a bad one to use?
Ah, its likely that you are not feeding the WP user object to the function.
The input var current_user needs to take in current’ users WP object. Or, another user.
If you put…
$current_user = wp_get_current_user();
…just before that function, it should work.
That was it! Thanks! This code works fine inside the admin_init hook.
$current_user = wp_get_current_user();
$my_user = Patreon_Wordpress::getPatreonUser( $current_user );
echo var_dump($my_user);
1 Like
Great! Note that you can use it to get other users’ info too. But the user must have connected his/her Patreon to your site.