Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewlimaza/f61f97989cdac363d041777072db56d2 to your computer and use it in GitHub Desktop.
Save andrewlimaza/f61f97989cdac363d041777072db56d2 to your computer and use it in GitHub Desktop.
Redirect non-members to 'Content Restricted' BuddyPress page for normal content.
<?php
/**
* Redirect non-members away from 'normal' content to BuddyPress content restricted page.
* Requires the BuddyPress Integration to be installed - https://www.paidmembershipspro.com/add-ons/buddypress-integration/
* Add this code to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
function my_template_redirect_require_membership_access() {
if ( ! pmpro_has_membership_access() && ! bp_current_component() && ! is_archive() && ! is_home() && function_exists( 'pmpro_bp_redirect_to_access_required_page' ) ) {
pmpro_bp_redirect_to_access_required_page();
}
}
add_action( 'template_redirect', 'my_template_redirect_require_membership_access' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment