Best Practices
Performance Considerations
- Rate Limiting: Always respect rate limiting to avoid notification spam
- Conditional Loading: Only load integration code when the target plugin is active
- Non-blocking: Use non-blocking HTTP requests for external notifications
- Memory Management: Be mindful of memory usage in error handlers
Security
- Sanitize Data: Always sanitize error data before processing
- Capability Checks: Verify user capabilities before allowing configuration changes
- Nonce Verification: Use nonces for AJAX requests and form submissions
- Data Validation: Validate all input data, especially from external sources
Error Handling
- Graceful Degradation: Ensure your code doesn’t break if Fatal Error Notify is deactivated
- Avoid Recursion: Be careful not to trigger errors within error handlers
- Logging: Use WordPress’s built-in logging functions when possible
- Testing: Test error scenarios thoroughly, including edge cases
Troubleshooting
Common Issues
Integration Not Appearing in Settings
- Ensure the target plugin class exists and is loaded
- Check that your integration is registered with the
fen_integrationsfilter - Verify the integration file is being included properly
Notifications Not Sending
- Check if the error type is enabled in the plugin settings
- Verify rate limiting isn’t preventing notifications
- Ensure the error isn’t being filtered out by custom hooks
- Check notification channel settings (email, Slack, etc.)
Custom Error Types Not Working
- Ensure error types are returned by
get_error_types() - Check that the error type matches exactly (case-sensitive)
- Verify the integration prefix is being added correctly
Debugging
Enable WordPress debug logging to troubleshoot issues:
// Add to wp-config.php
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
// Add debug logging to your integration
error_log( 'FEN Debug: ' . print_r( $error_data, true ) );
Examples
Custom Error Logger
/**
* Log all Fatal Error Notify errors to a custom table.
*/
add_action( 'fen_handle_error', function( $error ) {
global $wpdb;
$wpdb->insert(
$wpdb->prefix . 'custom_error_log',
array(
'error_type' => $error['type'],
'message' => $error['message'],
'file' => isset( $error['file'] ) ? $error['file'] : '',
'line' => isset( $error['line'] ) ? $error['line'] : 0,
'user_id' => isset( $error['user'] ) ? $error['user'] : 0,
'url' => isset( $error['url'] ) ? $error['url'] : '',
'timestamp' => current_time( 'mysql' ),
),
array( '%s', '%s', '%s', '%d', '%d', '%s', '%s' )
);
} );
Conditional Notifications
/**
* Only send notifications during business hours.
*/
add_filter( 'fen_ignore_error', function( $ignore, $error ) {
$current_hour = (int) current_time( 'H' );
// Business hours: 9 AM to 5 PM
if ( $current_hour < 9 || $current_hour >= 17 ) {
// Still log critical errors, but don't send notifications
if ( isset( $error['type'] ) && $error['type'] !== E_ERROR ) {
return true;
}
}
return $ignore;
}, 10, 2 );
Enhanced Error Context
/**
* Add additional context to all error notifications.
*/
add_filter( 'fen_error', function( $error ) {
// Add server information
$error['message'] .= "\n\n--- Server Info ---\n";
$error['message'] .= "PHP Version: " . PHP_VERSION . "\n";
$error['message'] .= "WordPress Version: " . get_bloginfo( 'version' ) . "\n";
$error['message'] .= "Memory Usage: " . size_format( memory_get_usage( true ) ) . "\n";
$error['message'] .= "Peak Memory: " . size_format( memory_get_peak_usage( true ) ) . "\n";
// Add active plugins
if ( function_exists( 'get_plugins' ) ) {
$active_plugins = get_option( 'active_plugins', array() );
$error['message'] .= "Active Plugins: " . count( $active_plugins ) . "\n";
}
return $error;
} );