Broken Link Notifier

The Broken Link Notifier plugin has some useful hooks for developers to use to further enhance its functionality.

TYPE ⇢ Filter

This filter allows developers to modify the array of HTML elements and their respective attributes that are treated as link sources. By default, the a, iframe, and video elements are considered link sources with their href and src attributes. Additionally, the img tag's src attribute is added by default only if the relevant setting (blnotifier_include_images) is enabled. This gives developers flexibility to extend or modify which HTML tags and attributes are recognized as valid link sources in the plugin.

Example Usage

PHP
/**
 * Add the 'audio' tag as a valid link source.
 *
 * @param array $el → The default array of HTML elements and their link attributes.
 *
 * @return array → The modified array with the 'audio' tag added.
 */
add_filter( 'blnotifier_html_link_sources', function( $el ) {
    // Add 'audio' tag with 'src' attribute as a link source.
    $el[ 'audio' ] = 'src';
    
    return $el;
}, 10 );

blnotifier_omitted_pageload_post_types

TYPE ⇢ Filter

This filter allows developers to adjust the list of post types that should be excluded from page load scans. By default, this list mirrors the omitted Multi-Scan post types, but the filter allows it to diverge for more granular control over scan behavior.

Example Usage

PHP
/**
 * Exclude a post type from page load scans without affecting Multi-Scans.
 *
 * @param array $post_types → Default list of omitted post types for page loads.
 *
 * @return array → Modified list with 'another_type' added.
 */
add_filter( 'blnotifier_omitted_pageload_post_types', function( $post_types ) {
    $post_types[] = 'another_type';
    return $post_types;
}, 10 );

blnotifier_omitted_multiscan_post_types

TYPE ⇢ Filter

This filter lets developers modify the list of post types that are omitted from Multi-Scan operations. By default, the plugin calculates omitted post types by comparing all registered post types to the list of explicitly allowed ones. This filter provides a way to manually override or append additional omissions.

Example Usage

PHP
/**
 * Add a custom post type to the list of omitted post types during Multi-Scan.
 *
 * @param array $omitted → Default list of omitted post types.
 *
 * @return array → Modified list with 'custom_type' excluded.
 */
add_filter( 'blnotifier_omitted_multiscan_post_types', function( $omitted ) {
    $omitted[] = 'custom_type';
    return $omitted;
}, 10 );

TYPE ⇢ Filter

This filter allows developers to intercept and modify a URL before Broken Link Notifier performs any checks. It can be used to skip specific links, preprocess them, or return a fully custom status array to override the default check logic.

Example Usage

PHP
/**
 * Skip links containing a specific query string before link checks.
 *
 * @param string|array $link The original link to be checked.
 *
 * @return string|array Modified link or structured status array.
 */
add_filter( 'blnotifier_link_before_prechecks', function( $link ) {
    // Skip UTM tracking links
    if ( is_string( $link ) && strpos( $link, 'utm_' ) !== false ) {
        return [
            'type' => 'good',
            'code' => 200,
            'text' => 'Skipped due to tracking params',
            'link' => $link
        ];
    }

    return $link;
}, 10 );

blnotifier_status

TYPE ⇢ Filter

This filter allows you to customize or override the final status of a scanned URL after an HTTP request has been made. It’s useful for reclassifying response codes, customizing messages, or flagging edge cases that aren't handled by default. Accepted types include: ommitted, good, warning, and broken. All codes are listed in the plugin's Settings on the bottom.

Example Usage

PHP
/**
 * Skip links containing a specific query string before link checks.
 *
 * @param string|array $link The original link to be checked.
 *
 * @return string|array Modified link or structured status array.
 */
add_filter( 'blnotifier_link_before_prechecks', function( $link ) {
    // Skip UTM tracking links
    if ( is_string( $link ) && strpos( $link, 'utm_' ) !== false ) {
        return [
            'type' => 'ommitted',
            'code' => 200,
            'text' => 'Skipped due to tracking params',
            'link' => $link
        ];
    }

    return $link;
}, 10 );

blnotifier_http_request_args

TYPE ⇢ Filter

This filter allows you to customize the arguments used in the HTTP request to check a URL's status. It’s particularly useful for adjusting timeouts, setting custom headers, or controlling SSL verification behavior when making the request.

Example Usage

PHP
/**
 * Modify the HTTP request arguments for checking links.
 *
 * @param array  $http_request_args The HTTP request arguments.
 * @param string $url               The URL being checked.
 *
 * @return array The modified HTTP request arguments.
 */
add_filter( 'blnotifier_http_request_args', function( $http_request_args, $url ) {
    // Change the timeout for specific URLs
    if ( strpos( $url, 'example.com' ) !== false ) {
        $http_request_args[ 'timeout' ] = 10;  // Set timeout to 10 seconds
    }

    // Add a custom user-agent for a specific domain
    if ( strpos( $url, 'anotherdomain.com' ) !== false ) {
        $http_request_args[ 'user-agent' ] = 'Custom User-Agent';
    }

    return $http_request_args;
}, 10, 2 );

blnotifier_remove_source_qs

TYPE ⇢ Filter

This filter allows you to modify or extend the list of query strings that should be removed from a source URL in the results. By default, it includes common tracking query strings like utm_*, but you can use this filter to add or remove any query parameters that should be stripped for the source URL.

Example Usage

PHP
/**
 * Add custom query strings to be removed from the source URL.
 *
 * @param array $qs The default query strings to remove.
 *
 * @return array Modified list of query strings to remove.
 */
add_filter( 'blnotifier_remove_source_qs', function( $qs ) {
    // Add a custom query string to remove
    $qs[] = 'custom_tracking_param';

    return $qs;
} );

blnotifier_url_schemes

TYPE ⇢ Filter

This filter allows you to modify or extend the list of URL schemes that are ignored during the pre-check. By default, it includes a long list of both official and unofficial schemes that are not typically relevant for HTTP URL checks. You can use this filter to add custom schemes that you want to exclude from being processed or detected.

Example Usage

PHP
/**
 * Add custom URL schemes to be ignored in the pre-check.
 *
 * @param array $schemes The default URL schemes to ignore.
 *
 * @return array Modified list of schemes to ignore.
 */
add_filter( 'blnotifier_url_schemes', function( $schemes ) {
    // Add a custom scheme to ignore
    $schemes[] = 'customscheme';
    
    return $schemes;
} );

blnotifier_capability

TYPE ⇢ Filter

This filter allows you to modify the required capability for accessing the plugin's settings page in the WordPress admin menu. By default, it uses the manage_options capability, which is typically granted to administrators. You can use this filter to adjust access control, for instance, allowing certain user roles to access the plugin's settings page.

Example Usage

PHP
/**
 * Modify the capability required to access the plugin settings.
 *
 * @param string $capability The current capability required to access the settings page.
 *
 * @return string Modified capability.
 */
add_filter( 'blnotifier_capability', function( $capability ) {
    // Change the capability to 'edit_posts' so editors can access the settings
    return 'edit_posts';
} );

blnotifier_suggested_offsite_checkers

TYPE ⇢ Filter

This filter allows you to modify the list of suggested offsite broken link checkers on the Multi-Scan page. These are third-party tools recommended for users to check their websites for broken links. The default list includes popular services like Dead Link Checker, Dr Link Check, and Sitechecker. You can use this filter to add, remove, or modify the suggested tools as needed.

Example Usage

PHP
/**
 * Modify the list of suggested offsite broken link checkers.
 *
 * @param array $links The current list of suggested offsite checkers.
 *
 * @return array Modified list of suggested offsite checkers.
 */
add_filter( 'blnotifier_suggested_offsite_checkers', function( $links ) {
    // Add a new checker to the list
    $links[ 'Broken Link Checker' ] = 'https://www.brokenlinkcheck.com/';

    // Remove the 'Dr Link Check' checker
    unset( $links[ 'Dr Link Check' ] );

    return $links;
} );

blnotifier_notify

TYPE ⇢ Action

This action hook is triggered when broken links are found and notifications are sent out. It provides an opportunity to perform additional actions, such as logging, sending custom notifications, or integrating with other systems. The hook passes the necessary data such as flagged links, the count of broken links, the list of all links, and the source URL.

Example Usage

PHP
/**
 * Custom action when broken links are found.
 *
 * @param array $flagged An array of the flagged links categorized by type.
 * @param int $flagged_count The count of broken links.
 * @param array $all_links The complete list of all links.
 * @param string $source_url The URL where the broken links were found.
 *
 * @return void
 */
add_action( 'blnotifier_notify', function( $flagged, $flagged_count, $all_links, $source_url ) {
    // Log the broken links to a custom log file
    if ( $flagged_count > 0 ) {
        $log = fopen( 'broken-links-log.txt', 'a' );
        fwrite( $log, "Broken links found on: " . $source_url . "\n" );
        foreach ( $flagged as $key => $section ) {
            foreach ( $section as $f ) {
                if ( $f[ 'type' ] == 'broken' ) {
                    fwrite( $log, "URL: " . $f[ 'link' ] . " - Status Code: " . $f[ 'code' ] . " - " . $f[ 'text' ] . "\n" );
                }
            }
        }
        fclose( $log );
    }
} );

