Skip to main content

Run your own code when Link Health’s schedule or exclusions are saved

Premium Intermediate

Two before/after pairs fire when the Schedule and Exclusions forms on Settings → Link Health are saved, or when their routes are called (schedule, exclusions). Each pair fires only for a request that sends at least one of its route’s fields and passes validation: before immediately before the save, after once the save is done. A refused request (400, where nothing is saved) fires nothing, and so does a request with none of the fields. A field sent with the value already saved still fires.

  • benecaster_outlinks_health_settings_save_before ( array $changes, array $previous ): $changes holds only the keys sent, check_frequency (weekly or daily) and/or digest_frequency (weekly, daily or off). $previous is { check_frequency, digest_frequency } before the save.
  • benecaster_outlinks_health_settings_save_after ( array $settings, array $previous ): $settings is { check_frequency, digest_frequency } as saved, after a changed check frequency has rescheduled the check.
  • benecaster_outlinks_health_exclusions_save_before ( array $exclusions, array $previous ): both are { domains, post_types, categories }. $exclusions holds the cleaned lists about to be saved (domains lower case without www., a pasted URL reduced to its host; post types from episode, page and post; categories as term ids), $previous the lists saved until now. A list the request did not send is the same in both.
  • benecaster_outlinks_health_exclusions_save_after ( array $exclusions, array $previous, int $removed ): after the save, once the items the new exclusions cover have left Link Health; $removed is how many.

Code

<?php
add_action( 'benecaster_outlinks_health_exclusions_save_after', function ( array $exclusions, array $previous, int $removed ): void {
    $added = array_diff( $exclusions['domains'], $previous['domains'] );
    if ( [] !== $added ) {
        error_log( sprintf( 'Link Health now skips %s (%d items removed)', implode( ', ', $added ), $removed ) );
    }
}, 10, 3 );

View on GitHub →

Hooks Used

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