Using WordPress ‘get_edit_user_link’ PHP filter

The get_edit_user_link WordPress PHP filter allows you to modify the user edit link.

Usage

add_filter('get_edit_user_link', 'your_function_name', 10, 2);

function your_function_name($link, $user_id) {
    // your custom code here
    return $link;
}

Parameters

  • $link (string) – The user edit link.
  • $user_id (int) – User ID.

More information

See WordPress Developer Resources: get_edit_user_link

Examples

Modify the user edit link to redirect to a custom admin page instead of the default WordPress user edit page.

add_filter('get_edit_user_link', 'change_edit_user_link', 10, 2);

function change_edit_user_link($link, $user_id) {
    return admin_url('admin.php?page=custom_user_edit&user_id=' . $user_id);
}

Add a tracking parameter to the user edit link for tracking purposes.

add_filter('get_edit_user_link', 'add_tracking_to_user_link', 10, 2);

function add_tracking_to_user_link($link, $user_id) {
    return add_query_arg('utm_source', 'your_source', $link);
}

Prevent users with specific roles from having an edit link.

add_filter('get_edit_user_link', 'remove_edit_link_for_roles', 10, 2);

function remove_edit_link_for_roles($link, $user_id) {
    $user = get_userdata($user_id);

    if (in_array('subscriber', $user->roles)) {
        return '';
    }

    return $link;
}

Change the user edit link based on a custom user meta value.

add_filter('get_edit_user_link', 'modify_link_based_on_user_meta', 10, 2);

function modify_link_based_on_user_meta($link, $user_id) {
    $custom_meta = get_user_meta($user_id, 'your_custom_meta', true);

    if ('special_value' === $custom_meta) {
        return admin_url('admin.php?page=special_edit_user&user_id=' . $user_id);
    }

    return $link;
}

Add a custom CSS class to the edit user link for styling purposes.

add_filter('get_edit_user_link', 'add_custom_css_class_to_link', 10, 2);

function add_custom_css_class_to_link($link, $user_id) {
    return str_replace('<a ', '<a class="your-custom-class" ', $link);
}