Created
June 4, 2014 08:18
-
-
Save imvision/a931df5466a7341e4046 to your computer and use it in GitHub Desktop.
Restrict certain pages to logged in users only
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: BP Restrict | |
Plugin URI: | |
Description: Restrict wordpress pages to logged in users | |
Version: 1.2.0 | |
Author: Ali Roshan | |
Author Email: [email protected] | |
License: | |
Copyright 2011 Ali Roshan ([email protected]) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License, version 2, as | |
published by the Free Software Foundation. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
class BPRestrict { | |
/* --------------------------------------------* | |
* Constants | |
* -------------------------------------------- */ | |
private $redirect = 'register'; | |
private $pages = array( | |
'members' | |
//,'groups' | |
); | |
/** | |
* Constructor | |
*/ | |
function __construct() { | |
//Hook up to the init action | |
add_action('init', array(&$this, 'bpr_MembersOnly')); | |
} | |
function bpr_MembersOnly() { | |
if (!is_user_logged_in()) { | |
$page_slug = end(explode("/", rtrim($_SERVER['REQUEST_URI'], '/'))); | |
if (in_array($page_slug, $this->pages)) { | |
wp_redirect(site_url($this->redirect)); | |
exit(); | |
} | |
} | |
} | |
} | |
// end class | |
new BPRestrict(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment