Created
October 12, 2020 15:03
-
-
Save ronalfy/61863551bcee17ba2eb99a1c567d5918 to your computer and use it in GitHub Desktop.
PMPro - Redirect Forum Archive - Login Page
This file contains 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 | |
/** | |
* 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