blnotifier_email_emails

TYPE ⇢ Filter

This filter allows modification of the list of email addresses to which notifications are sent when broken links are found. You can add or modify email addresses before the notification is sent.

Example Usage

PHP
/**
 * Modify the email recipients for broken link notifications.
 *
 * @param string $emails The email addresses to send notifications to.
 * @param array $flagged An associative array of flagged links organized by source section (e.g., header, content, footer). Each item contains arrays of link data with type, code, text, and link keys.
 * @param string $source_url The URL where the broken links were found.
 *
 * @return string The modified list of email addresses.
 */
add_filter( 'blnotifier_email_emails', function( $emails, $flagged, $source_url ) {
    // Add a custom email recipient
    $emails .= ', custom@example.com';
    return $emails;
}, 10, 3 );

blnotifier_email_subject

TYPE ⇢ Filter

This filter allows modification of the subject line for the email notification sent when broken links are found. You can change the subject dynamically based on the flagged links or source URL.

Example Usage

PHP
/**
 * Modify the subject of the email for broken link notifications.
 *
 * @param string $subject The subject of the email.
 * @param array $flagged An associative array of flagged links organized by source section (e.g., header, content, footer). Each item contains arrays of link data with type, code, text, and link keys.
 * @param string $source_url The URL where the broken links were found.
 *
 * @return string The modified email subject.
 */
add_filter( 'blnotifier_email_subject', function( $subject, $flagged, $source_url ) {
    // Append the source URL to the subject
    $subject .= ' - ' . $source_url;
    return $subject;
}, 10, 3 );

blnotifier_email_message

TYPE ⇢ Filter

This filter allows modification of the email message body sent when broken links are found. You can customize the content of the email before it is sent.

Example Usage

PHP
/**
 * Modify the content of the email for broken link notifications.
 *
 * @param string $message The email message content.
 * @param array $flagged An associative array of flagged links organized by source section (e.g., header, content, footer). Each item contains arrays of link data with type, code, text, and link keys.
 * @param string $source_url The URL where the broken links were found.
 *
 * @return string The modified email message.
 */
add_filter( 'blnotifier_email_message', function( $message, $flagged, $source_url ) {
    // Add a custom note at the end of the email
    $message .= '<br><br><em>Please address these issues at your earliest convenience.</em>';
    return $message;
}, 10, 3 );

blnotifier_email_headers

TYPE ⇢ Filter

This filter allows modification of the email headers before the notification email is sent. You can add custom headers or modify existing ones.

Example Usage

PHP
/**
 * Modify the headers for the email for broken link notifications.
 *
 * @param array $headers The email headers.
 * @param array $flagged An associative array of flagged links organized by source section (e.g., header, content, footer). Each item contains arrays of link data with type, code, text, and link keys.
 * @param string $source_url The URL where the broken links were found.
 *
 * @return array The modified email headers.
 */
add_filter( 'blnotifier_email_headers', function( $headers, $flagged, $source_url ) {
    // Add a custom header
    $headers[] = 'X-Custom-Header: Broken Links Notification';
    return $headers;
}, 10, 3 );

blnotifier_discord_args

TYPE ⇢ Filter

Filter the arguments sent to the Discord webhook when broken links are detected. Use this hook if you want to customize the structure, content, or metadata of the Discord notification — such as title, embed styling, message body, or individual link fields.

Structure of $discord_args:

PHP
$discord_args = [
    'msg'            => '',                                         // Optional plain text message
    'embed'          => true,                                       // Enable Discord embed layout
    'author_name'    => 'Source: '.$source_url,                     // Author header
    'author_url'     => $source_url,                                // Link for author name
    'title'          => get_bloginfo( 'name' ),                     // Site title
    'title_url'      => home_url(),                                 // Link for title
    'desc'           => '-------------------',                      // Description line (or separator)
    'img_url'        => '',                                         // Optional image to display
    'thumbnail_url'  => '',                                         // Optional thumbnail
    'disable_footer' => false,                                      // Hide default footer
    'bot_avatar_url' => BLNOTIFIER_PLUGIN_IMG_PATH.'logo-teal.png', // Bot avatar image
    'bot_name'       => BLNOTIFIER_NAME,                            // Bot name
    'fields'         => [                                           // Embed fields (each broken link gets one)
        [
            'name'   => 'Broken Link:',
            'value'  => 'https://example.com/link
            Status Code: 404 - Not Found',
            'inline' => false
        ],
        ...
    ]
]

Example Usage

PHP
/**
 * Customize the Discord notification arguments.
 *
 * @param array  $args        The default Discord arguments used for the webhook.
 * @param array  $flagged     Flagged links organized by section (header, content, footer). 
 *                            Each entry includes 'type', 'code', 'text', and 'link'.
 * @param string $source_url  The URL of the source page where links were checked.
 * 
 * @return array Modified arguments to send to the Discord webhook.
 */
add_filter( 'blnotifier_discord_args', function( $args, $flagged, $source_url ) {
    $args[ 'title' ] = '⚠️ Broken Links Reported';
    $args[ 'desc' ] = 'Detected on: ' . gmdate( 'Y-m-d H:i:s' );
    $args[ 'bot_name' ] = 'LinkBot 3000';
    return $args;
}, 10, 3 );

blnotifier_msteams_args

TYPE ⇢ Filter

Filter the data sent to the Microsoft Teams webhook when broken links are found. This hook allows developers to customize the payload sent to MS Teams, including the title, message, source, and individual link facts.

Structure of $msteams_args:

PHP
$msteams_args = [
    'site_name'   => get_bloginfo( 'name' ),                    // Name of the WordPress site.
    'title'       => 'Broken Links Found',                      // Title shown on the MS Teams card.
    'msg'         => 'The following broken links were found:',  // Intro message.
    'img_url'     => '',                                        // Optional image URL (not used by default).
    'source_url'  => $source_url,                               // URL of the page that was scanned.
    'facts'       => [                                          // Array of broken link details.
        [
            'name'  => 'Broken Link:',                          // Always "Broken Link:"
            'value' => '[URL](URL) \
            _Status Code: **CODE** - TEXT_',                    // Markdown-formatted info
        ],
        // ... more facts as needed
    ]
];

Example Usage

PHP
/**
 * Modify MS Teams arguments before sending webhook.
 *
 * @param array  $args        The default MS Teams arguments.
 * @param array  $flagged     Flagged links grouped by section.
 * @param string $source_url  The URL being scanned.
 *
 * @return array Modified MS Teams arguments.
 */
add_filter( 'blnotifier_msteams_args', function( $args, $flagged, $source_url ) {
    $args[ 'title' ] = '🚨 Link Check Alert';
    $args[ 'msg' ] = 'Broken links were discovered on your site.';
    $args[ 'facts' ][] = [
        'name'  => 'Total Issues Found',
        'value' => strval( array_sum( array_map( 'count', $flagged ) ) ),
    ];
    $args[ 'facts' ][] = [
        'name'  => 'Scan Date',
        'value' => gmdate( 'Y-m-d H:i:s' ),
    ];

    return $args;
}, 10, 3 );

blnotifier_strings_to_replace

TYPE ⇢ Filter

Allows customization of the string replacements that are applied to scanned links before (and optionally after) processing. This is useful for replacing problematic characters or symbols in URLs with sanitized equivalents and vice versa.

Example Usage

PHP
/**
 * Modify string replacements for link scanning
 *
 * Replace en dashes or weird encodings that might show up in URLs
 *
 * @param array $replacements List of character replacements.
 * @return array Modified list of replacements.
 */
add_filter( 'blnotifier_strings_to_replace', function( $replacements ) {
    $replacements[ '–' ] = '-';       // En dash
    $replacements[ '%' ] = '%';      // Full-width percent sign
    $replacements[ '&' ] = '&';      // Full-width ampersand
    return $replacements;
} );

blnotifier_force_head_file_types

TYPE ⇢ Filter

Customize which file types should force a HEAD request when scanned. This helps avoid unnecessary data transfer for large assets like images, videos, and documents during link checking.

Example Usage

PHP
/**
 * Add custom file types that should use HEAD requests during link checking
 *
 * @param array $file_types List of file extensions that should be checked via HEAD.
 * @param bool  $docs_use_head Whether document extensions are currently enabled.
 * @return array Modified list of extensions.
 */
add_filter( 'blnotifier_force_head_file_types', function( $file_types, $docs_use_head ) {
    $file_types[] = 'zip';     // Add ZIP archives
    $file_types[] = 'exe';     // Add Windows executables
    return $file_types;
}, 10, 2 );

Sign In

Register

Reset Password

Please enter your username or email address, you will receive a link to create a new password via email.