Last active
December 23, 2024 18:20
-
-
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).
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 | |
/** | |
* Redirect the main user page parent to a custom page. | |
*/ | |
function my_pmproup_wp_parent_page_redirect() { | |
global $wpdb, $post, $current_user; | |
// Return early if the User Pages Add On is not active. | |
if ( ! function_exists( 'pmproup_getOptions' ) ) { | |
return; | |
} | |
$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