Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Last active May 14, 2024 17:34
Show Gist options
  • Save kimcoleman/e439e927aa282d88f428503d96006e89 to your computer and use it in GitHub Desktop.
Save kimcoleman/e439e927aa282d88f428503d96006e89 to your computer and use it in GitHub Desktop.
Redirect the Top Level User Page (parent page of all user pages) to a custom page (not the homepage, which is default for non-admins in the User Pages Add On).
<?php
/**
* Redirect the main user page parent to a custom page.
*/
function my_pmproup_wp_parent_page_redirect() {
global $wpdb, $post, $current_user;
$options = pmproup_getOptions();
if ( ! is_admin() && ! empty($post) && ! empty($options['parent_page'] ) && $post->ID == $options['parent_page'] ) {
if ( ! current_user_can( "manage_options" ) ) {
$user_page_id = pmproup_get_page_for_user( $current_user->ID );
if ( ! empty( $user_page_id ) ) {
//redirect to the user's user page
wp_redirect(get_permalink($user_page_id));
exit;
} else {
//redirect to a custom page
wp_redirect( pmpro_url( 'levels' ) );
exit;
}
}
}
}
add_action( 'wp', 'my_pmproup_wp_parent_page_redirect', 9 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment