benecaster_outlinks_health_item_action_before
Fires before Link Health writes one of its actions to one item: dismiss, restore, fix a URL, unlink, or track a link with Outlinks. It fires whether the action came from Settings → Link Health, a bulk selection there, or the POST /benecaster-outlinks/v1/link-health/actions route, once for each item a bulk request writes.
It fires once every check on the item has passed, immediately before the write. An item that is refused (not found, the wrong kind for the action, a post the user cannot edit, a link no longer in its post, a show where Outlinks is off, a link name already taken, an unusable URL) fires neither this hook nor benecaster_outlinks_health_item_action_after. For dismiss and restore, the items are written together, so every item’s before fires ahead of the one write.
$args depends on the action:
dismiss,restore:[]update_url:old_url,url(the cleaned new address) andpost_idunlink:urlandpost_idcreate_outlink:url(the link as it stands in the episode),post_id,show_id(the episode’s show) andslug(the cleaned link name)
Link Health is install-wide and needs Outlinks switched on for at least one show, so the hook never fires while Outlinks is off for every show or the licence has lapsed.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$action |
string |
— | `dismiss`, `restore`, `update_url`, `unlink` or `create_outlink` |
$item |
array |
— | `[ 'type' => 'site_link'|'redirect', 'id' => int ]`, the pair the actions route takes |
$args |
array |
— | What the action is about to write, by action as listed above |
Examples
Refuse nothing, but record who is about to unlink what
add_action( 'benecaster_outlinks_health_item_action_before', function ( string $action, array $item, array $args ): void {
if ( 'unlink' === $action ) {
error_log( sprintf( 'User %d is unlinking %s from post %d', get_current_user_id(), $args['url'], $args['post_id'] ) );
}
}, 10, 3 );
Notes
A write that fails after this hook (WordPress could not save the post, or the new link could not be created) fires no after. Walkthrough: Run your own code before and after each Link Health action.
Need this built rather than just documented? See our services →