Skip to content

Instantly share code, notes, and snippets.

@seventhqueen
Created January 30, 2017 15:30
Show Gist options
  • Save seventhqueen/e071728dfec33e5108abd954181678e6 to your computer and use it in GitHub Desktop.
Save seventhqueen/e071728dfec33e5108abd954181678e6 to your computer and use it in GitHub Desktop.
Private WordPress community site - redirect guests to register page
<?php
/**
* Restrict users to your site and redirect them to register page
* @author SeventhQueen
*
* @return void
*/
function sq_restrict_my_website(){
global $pmpro_pages;
if(!is_user_logged_in() && ( function_exists('bp_is_active') && ! bp_is_register_page() ) && $GLOBALS['pagenow'] !== 'wp-login.php' && ( !empty( $pmpro_pages ) && !is_page($pmpro_pages) )){
wp_redirect(wp_registration_url());
exit();
}
}
add_action('template_redirect', 'sq_restrict_my_website');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment