You should be able to catch this on template_redirect or during parse_request / pre_get_posts.
Whitelist some pages like the login or your IP addresses otherwise you’ll get locked out should you sign-off.
Adding 301 to the wp_redirect will help search engines.
// NOTE: This code has not been tested
function wpse12302015_check_user_status()
{
// a user with admin privileges? - forget about it
if(current_user_can('manage_options')) {
return;
}
// whitelist some pages
if( is_page( 'login' ) )
{
return;
}
// send them off to the new website using the current request
$url="http://www.example.com" . $_SERVER['REQUEST_URI'];
wp_redirect( $url, 301 ); // Moved Permanently
exit();
}
add_action( 'template_redirect', 'wpse12302015_check_user_status' );
The template_redirect doesn’t look like it hits the login events.
Login Events
- [
init] - [
widgets_init] - [
wp_loaded] - [
admin_init] - [
wp_authenticate] - [
wp_login] - [
shutdown]
Front End Events
- [
init] - [
widgets_init] - [
wp_loaded] - [
parse_request] - [
pre_get_posts] - [
template_redirect]
Admin Events
- [
init] - [
widgets_init] - [
wp_loaded] - [
admin_menu] - [
admin_init] - [
wp_print_scripts] - [
admin_head] - [
admin_footer] - [
shutdown]