Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/94edb917c37e166c380aae6d3a4d4af6 to your computer and use it in GitHub Desktop.
Save kimcoleman/94edb917c37e166c380aae6d3a4d4af6 to your computer and use it in GitHub Desktop.
Redirect the Member's Profile page to the bbPress User Profile when using the Member Directory and Profile Pages Add On for Paid Memberships Pro
<?php
/**
* Use this recipe to redirect the Profile page as defined under Memberships > Page Settings to the member's
* bbPress User Profile when using the Member Directory and Profile Pages Add On in conjunction with bbPress.
*
* You must set a placeholder page under Memberships > Page Settings > Profile in order for this redirect to work.
*/
function redirect_profile_page_to_bbpress_user_profile() {
global $pmpro_pages;
if ( ! empty( $pmpro_pages ) && ! empty( $pmpro_pages['profile'] ) && is_page( $pmpro_pages['profile'] ) ) {
$pu = sanitize_text_field( $_REQUEST['pu'] );
if ( ! empty( $pu ) ) {
$user = get_user_by( 'login', $pu );
if ( $user ) {
$user_profile_link = bbp_get_user_profile_url( $user->ID );
}
} else {
$user_profile_link = bbp_get_user_profile_url( get_current_user_id() );
}
wp_redirect( $user_profile_link );
exit;
}
}
add_action( 'template_redirect', 'redirect_profile_page_to_bbpress_user_profile' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment