Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: One profile page to rule them all

This hack redirects non-editing users from their WordPress profile to their forum profile. Set $my_forums_directory to the directory or URL of the forums, and save it as a WordPress plugin.

Sometimes the page headers have already been sent, so wp_redirect() can’t be relied on, and instead the HTML has to perform the redirect.

WordPress users that can edit posts will still see the normal WordPress user screens. Since these screens don’t integrate well, it might be sensible to redirect admin users to /forums/bb-admin/users.php – but I’ve not done that here.

add_action('admin_head', 'my_wp_profile_redirect', 0);

function my_wp_profile_redirect() {
// Based on a part of Kim Parsell's https://wordpress.org/extend/plugins/wp-hide-dashboard/
global $parent_file, $current_user, $user_login;
$my_forums_directory = "/forums/"; // Set this to the directory or URL of the forums.
if (!current_user_can('edit_posts') && $parent_file == 'users.php') {
$my_profile_destination = $my_forums_directory."profile/".esc_attr( str_replace( " ", "-", strtolower( $user_login ) ) )."/edit";
if (!headers_sent()) {
wp_redirect($my_profile_destination);
} else {
echo '<meta http-equiv="refresh" content="0; url='.$my_profile_destination.'"><script type="text/javascript">document.location.href="'.$my_profile_destination.'"</script></head>';
echo '<body><a href="'.$my_profile_destination.'">View profile</a></body></html>';
}
exit();
}
}

Skip to toolbar