Created
February 12, 2026 08:12
-
-
Save dwanjuki/8ab3cdd77002e30d1ab09a4b1b60ae05 to your computer and use it in GitHub Desktop.
Redirect BuddyBoss/BuddyPress Profile pages to PMPro Member Directory Profile pages.
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 // copy from below. | |
| /** | |
| * Redirect BuddyBoss/BuddyPress Profile pages to PMPro Member Directory Profile pages. | |
| * | |
| * 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 my_buddypress_pmpromd_profiles_redirect() { | |
| global $pmpro_pages; | |
| // Bail if PMPro Member Directory Add On is inactive or profile page not set. | |
| if ( ! function_exists( 'pmpromd_build_profile_url' ) || empty( $pmpro_pages['profile'] ) ) { | |
| return; | |
| } | |
| // Bail if not a BuddyPress/BuddyBoss profile page. | |
| if ( ! bp_is_user_profile() ) { | |
| return; | |
| } | |
| // Get profile user ID. | |
| $profile_user_id = bp_displayed_user_id(); | |
| // Bail if the user is viewing their own BuddyPress profile page. | |
| if ( bp_loggedin_user_id() === $profile_user_id ) { | |
| return; | |
| } | |
| // Get the profile user's ID. | |
| $profile_user = get_user_by( 'ID', $profile_user_id ); | |
| // Get PMPro directory profile URL. | |
| $redirect_url = pmpromd_build_profile_url( $profile_user ); | |
| // Redirect to PMPro directory profile. | |
| if ( ! empty( $redirect_url ) ) { | |
| wp_redirect( $redirect_url ); | |
| exit; | |
| } | |
| } | |
| add_action( 'bp_template_redirect', 'my_buddypress_pmpromd_profiles_redirect' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment