Please or Register to create posts and topics.

specified user role for profile page login

Hi, guys

After input your code,  it works on my site, all users can only visit a /my-edit-profile-page/ to edit the profile, but…

Could anyone please modify the code for me to restrict the function only works on specified user role, such as only forum subscribers instead of site admin? Thanks.

https://asgaros.com/support/topic/change-urls-login-register-profile-etc/

Change Edit Profile URL

add_filter('edit_profile_url', 'my_edit_profile_url', 10, 3);

function my_edit_profile_url($url, $user_id, $scheme) {
    return home_url('/my-edit-profile-page/'.$user_id);
}

 


Hello @aa276

You can try to use the following code:

function my_edit_profile_url($url, $user_id, $scheme) {
    if (current_user_can('manage_options')) {
        return $url;
    } else {
        return home_url('/my-edit-profile-page/'.$user_id);
    }
}

 

aa276 has reacted to this post.
aa276
If you want to support the development of Asgaros Forum, you can leave a good review or donate. Thank you very much!

I update it with the new code below. It works. The admin can visit the profile edit page (back end), but the normal user can only use the ‘/my-edit-profile-page/’ page to edit their profile.

It also changes the front user profile “edit profile” link to /my-edit-profile-page/ page. I will keep testing the site. So far so good.

Thank you so much.

Here is the full code I used.

add_filter(‘edit_profile_url’, ‘my_edit_profile_url’, 10, 3);
function my_edit_profile_url($url, $user_id, $scheme) {
if (current_user_can(‘manage_options’)) {
return $url;
} else {
return home_url(‘/my-edit-profile-page/’.$user_id);
}
}