Hooks and Filters

Hooks and Filters


Fatal Error Notify provides several hooks and filters that allow you to customize error handling behavior, modify notification contents, and integrate with your own plugins or themes.

Error Handling Filters

fen_ignore_error

Allows you to completely ignore specific errors before they are processed.

/**
 * Filter whether to ignore an error.
 *
 * @param bool  $ignore Whether to ignore the error.
 * @param array $error  The error data array.
 */
add_filter( 'fen_ignore_error', function( $ignore, $error ) {
    // Ignore all warnings from a specific plugin
    if ( isset( $error['file'] ) && strpos( $error['file'], 'problematic-plugin' ) !== false ) {
        return true;
    }
    return $ignore;
}, 10, 2 );
fen_is_error_type_enabled

Filter whether an error type is enabled for notifications on a specific channel.

/**
 * Filter whether an error type is enabled for notifications.
 *
 * @param bool   $enabled Whether the error type is enabled.
 * @param array  $error   The error data array containing 'type' and other details.
 * @param string $channel The notification channel (email, slack, twilio, echodash) or false for any channel.
 */
add_filter( 'fen_is_error_type_enabled', function( $enabled, $error, $channel ) {
    // Only send critical WooCommerce errors to Slack
    if ( $channel === 'slack' && strpos( $error['type'], 'woocommerce_' ) === 0 ) {
        return in_array( $error['type'], [ 'woocommerce_emergency', 'woocommerce_critical' ] );
    }
    return $enabled;
}, 10, 3 );
fen_is_error_paused

Filter whether an error notification is paused.

/**
 * Filter whether an error notification is paused.
 *
 * @param bool  $paused Whether the error notification is paused.
 * @param array $error  The error data array.
 */
add_filter( 'fen_is_error_paused', function( $paused, $error ) {
    // Pause all errors during maintenance mode
    if ( wp_maintenance_mode() ) {
        return true;
    }
    return $paused;
}, 10, 2 );
fen_is_rate_limited

Filter whether an error notification is rate limited.

/**
 * Filter whether an error notification is rate limited.
 *
 * @param bool  $rate_limited Whether the error is currently rate limited.
 * @param array $error        The error data array.
 */
add_filter( 'fen_is_rate_limited', function( $rate_limited, $error ) {
    // Never rate limit critical errors
    if ( isset( $error['type'] ) && $error['type'] === E_ERROR ) {
        return false;
    }
    return $rate_limited;
}, 10, 2 );

Rate Limiting Customization

fen_rate_limit_time

Customize the rate limiting time period (default is 1 hour).

/**
 * Change rate limiting to 30 minutes instead of 1 hour.
 */
add_filter( 'fen_rate_limit_time', function( $time ) {
    return 30 * MINUTE_IN_SECONDS;
} );
fen_rate_limit_data

Customize what data is used to generate the rate limiting hash.

/**
 * Include user ID in rate limiting to separate errors by user.
 *
 * @param array $rate_limit_data The data to use for rate limiting.
 * @param array $error           The full error data array.
 */
add_filter( 'fen_rate_limit_data', function( $rate_limit_data, $error ) {
    if ( isset( $error['user'] ) ) {
        $rate_limit_data['user'] = $error['user'];
    }
    return $rate_limit_data;
}, 10, 2 );

Notification Content Filters

fen_error

Filter the error data before sending notifications.

/**
 * Filter the error data before sending notifications.
 *
 * @param array $error The error data array.
 */
add_filter( 'fen_error', function( $error ) {
    // Add custom context to error messages
    if ( isset( $error['message'] ) ) {
        $error['message'] = '[Site: ' . get_bloginfo( 'name' ) . '] ' . $error['message'];
    }
    return $error;
} );
fen_email_notification_output

Filter the email notification output.

/**
 * Filter the email notification output.
 *
 * @param string $output The email notification output.
 * @param array  $error  The error data array.
 */
add_filter( 'fen_email_notification_output', function( $output, $error ) {
    // Add custom footer to email notifications
    $output .= '<hr><p><strong>Need help?</strong> Contact support at [email protected]</p>';
    return $output;
}, 10, 2 );
fen_email_notification_subject

Filter the email notification subject.

/**
 * Filter the email notification subject.
 *
 * @param string $subject The email notification subject.
 * @param array  $error   The error data array.
 */
add_filter( 'fen_email_notification_subject', function( $subject, $error ) {
    // Add priority indicator for fatal errors
    if ( isset( $error['type'] ) && $error['type'] === E_ERROR ) {
        $subject = '[URGENT] ' . $subject;
    }
    return $subject;
}, 10, 2 );
fen_full_request_url

Filter the full request URL included in notifications.

/**
 * Filter the full request URL.
 *
 * @param string $url   The full request URL.
 * @param array  $error The error data array.
 */
add_filter( 'fen_full_request_url', function( $url, $error ) {
    // Add UTM parameters for tracking
    return add_query_arg( 'utm_source', 'error_notification', $url );
}, 10, 2 );
fen_slack_notification_data

Filter the complete Slack notification payload before it is sent. This gives you full control over the entire message structure.

/**
 * Filter the Slack notification data.
 *
 * @param array $data  The notification data (includes 'channel', 'blocks', 'attachments', etc.).
 * @param array $error The error data array.
 */
add_filter( 'fen_slack_notification_data', function( $data, $error ) {
    // Add a custom header to all Slack notifications
    array_unshift( $data['blocks'], array(
        'type' => 'section',
        'text' => array(
            'type' => 'mrkdwn',
            'text' => ':rotating_light: *Production Alert*',
        ),
    ) );
    return $data;
}, 10, 2 );
fen_slack_show_actions

Controls whether Slack action buttons (Pause Notification, Pause This File, Mute Plugin) are displayed. Return false to hide all action buttons.

/**
 * Hide all Slack action buttons.
 *
 * @param bool  $show_actions Whether to show action buttons. Default true.
 * @param array $error        The error data array.
 */
add_filter( 'fen_slack_show_actions', '__return_false' );

You can also conditionally hide buttons based on the error:

add_filter( 'fen_slack_show_actions', function( $show, $error ) {
    // Only show action buttons for fatal errors
    if ( isset( $error['type'] ) && $error['type'] !== E_ERROR ) {
        return false;
    }
    return $show;
}, 10, 2 );
fen_slack_actions

Filter the individual Slack action buttons for granular control. Each button is an array with Slack’s button element structure.

/**
 * Remove the "Mute Plugin" button from Slack notifications.
 *
 * @param array $actions The action buttons array.
 * @param array $error   The error data array.
 */
add_filter( 'fen_slack_actions', function( $actions, $error ) {
    foreach ( $actions as $key => $action ) {
        if ( strpos( $action['text']['text'], 'Mute Plugin' ) !== false ) {
            unset( $actions[ $key ] );
        }
    }
    return array_values( $actions );
}, 10, 2 );
fen_slack_blocks

Filter the Slack message blocks array. This lets you customize the notification content without modifying the full payload.

/**
 * Add a custom block to Slack notifications.
 *
 * @param array $blocks The Slack message blocks.
 * @param array $error  The error data array.
 */
add_filter( 'fen_slack_blocks', function( $blocks, $error ) {
    // Add a context block with the current WordPress version
    $blocks[] = array(
        'type'     => 'context',
        'elements' => array(
            array(
                'type' => 'mrkdwn',
                'text' => 'WP ' . get_bloginfo( 'version' ) . ' | PHP ' . PHP_VERSION,
            ),
        ),
    );
    return $blocks;
}, 10, 2 );

WordPress Mail Integration

fen_use_wp_mail

Control whether to use WordPress’s wp_mail() function or PHP’s mail() function.

/**
 * Force use of PHP mail() instead of wp_mail().
 */
add_filter( 'fen_use_wp_mail', '__return_false' );

Action Hooks


Error Processing Actions

fen_handle_error

Fired when an error is being handled, before notifications are sent.

/**
 * Log all errors to a custom log file.
 *
 * @param array $error The error data array.
 */
add_action( 'fen_handle_error', function( $error ) {
    error_log( 
        '[' . date( 'Y-m-d H:i:s' ) . '] FEN Error: ' . print_r( $error, true ),
        3,
        WP_CONTENT_DIR . '/custom-error.log'
    );
} );
fen_handle_error_{type}

Fired for specific error types (e.g., fen_handle_error_1 for E_ERROR).

/**
 * Send critical errors to external monitoring service.
 */
add_action( 'fen_handle_error_1', function( $error ) { // E_ERROR = 1
    // Send to external monitoring service
    wp_remote_post( 'https://monitoring.example.com/api/errors', [
        'body' => json_encode( $error ),
        'headers' => [ 'Content-Type' => 'application/json' ]
    ] );
} );

Settings Management


Getting Settings

Access Fatal Error Notify settings programmatically:

// Get all settings
$settings = fatal_error_notify()->admin->get_all();

// Get a specific setting
$email = fatal_error_notify()->admin->get( 'notification_email' );

// Get setting with default value
$slack_channel = fatal_error_notify()->admin->get( 'slack_channel_id', '#general' );

Setting Filters

fen_get_setting_{key}

Filter individual setting values when they’re retrieved.

/**
 * Override license key from wp-config.php constant.
 */
add_filter( 'fen_get_setting_license_key', function( $license_key ) {
    if ( defined( 'FATAL_ERROR_NOTIFY_LICENSE_KEY' ) ) {
        return FATAL_ERROR_NOTIFY_LICENSE_KEY;
    }
    return $license_key;
} );