Created
February 23, 2022 10:54
-
-
Save ipokkel/9d128e4e352f1b847364de742fe69119 to your computer and use it in GitHub Desktop.
Redirect non-members from bbPress forums page. #pmpro #bbpress
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 | |
| /** | |
| * Redirects all non-members from the forums page. | |
| * | |
| * This recipe requires bbPress and Paid Memberships Pro plugins. | |
| * | |
| * You can add this recipe to your site by creating a custom plugin | |
| * or using the Code Snippets plugin available for free in the WordPress repository. | |
| * Read this companion article for step-by-step directions on either method. | |
| * https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
| */ | |
| function pmpro_maybe_redirect_bbpress_forums_archive() { | |
| // Let's only do this if bbPress & PMPro is active | |
| if ( ! function_exists( 'bbp_is_forum_archive' ) || ! function_exists( 'pmpro_hasMembershipLevel' ) ) { | |
| return; | |
| } | |
| // Let's check if we're on the bbPress forums archive page. | |
| if ( bbp_is_forum_archive() && ! pmpro_hasMembershipLevel() ) { | |
| // Redirect the user to the membership levels page. | |
| wp_safe_redirect( pmpro_url( 'levels' ) ); | |
| exit; | |
| } | |
| } | |
| add_action( 'template_redirect', 'pmpro_maybe_redirect_bbpress_forums_archive' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment