Skip to content

Instantly share code, notes, and snippets.

@etiennetremel
Last active December 14, 2015 22:19
Show Gist options
  • Save etiennetremel/5158025 to your computer and use it in GitHub Desktop.
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.
<?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