Help with conditional statements

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?

i’m trialling
if(Patreon_Wordpress::isPatron( wp_get_current_user() ) ) { // output code for valid patron }

is there a better way to write this?

What’s an example of how you’d use the information? Much of the validation is already included in the Patreon plugin or the Patron Pro Plugin.

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.

For example with PMPro

    if( function_exists('pmpro_hasMembershipLevel') && pmpro_hasMembershipLevel( array('1', '3') ) ) {    
      get_template_part('includes/subscription', 'benefits');

Patreon example (note i’m using the pro extension)

  if( class_exists('Patreon_Wordpress') && Patreon_Wordpress::isPatron( $current_user )  ) {    
      get_template_part('includes/subscription', 'benefits');

To check for a user’s patronage level, you can use getUserPatronage function:

You can use the below code to gate any part of your website:

If you use Patron Pro, the code is a bit different:

@codebard Is there a repository or folder with all the documentation? It is hard to find what I need without access to a central folder.

@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?

The Codebard Docs page should have most of what you need. The few other resources that you may need are below:

For Patreon Wordpress:

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!

$pUser = get_user_by("id", $userid);
$user_patronage = Patreon_Wordpress::getUserPatronage( $pUser );

This code works on a “user listing” page but not on the profile page.

If I comment out this line in the plugin then it works:

if ( self::$current_user_pledge_amount != -1 ) {
			return self::$current_user_pledge_amount;

Help would be appreciated.

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="<?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>
1 Like

But this is for the current user. I’m trying to get the Patron status of other users, NOT the current user.

ok, gotcha, I didn’t understand at first as you commented on my post which was about the current user.

Have you tried my code replacing wp_get_current_user() with get_user_by()


No, that doesn’t work, because the issue is with this function:

$anotherUser = get_user_by("id", $userid);
$user_patronage = Patreon_Wordpress::getUserPatronage($anotherUser);

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.

I’m asking for the plugin developers to fix this.

1 Like

I think I’ll start a new topic as this is just being confused.