Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronalfy/61863551bcee17ba2eb99a1c567d5918 to your computer and use it in GitHub Desktop.
Save ronalfy/61863551bcee17ba2eb99a1c567d5918 to your computer and use it in GitHub Desktop.
PMPro - Redirect Forum Archive - Login Page
<?php
/**
* Forwards non-logged-in-users going to /forums/ to the WordPress login URL.
*
* 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() {
if ( is_post_type_archive( 'forum' ) && ! is_user_logged_in() ) {
wp_safe_redirect( wp_login_url( home_url( '/forum/' ), true ) );
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