Hello. I started a project with Patreon for WordPress in April 2021. I have a site running PMPro and want to switch subscribers to Patreon. I put that project on hold to build a custom WordPress theme for the site.
Now I’m revisiting switching to Patreon. Where is all the documentation? Is it in Dropbox Paper?
I need to write some conditional statements checking if user is a valid patron, if they have an existing patron account, if their account is expired, that type of thing. How do I do that?
Thanks @jennbriden , I’ve built a custom WordPress theme. It currently uses PMPro for membership, and have several instances where I check if the user if logged in with a current membership and conditionaly display content. I want to do similar with Patreon.
@codebard I only have one patron level so will this suffice?
if( class_exists('Patreon_Wordpress') && Patreon_Wordpress::isPatron() ) {
// output for logged-in Patron
} else {
// output for all other users
}
or is it better to use
if( class_exists('Patreon_Wordpress') && Patreon_Wordpress:: getUserPatronage() ) {
// output for logged-in Patron
} else {
// output for all other users
}
is there a condition that checks that a user was formerly a patron? or one for users that have a Patreon account but not a patron of my specific account?
If you are using Patron Plugin Pro, everything is much easier: Every function in Patron Pro also functions as a hook and a filter. You can filter any parameter that goes into a function before the function runs. You can filter any output from any function. You can also run actions right before a function runs and right after a function completes, using the function’s own parameters. Ie, its like the WP hooks system, except every function has filters and hooks.
If you browse the plugin.php included in the plugin, you can see every single function that you can hook into.
Checking for user patronage amount is better and future proof. Just compare it to your current tier $ level, and do whatever you need to do based on the comparison. This way, in case you add more tiers, the comparison logic will still work.
I am having the same problem here. Using the plugin Ultimate Member, when I look at a user’s profile page, I am trying to show if they are a patron or not - I am using this code which should work as I’m passing a user object into it but it always returns with the current user’s patron level, not the one I’m looking at!
That just caches the pledge amount for the duration of the page run. If its not reflecting the correct level in any given page, try checking whether there is anything that resets it during the page load (any plugin or etc).
Hi. I don’t think you understood what I said. I’m not trying to get the pledge level of a page. I’m trying to display, next to a user’s name, if they are a Patron or not. It works on my “member list” page but if I view a user on their profile page it says everyone is a Patron, because it is not looking at their status but at mine!
Try adapting from this (this checks if user is patron and output their current pledge amount)
// User
$current_user = wp_get_current_user();
$current_user_display_name = $current_user->display_name;
if(class_exists('Patreon_Wordpress')) {
// Check how much patronage the user has
$user_patronage = Patreon_Wordpress::getUserPatronage();
$current_pledge = $user_patronage / 100;
$current_pledge = number_format($current_pledge,2);
// Check if user is a patron whose payment is declined
$declined = Patreon_Wordpress::checkDeclinedPatronage($current_user);
// Check if this user account is connected to Patreon
$linked_patreon_account = get_user_meta( get_current_user_id(), 'patreon_user_id', true );
}
// User has a conntected Patreon account
if( class_exists('Patreon_Wordpress') && $linked_patreon_account ) { ?>
<p>You have successfully linked your <a href="https://www.patreon.com/user?u=<?php echo $linked_patreon_account; ?>">Patreon account</a> to <?php echo get_bloginfo(); ?>.</p>
<?php }
// User holds a Patreon account with a valid pledge of $5.50
if ( !$declined && ($user_patronage >= 550) ) { ?>
<p>Your current pledge is <?php echo $current_pledge; ?></p>
If I use that function, even though I’m passing another user into it, it always returns whether the patronage of the current user, if I’m running this function on a specific user’s profile page.
The function is broken in the plugin!
I’ve identified the problem code in the plugin which is this:
if ( self::$current_user_pledge_amount != -1 ) {
return self::$current_user_pledge_amount;
}
That code is wrong because it always returns the current user, even if you are asking for info about another user.