Dismiss, fix, unlink or track Link Health items from code, one at a time or in bulk
POST /benecaster-outlinks/v1/link-health/actions is the route behind Link Health’s per-item and bulk actions. It is install-wide, with no show in the path: it needs manage_options (an X-WP-Nonce for wp_rest) and Outlinks on for at least one show, else 403 benecaster_outlinks_not_active.
The body carries action (dismiss, restore, update_url, unlink or create_outlink) and items, a list of { type: 'site_link'|'redirect', id } (1 to 200, exactly one for create_outlink), plus url for update_url and slug for create_outlink. A malformed body is 400 benecaster_outlinks_action_invalid with data.field. Otherwise the answer is always 200 { results }, one result per item in the order sent, each with type, id and ok, and code and message when it failed. A bulk action is not all-or-nothing, so read every ok.
| Action | Applies to | What it does |
|---|---|---|
dismiss / restore |
any item | Hides the item from the broken lists and counts until it is restored. It is still checked. No post is edited. |
update_url |
site links | Points every link or image in the item’s post that uses the item’s URL at url, in the content (a revision is kept) and, for an episode, in its RSS description. The item becomes unchecked; the result carries the cleaned url. |
unlink |
site links that are links | Removes every link to the URL in the post, keeping its text. The item leaves Link Health. |
create_outlink |
one link in an episode | Creates a standalone tracked link in the episode’s show (which must have Outlinks on itself) with the link’s URL as its destination, and points the link in the episode at its /go/{slug}?ep={episode} address. The result carries redirect: { id, slug, go_url, destination_url }. |
Only the matching attribute or tags change in a post; the rest of its HTML is left byte for byte.
Code
<?php
wp_set_current_user( 1 );
$request = new WP_REST_Request( 'POST', '/benecaster-outlinks/v1/link-health/actions' );
$request->set_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );
$request->set_body_params( [
'action' => 'update_url',
'items' => [ [ 'type' => 'site_link', 'id' => 41 ], [ 'type' => 'site_link', 'id' => 42 ] ],
'url' => 'https://example.com/new-page',
] );
foreach ( rest_do_request( $request )->get_data()['results'] as $result ) {
if ( ! $result['ok'] ) {
error_log( "Item {$result['id']}: {$result['code']}" );
}
}
Need this built rather than just documented? See our services →