specified user role for profile page login
Quote from aa276 on August 19, 2019, 8:04 pmHi, 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); }
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); }
Quote from Asgaros on August 20, 2019, 7:16 amHello @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); } }
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); } }
Quote from aa276 on August 20, 2019, 8:27 pmI 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);
}
}
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);
}
}