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:

https://www.dropbox.com/scl/fi/9spl5hqv6d55gb3vxbyru/Patreon-WordPress-how-to-lock-any-part-of-your-Website.paper?dl=0&rlkey=zr3qdxi5g5sp83c6kbrqc92bt

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

https://www.dropbox.com/scl/fi/69dejrx1ol95tx5kvww78/Patron-Pro-how-to-lock-any-part-of-your-Website.paper?dl=0

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

https://www.dropbox.com/scl/fi/0eshdfu5rhl72oi7ascnj/Patreon-WordPress-Filters.paper?dl=0&rlkey=m5g2u0kzcbrz7dqlex3uta6s7

https://www.dropbox.com/scl/fi/82g2nr738mqgx3ewwflxh/Patreon-WordPress-Action-Hooks.paper?dl=0

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.