Run your own code before and after each Link Health action — dismiss, restore, fix a URL, unlink, track
benecaster_outlinks_health_item_action_before and benecaster_outlinks_health_item_action_after fire once per item, whether the action came from the Link Health page, a bulk selection or the actions route. A bulk request fires them once for each item it writes.
beforefires once every check on the item has passed, immediately before its write. An item that is refused (not found, the wrong kind for the action, noedit_poston its post, the link no longer in the post, a show where Outlinks is off, a name already taken, an unusable URL) fires neither hook. A malformed request (400) fires nothing.afterfires only when the item succeeded.$resultis that item’s row from the route’s answer:okistrue,update_urladdsurl, andcreate_outlinkaddsredirect: { id, slug, go_url, destination_url }. A write that fails afterbefore(WordPress could not save the post, or the new link could not be created) firesbeforewith noafter.- For
dismissandrestorethe items are written together, so every item’sbeforefires ahead of the one write and everyafterfollows it.
$item is [ 'type' => 'site_link'|'redirect', 'id' => int ]. $args depends on the action:
$action |
$args |
|---|---|
dismiss, restore |
[] |
update_url |
old_url, url (the cleaned new address), post_id |
unlink |
url, post_id |
create_outlink |
url (the link as it stands in the episode), post_id, show_id (the episode’s show), slug (the cleaned link name) |
Code
<?php
add_action( 'benecaster_outlinks_health_item_action_after', function ( string $action, array $item, array $args, array $result ): void {
if ( 'update_url' === $action ) {
error_log( sprintf( 'Link Health: post %d now links to %s instead of %s', $args['post_id'], $args['url'], $args['old_url'] ) );
}
}, 10, 4 );
Hooks Used
Need this built rather than just documented? See our services →