Skip to main content

List what Link Health has found — broken, redirected, expired, dismissed — from code

Premium Intermediate

GET /benecaster-outlinks/v1/link-health/items is the route behind Settings → Link Health. It is install-wide: 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. It lists every item Link Health watches across every show, including shows where Outlinks is switched off, plus pages and posts, which belong to no show.

Query: source (redirect, episode, page or post; absent for all), show_id (absent or 0 for any; a show means its episodes and its tracked links only), status (broken when absent; redirected, expired, unchecked, excluded, healthy or all), dismissed (1 lists only dismissed items; otherwise they are left out), page (from 1) and per_page (1–100, default 50). An unknown value is 400 benecaster_outlinks_filter_invalid with data.field.

Answer: { items, total, page, per_page, shows }, with shows as { id, title }. Tracked links come first, then site links, each newest first. Each item has:

  • type (redirect or site_link) and id, the pair the actions route takes;
  • url, item_type (link or image), source, source_id (the post; null for a tracked link) and source_title (the post’s title, or a tracked link’s name);
  • go_url (a tracked link’s /go/ address) and edit_url (an episode’s opens Benecaster’s episode editor, a page’s or post’s the WordPress editor, a tracked link’s its show’s Outlinks tab);
  • show_id and show_title, status, http_status and consecutive_failures;
  • last_checked and first_detected (in the site’s date format), first_detected_at (ISO 8601 UTC), dismissed and converted.

A site link’s status comes from its last check: broken, redirected (a redirect that ended somewhere working), unchecked or healthy. A tracked link’s is healthy, broken, expired, unchecked or excluded.

Code

<?php
wp_set_current_user( 1 );
$request = new WP_REST_Request( 'GET', '/benecaster-outlinks/v1/link-health/items' );
$request->set_header( 'X-WP-Nonce', wp_create_nonce( 'wp_rest' ) );
$request->set_query_params( [ 'source' => 'episode', 'status' => 'broken', 'per_page' => 100 ] );
foreach ( rest_do_request( $request )->get_data()['items'] as $item ) {
    printf( "%s in %s (%s)\n", $item['url'], $item['source_title'], $item['http_status'] ?? 'no response' );
}

View on GitHub →

Need this built rather than just documented? See our services →