Last active
December 14, 2015 22:19
-
-
Save etiennetremel/5158025 to your computer and use it in GitHub Desktop.
Allow admin people or custom visitor IP to visit the site, otherwise, people are redirected to a specific page such as coming-soon.html
Code to copy/past in functions.php in theme folder.
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 | |
/** | |
* REDIRECT TO COMING SOON PAGE FOR NOT ALLOWED VISITORS | |
* Allow admin people or custom visitor IP to visit the site, otherwise, | |
* people are redirected to a specific page such as coming-soon.html | |
* Code to copy/past in functions.php in theme folder. | |
*/ | |
// Disallow access to website if not admin: | |
remove_filter('template_redirect','redirect_canonical'); | |
if ( ! ( is_super_admin() || is_login_page() || $_SERVER['REMOTE_ADDR'] == '000.000.000.000' ) ) { | |
header( 'Location: http://www.my-wordpress-site.com/coming-soon.html' ); | |
exit(); | |
} | |
function is_login_page() { | |
return in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment