This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
get_edit_user_link filter
Filters the user edit link.
To use the get_edit_user_link filter, first you have to register it using add_filter. You can write this code into functions.php of your activated theme or in a custom WordPress Plugin.
We at WePlugins, always prefer to create a custom WordPress Plugin while using hooks so nothing breaks when you update your WordPress Theme in the future.
In the below live example, we have defined a function modify_get_edit_user_link_defaults which takes 2 parameters and we registered using add_filter. The first parameter get_edit_user_link is the name of the hook, the second parameter modify_get_edit_user_link_defaults is the name of the function which needs to be called, the third parameter is the priority of calling the hook if the same hook is used multiple times, and the last parameter is the number of arguments (if any) to be passed in the registered function.
Sometimes, you have to remove a registered hook so you can use remove_filter to remove the get_edit_user_link filter.
Parameters
- $link : (string) The edit link.
- $user_id : (int) User ID.
Below are the 2 parameters required to use this hook.
Live Example
apply_filters('get_edit_user_link', string $link, int $user_id)
Below is an example of how you can use this hook.
function weplugins_modify_get_edit_user_link_defaults($link, $user_id) { // Update the $link variable according to your website requirements and return this variable. You can modify the $link variable conditionally too if you want. return $link; } // add the filter add_filter("get_edit_user_link", "weplugins_modify_get_edit_user_link_defaults", 10, 2);
Example 1: Customize User Edit Link Based on User Role
In this example, we modify the user edit link based on the user’s role.
function weplugins_modify_get_edit_user_link_role($link, $user_id) { $user_info = get_userdata($user_id); if (in_array('administrator', $user_info->roles)) { $link = '/custom-admin-edit-link'; } return $link; } add_filter("get_edit_user_link", "weplugins_modify_get_edit_user_link_role", 10, 2);
Example 2: Append Query Parameter to Edit Link
This example demonstrates how to append a custom query parameter to the user edit link.
function weplugins_append_query_to_edit_link($link, $user_id) { return add_query_arg('ref', 'custom_param', $link); } add_filter("get_edit_user_link", "weplugins_append_query_to_edit_link", 10, 2);
Example 3: Conditional Link Based on User Meta
Here, we change the user edit link conditionally based on specific user meta.
function weplugins_conditional_edit_link($link, $user_id) { $meta_value = get_user_meta($user_id, 'custom_meta', true); if ($meta_value == 'special') { $link = '/special-edit-link'; } return $link; } add_filter("get_edit_user_link", "weplugins_conditional_edit_link", 10, 2);
To remove a hook callback, use the example below.
remove_filter("get_edit_user_link", "weplugins_modify_get_edit_user_link_defaults", 10, 2);
Please make sure to provide the same callback function name, priority, and number of arguments while removing the hook callback.
If you’re having any trouble using this hook, please Contact Us and we’d be happy to assist you.
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.