options = get_option('private_buddypress'); $this->dbVersion = get_option('private_buddypress_version'); // Load textdomain load_plugin_textdomain('private-buddypress', 'languages', dirname(plugin_basename(__FILE__)) . '/languages'); // Add admin options add_action('admin_init', array($this, 'AdminInit')); // Add login redirect function add_action('wp', array($this, 'LoginRedirect'), 1); } function AdminInit() { // Add settings section add_settings_section('private-buddypress', __('BuddyPress Protection', 'private-buddypress'), array($this, 'AdminOptions'), 'privacy'); add_action('load-options.php', array($this, 'SaveAdminOptions')); // Run action do_action('pbp_admin_init'); } function Install() { // Check if a existing installation if ( PRIVATE_BUDDYPRESS_VERSION == get_option( 'private_buddypress_version' ) ) return; // Default options $options = new stdClass(); $options->exclude = new stdClass(); $options->exclude->homepage = false; $options->exclude->registration = false; $options->exclude->blogpages = false; // Add or update options to database update_option('private_buddypress', $options); update_option('private_buddypress_version', PRIVATE_BUDDYPRESS_VERSION); } function IsBuddyPressFeed() { // Get BuddyPress global $bp; // Default value $isBuddyPressFeed = false; // Check if the current BuddyPress page is a feed if ( $bp->current_action == 'feed' || $bp->action_variables[0] == 'feed' ) $isBuddyPressFeed = true; // Return false if no BuddyPress feed has been called return apply_filters('pbp_is_buddypress_feed', $isBuddyPressFeed); } function ProtectBlogFeeds() { // Default value $protectBlogFeeds = false; // If blog pages should be protect, add protection to the feeds if ( is_feed() && false == $this->options->exclude->blogpages ) $protection = true; // Filter and return the value return apply_filters('pbp_protect_blog_feeds', $protection); } function LoginRedirect() { // Get current position $redirect_to = apply_filters('pbp_redirect_to_after_login', $_SERVER['REQUEST_URI']); // Check if user is logged in if ( false == is_user_logged_in() ): // Run action do_action('pbp_login_redirect'); // Check if current page is a feed if ( $this->ProtectBlogFeeds() || $this->IsBuddyPressFeed() ): // Try to get saved login credentials $credentials = array( 'user_login' => $_SERVER['PHP_AUTH_USER'], 'user_password' => $_SERVER['PHP_AUTH_PW'] ); // Send headers for authentication if ( is_wp_error( wp_signon( $credentials ) ) ): header('WWW-Authenticate: Basic realm="' . get_option('blogtitle') . '"'); header('HTTP/1.0 401 Unauthorized'); die('
|
|