Last active
February 2, 2022 15:50
-
-
Save sc0ttkclark/135896c11715e4cb04dad8f13cc3bb6d to your computer and use it in GitHub Desktop.
Lock the entire PMPro site down for anyone logged out.
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 | |
/* | |
* Lock down the site for anyone logged out. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
/** | |
* Handle locking down the site and redirecting traffic to the login page in certain circumstances. | |
*/ | |
function my_pmpro_site_lock_down() { | |
// Bypass if we are in the admin area, on the login page, or the user is logged in. | |
if ( is_admin() || pmpro_is_login_page() || is_user_logged_in() ) { | |
return; | |
} | |
// Redirect all traffic to the login page with redirect_to set to current page. | |
wp_redirect( pmpro_login_url( $_SERVER['REQUEST_URI'] ) ); | |
die(); | |
} | |
add_action( 'init', 'my_pmpro_site_lock_down' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment