Skip to content

Instantly share code, notes, and snippets.

@ipokkel
Created February 23, 2022 10:54
Show Gist options
  • Save ipokkel/9d128e4e352f1b847364de742fe69119 to your computer and use it in GitHub Desktop.
Save ipokkel/9d128e4e352f1b847364de742fe69119 to your computer and use it in GitHub Desktop.
Redirect non-members from bbPress forums page. #pmpro #bbpress
<?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