<?php /*
**************************************************************************
Plugin Name: registered-users-only-2
Plugin URI: http://jehy.ru/wp-plugins.en.html
Description: Redirects all non-logged in users to your login form. Make sure to disable registration or install WP-invites plugin if you want your blog truely private. Original author - Viper007Bond.
Version: 0.3
Min WP Version: 2.6
Max WP Version: 2.9.2
Author: Jehy
Author URI: http://jehy.ru/index.en.html
**************************************************************************/
class RegisteredUsersOnly {
var $exclusions = array();
// Class initialization
function RegisteredUsersOnly () {
// Register our hooks
add_action( 'wp', array(&$this, 'MaybeRedirect') );
add_action( 'template_notices', array(&$this, 'LoginFormMessage') );
}
// Depending on conditions, run an authentication check
function MaybeRedirect() {
global $bp;
// If the user is logged in, then abort
if ( is_user_logged_in() ) return;
if (bp_is_register_page() || bp_is_activation_page() )//buddypress
return;
$this->exclusions = array(
'wp-login.php',
'wp-signup.php',
'wp-register.php',
'wp-activate.php',
'wp-cron.php' // Just incase
);
// If the current script name is in the exclusion list, abort
if ( in_array( basename($_SERVER['PHP_SELF']), apply_filters( 'registered-users-only_exclusions', $this->exclusions) ) ) return;
// Still here? Okay, then redirect to the login form
bp_core_redirect(bp_get_signup_page());
}
function LoginFormMessage() {
global $bp;
if( bp_is_register_page() && 'request-details' == bp_get_current_signup_step() ) :
$error = __( 'Only registered users can participate in the community. Please register or login.', 'registered-users-only' );
echo '<div class="error">'.$error.'</div>';
endif;
}
}
// Start this plugin once all other plugins are fully loaded
add_action( 'plugins_loaded', create_function( '', 'global $RegisteredUsersOnly; $RegisteredUsersOnly = new RegisteredUsersOnly();' ) );
?>