Hello,
A dev I am working with implemented this code recipe
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
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();
}
}
}
?>