Created
October 27, 2023 11:33
-
-
Save kimcoleman/adacd984ade3cd416e2cbdbc415274b3 to your computer and use it in GitHub Desktop.
An example template that uses the pmpro_has_membership_access function to protect content.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Template Name: My Custom Template | |
* | |
* An example template that uses the pmpro_has_membership_access function to protect content. | |
* | |
*/ | |
get_header(); ?> | |
<main id="main" class="site-main" role="main"> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<?php | |
// Check if the user has access. | |
$hasaccess = pmpro_has_membership_access( $post->ID, null, true ); | |
if ( ! empty( $hasaccess[0] ) ) { | |
// The user has access, show the custom template content or page content. | |
echo $post->post_content; | |
} else { | |
// If the user doesn't have access, show the pmpro_get_no_access_message. | |
echo pmpro_get_no_access_message( '', $hasaccess[1], $hasaccess[2] ); | |
} | |
?> | |
<?php endwhile; ?> | |
</main><!-- #main --> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment