Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save eighty20results/117e55037df2031dd1e0efdf9d2c04dd to your computer and use it in GitHub Desktop.
Save eighty20results/117e55037df2031dd1e0efdf9d2c04dd to your computer and use it in GitHub Desktop.
Limit access to BuddyPress components for users without a valid Paid Memberships Pro membership level
<?php
/*
Plugin Name: PMPro/BuddyPress members only access
Plugin URI: http://www.paidmembershipspro.com/wp/pmpro-customizations/
Description: Limit access to BuddyPress pages/components for non-members.
Version: .1
Author: Thomas Sjolshagen @ Stranger Studios <thomas@eighty20results.com>
Author URI: http://www.eighty20results.com/thomas-sjolshagen
*/
function pmpro_buddypress_restrict_page_access() {
global $pmpro_pages;
global $bp;
if ( bp_is_activity_component() ||
bp_is_groups_component() /*|| bbp_is_single_forum()*/ ||
bp_is_forums_component() ||
bp_is_blogs_component() ||
bp_is_page( BP_MEMBERS_SLUG ) ) {
if( false == pmpro_hasMembershipLevel() ) {
// send to the levels page if the user doesn't have a valid membership
wp_redirect( get_permalink( $pmpro_pages['levels'] ) );
}
}
}
add_filter('get_header','pmpro_buddypress_restrict_page_access', 1 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment