1. <?php /*
  2.  
  3. **************************************************************************
  4.  
  5. Plugin Name: registered-users-only-2
  6. Plugin URI: http://jehy.ru/wp-plugins.en.html
  7. 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.
  8. Version: 0.3
  9. Min WP Version: 2.6
  10. Max WP Version: 2.9.2
  11. Author: Jehy
  12. Author URI: http://jehy.ru/index.en.html
  13.  
  14. **************************************************************************/
  15.  
  16. class RegisteredUsersOnly {
  17. var $exclusions = array();
  18. // Class initialization
  19. function RegisteredUsersOnly () {
  20. // Register our hooks
  21. add_action( 'wp', array(&$this, 'MaybeRedirect') );
  22. add_action( 'template_notices', array(&$this, 'LoginFormMessage') );
  23.  
  24. }
  25.  
  26. // Depending on conditions, run an authentication check
  27. function MaybeRedirect() {
  28. global $bp;
  29. // If the user is logged in, then abort
  30. if ( is_user_logged_in() ) return;
  31.  
  32. if (bp_is_register_page() || bp_is_activation_page() )//buddypress
  33. return;
  34.  
  35. $this->exclusions = array(
  36. 'wp-login.php',
  37. 'wp-signup.php',
  38. 'wp-register.php',
  39. 'wp-activate.php',
  40. 'wp-cron.php' // Just incase
  41. );
  42. // If the current script name is in the exclusion list, abort
  43. if ( in_array( basename($_SERVER['PHP_SELF']), apply_filters( 'registered-users-only_exclusions', $this->exclusions) ) ) return;
  44.  
  45. // Still here? Okay, then redirect to the login form
  46. bp_core_redirect(bp_get_signup_page());
  47. }
  48.  
  49. function LoginFormMessage() {
  50. global $bp;
  51.  
  52. if( bp_is_register_page() && 'request-details' == bp_get_current_signup_step() ) :
  53. $error = __( 'Only registered users can participate in the community. Please register or login.', 'registered-users-only' );
  54.  
  55. echo '<div class="error">'.$error.'</div>';
  56. endif;
  57. }
  58.  
  59. }
  60.  
  61. // Start this plugin once all other plugins are fully loaded
  62. add_action( 'plugins_loaded', create_function( '', 'global $RegisteredUsersOnly; $RegisteredUsersOnly = new RegisteredUsersOnly();' ) );
  63.  
  64. ?>