This simple to implement, you could put this into functions.php if you want it tied to a theme, or else create your own plugin from this:
add_action('init','my_force_login');
function my_force_login(){
if ( !is_user_logged_in() && !in_array( $GLOBALS['pagenow'], array( 'wp-login.php', 'wp-register.php' ) ) ) {
$force_login=get_option('my_force_login');
if($force_login){
wp_redirect( wp_login_url() );
exit;
}
}
}
For this to work you will then need to create an option (either a theme option if this is to be tied to a theme, or otherwise an extra option in an appropriate WordPress page.
In the above, I am assuming there is an option with name ‘my_force_login’ with value true/false (or 1/0) which determines if the redirect should take effect.
The redirect applies to all logged-out users to all pages except the login/register page.