Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example code for the Caldera Forms membership system PHP function. See: https://calderawp.com/doc/members-caldera-forms-getting-started/
<?php
//restrict access to whole post
add_action( 'template_redirect', function(){
if( ! cf_members_has_plan( 'your_plan_slug' ) ) {
wp_safe_redirect( home_url( 'sign-up' ) );
}
});
<?php
//Use in theme template to restrict content.
//presumes you have post meta key called "allowed_plans" saved.
$plans = get_post_meta( get_the_ID(), 'allowed_plans', true );
if( ! empty( $allowed ) && ! is_array( $allowed ) ){
$plans = array( $allowed );
}
$allowed = false;
foreach( $plans as $plan ){
if( cf_members_has_plan( 'your_plan_slug' ) ) {
$allowed = true;
break;
}
}
if( $allowed ) {
echo "I must be a member to see this";
}
<?php
//Use in theme template to restrict content.
if( cf_members_has_plan( 'your_plan_slug' ) ) {
echo "I must be a member to see this";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.