Run your own code when a Link Health check finishes, with everything it found broken
benecaster_outlinks_health_check_completed fires once per finished Link Health check, after old check history is pruned and after the Link Health notice and the email digest have been handled. A check that runs out of time carries on in a later request; the action fires only at the end of the request that finishes it. $finished_at is a Unix time.
$broken_items is everything Link Health counts as broken now, the same list the notice counts and the Outlinks tab’s summary line reads: [] when nothing is. Tracked links come first, then site links, each in id order. Every item has key (redirect:{id} or site_link:{id}, stable from run to run) and kind:
- a tracked link (
redirect; broken, not dismissed) also hasid,sluganddestination_url; - a site link (
site_link; last check broken, not dismissed, not on an excluded domain) also hasid,url,item_type(linkorimage),source_type(episode,pageorpost),source_id(the post) andhttp_status(null for no response).
Code
<?php
add_action( 'benecaster_outlinks_health_check_completed', function ( array $broken_items, int $finished_at ): void {
$redirects = array_filter( $broken_items, fn( array $item ): bool => 'redirect' === $item['kind'] );
wp_remote_post( 'https://status.example.com/hooks/link-health', [
'body' => wp_json_encode( [ 'at' => gmdate( 'c', $finished_at ), 'broken' => count( $broken_items ), 'tracked_links' => array_column( $redirects, 'slug' ) ] ),
] );
}, 10, 2 );
Hooks Used
Need this built rather than just documented? See our services →