Patron PRO plugin not respectin tiers? (code recipe)

Hello,
A dev I am working with implemented this code recipe

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

to restrict access depending on the Patreon tier to elements outside of default WP fields

But after testing I noticed that the code provides access to all Patreon subscribers, no matter what tier they have (in the below Code they should have a tier > 21 to get access).

Any idea what is wrong? Thanks for any heads up :slight_smile:

Here is the full code

<?php
    function lezione_restricted_content(){ ?>
        <script>
            jQuery( document ).ready(function() {
                console.log( "Confidential content!" );
                jQuery("#restricted-content" ).remove();
            });
        </script>
<?php } ?>
<?php
    function lezione_sign_up(){ ?>
        <div class="well-blue restricted-content">
            Restricted content
        </div>
<?php } ?>

<?php
	if ( get_post_type( get_the_ID() ) == 'lezione' ) {
		$free_lesson = get_field( "free_lesson" );
		if( $free_lesson ){
			// echo "Free Lesson";
		} else {

			if ( is_user_logged_in() ) {
				if ( !$user ) {
					$user = wp_get_current_user();
				}
				$user_patronage = Patreon_Wordpress::getUserPatronage();
				$declined = Patreon_Wordpress::checkDeclinedPatronage($user);
				$vip = 'no';
				$vip = get_user_meta( $user->ID, 'cb_p6_a1_vip_user', true );
				$user_patreon_level = get_user_meta( $user->ID, 'cb_p6_a1_patreon_level', true );
				$redir = home_url(add_query_arg($_GET,$wp->request));
				if( $vip ){
					// echo "vip <br>";
				} else {
					// echo "No vip <br>";
					$user_roles = ( array ) $user->roles;	
					$terms = get_the_terms( get_the_ID(), 'corso' ); 

                    if($terms){
                        foreach($terms as $term) {
                            $slug = $term->slug;
                            if ( in_array( $slug, $user_roles ) ) {
                                // echo 'what have a match!<br>';
                                // echo $slug .'<br>';
                            } else {
                                // echo 'NO match!<br>';
                                // echo $slug .'<br>';

                                // echo '$user_patronage: ' . $user_patronage .'<br>';
                                // echo '$user_patreon_level: ' . $user_patreon_level .'<br>';
                                if ( ( ! $declined ) OR !current_user_can( 'manage_options' ) ) {
                                    if ( $user_patronage > 21 ){
                                        // echo '$user_patronage: ' . $user_patronage .' > 21<br>';
                                    } elseif( $user_patreon_level > 21 ) {
                                        // echo '$user_patreon_level: ' . $user_patreon_level .' > 21<br>';
                                    } else {
                                        lezione_restricted_content();
                                        lezione_sign_up();
                                    }
                                }
                            }
                        }
                    } else { 
                        lezione_restricted_content();
                        lezione_sign_up();
                    }
				}
			} else {
                lezione_restricted_content();
                lezione_sign_up();
			}
		}
	}
?>

No need to check for $declined.

That code is working on many websites at this moment. Its likely that there may be a situation at your site, or your site may have lost connection to Patreon because your creator access token got refreshed. That currently happens if you try to log in to your site with your creator account. Try checking if your site was disconnected and reconnecting it.

I think the site is connected to Patreon because the code works for providing access only to Patreon subscribers, the issue is that it doesn’t respect the tier that is set in the code,

                                    if ( $user_patronage > 21 ){
                                        // echo '$user_patronage: ' . $user_patronage .' > 21<br>';
                                    } elseif( $user_patreon_level > 21 ) {
                                        // echo '$user_patreon_level: ' . $user_patreon_level .' > 21<br>';
                                    } else {

it provides access to all Patreon subscribers.

A fix for this kind of tier mismatching went out at patreon.com very recently. Give a try to testing it out again.

Actually, it turns out the error was in my code. Patreon tier needs to be written with 2 zeros as decimals, like 1100, and not 11.

Thanks

1 Like