Created
December 12, 2024 15:23
-
-
Save kimcoleman/d707f80051a8446538a1d874bfab4ab1 to your computer and use it in GitHub Desktop.
Custom recipe to lock down everything but the homepage. Used for the Condo Owner's Association Demo at https://coa.pmproplugin.com/
This file contains 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 | |
function my_coa_demo_template_redirect_lock_entire_site(){ | |
// If the user has a membership level, we don't need to lock down the site. | |
if ( ! function_exists( 'pmpro_hasMembershipLevel' ) || pmpro_hasMembershipLevel() ) { | |
return; | |
} | |
// If they have membership, return. | |
if ( pmpro_hasMembershipLevel() ) { | |
return; | |
} | |
global $pmpro_pages; | |
$okay_pages = array( '79' ); | |
if ( is_front_page() || is_page( $pmpro_pages ) || is_page( $okay_pages ) || strpos( $_SERVER['REQUEST_URI'], "login" ) ) { | |
return; | |
} | |
if ( is_user_logged_in() ) { | |
wp_safe_redirect( home_url() ); | |
exit; | |
} else { | |
// The user needs to be redirected to log in. | |
wp_safe_redirect( pmpro_login_url( get_permalink( $pmpro_pages['account'] ) ) ); | |
exit; | |
} | |
} | |
add_action( 'template_redirect', 'my_coa_demo_template_redirect_lock_entire_site' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment