Using WordPress ‘edit_link’ PHP action

The edit_link WordPress action fires after a link was updated in the database.

Usage

add_action('edit_link', 'your_custom_function');
function your_custom_function($link_id) {
    // your custom code here
}

Parameters

  • $link_id (int) – ID of the link that was updated.

More information

See WordPress Developer Resources: edit_link

Examples

Log when a link is updated, for auditing purposes.

add_action('edit_link', 'log_link_updates');
function log_link_updates($link_id) {
    error_log("Link ID {$link_id} has been updated.");
}

Send email notifications to a list of users when a link is updated.

add_action('edit_link', 'notify_users_about_link_updates');
function notify_users_about_link_updates($link_id) {
    $users = get_users(); // Get all users
    $link = get_bookmark($link_id); // Get the updated link details
    $subject = "Link Updated: {$link->link_name}";

    foreach ($users as $user) {
        wp_mail($user->user_email, $subject, "The link '{$link->link_name}' has been updated.");
    }
}

Update custom metadata

Update custom metadata associated with the link when it’s updated.

add_action('edit_link', 'update_custom_metadata_on_link_update');
function update_custom_metadata_on_link_update($link_id) {
    update_metadata('link', $link_id, 'custom_meta_key', 'custom_meta_value');
}

Perform a custom action if the updated link belongs to a specific category.

add_action('edit_link', 'custom_action_based_on_link_category');
function custom_action_based_on_link_category($link_id) {
    $link = get_bookmark($link_id);
    if (in_array('specific-category', $link->link_category)) {
        // your custom code here
    }
}

Invalidate cache for a specific page when a link is updated.

add_action('edit_link', 'invalidate_cache_on_link_update');
function invalidate_cache_on_link_update($link_id) {
    wp_cache_delete('specific_cache_key', 'group');
}