-
-
Save fovoc/04b123a27b0b4c614f12 to your computer and use it in GitHub Desktop.
Lockdown BuddyPress with Paid Memberships Pro Example
This file contains 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: PMPro BuddyPress Customizations | |
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-buddypress-customizations/ | |
Description: Example code to lock down parts of BuddyPress with PMPro | |
Version: 0.2 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
*/ | |
/* | |
Copyright 2010 Stranger Studios (email : [email protected]) | |
*/ | |
//disable buddy press admin bar | |
define('BP_DISABLE_ADMIN_BAR', true); | |
//hide some pages in buddypress | |
function pmpros_hide_buddy_press_pages() | |
{ | |
$uri = $_SERVER['REQUEST_URI']; | |
$not_allowed = array( | |
//"/members/", | |
"/groups/", | |
"/groups/create/", | |
"/groups/create/*", | |
"/members/groups/", | |
"/members/*/settings/", | |
); | |
foreach($not_allowed as $check) | |
{ | |
//prep for regex | |
$check = str_replace("/", "[\/]+", $check); //replace / | |
$check = str_replace("*\/", "[^\/]*\/", $check); //replace * in middle of URIs | |
$check = str_replace("+*", "+.*", $check); //replace * at end of URIs | |
$check = "/^" . $check . "\/?$/"; //add start/end / | |
if(preg_match($check, $uri)) | |
{ | |
wp_redirect(home_url()); | |
exit; | |
} | |
} | |
//redirect groups to the forum | |
$redirects = array( | |
"/groups/*", | |
"/groups/*/home", | |
"/groups/*/members", | |
); | |
foreach($redirects as $check) | |
{ | |
//prep for regex | |
$check = str_replace("/", "[\/]+", $check); //replace / | |
$check = str_replace("*", "([^\/]*)", $check); //replace * | |
$check = "/^" . $check . "\/?/"; //add start/end / | |
$matched = preg_match($check, $uri, $matches); | |
if(!empty($matches[1])) | |
{ | |
//but check if we're already on the forums | |
$new_uri = "/groups/" . $matches[1] . "/forum/"; | |
if(strpos($uri, $new_uri) === false) | |
{ | |
wp_redirect(home_url("/groups/" . $matches[1] . "/forum/")); | |
exit; | |
} | |
} | |
} | |
//lock some things for members only | |
$members_only = array( | |
"/members/", | |
); | |
foreach($members_only as $check) | |
{ | |
//prep for regex | |
$check = str_replace("/", "[\/]+", $check); //replace / | |
$check = str_replace("*\/", "[^\/]*\/", $check); //replace * in middle of URIs | |
$check = str_replace("+*", "+.*", $check); //replace * at end of URIs | |
$check = "/^" . $check . "\/?/"; //add start/end / | |
//make sure they are a member | |
if(preg_match($check, $uri) && !pmpro_hasMembershipLevel()) | |
{ | |
wp_redirect(pmpro_url("levels")); | |
exit; | |
} | |
} | |
} | |
add_action("init", "pmpros_hide_buddy_press_pages"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment