Filter
uncanny-automator
automator_rest_routes_log_display_notices_warnings
Filters the notices and warnings displayed in the Automator REST API logs for core integration.
add_filter( 'automator_rest_routes_log_display_notices_warnings', $callback, 10, 1 );
Description
Fires before REST API error display settings are applied for log routes. Developers can filter this to `true` to enable `display_errors`, which can be useful for debugging REST API requests, but should be disabled in production.
Usage
add_filter( 'automator_rest_routes_log_display_notices_warnings', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'automator_rest_routes_log_display_notices_warnings' filter.
*
* This filter allows you to control whether error display is disabled for the log display REST API route.
* By default, it's disabled (errors are suppressed). This example shows how to enable error display
* under specific conditions, for debugging purposes.
*
* In this example, we'll enable error display only for logged-in administrators who have the 'manage_options' capability.
*
* @param bool $disable_errors The current value of the 'display_errors' setting. Defaults to false (suppress errors).
* @return bool True to disable errors (suppress), false to enable errors (display).
*/
add_filter(
'automator_rest_routes_log_display_notices_warnings',
function ( $disable_errors ) {
// Check if the current user is an administrator.
if ( current_user_can( 'manage_options' ) ) {
// If the user is an administrator, we want to *enable* error display for debugging.
// Therefore, we return false, which will cause the `ini_set('display_errors', '0')` line
// in the core function to *not* be executed.
return false;
}
// For all other users, maintain the default behavior of suppressing errors.
return $disable_errors;
},
10, // Priority
1 // Accepted args
);
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/core/services/rest-routes.php:133
src/core/services/rest-routes.php:215
array(
// The permission callback.
'methods' => 'GET',
'permission_callback' => $authentication,
'callback' => function ( WP_REST_Request $request ) {
// Disable errors so JS won't break.
if ( ! apply_filters( 'automator_rest_routes_log_display_notices_warnings', false ) ) {
ini_set( 'display_errors', '0' ); // phpcs:ignore WordPress.PHP.IniSet
}
global $wpdb;
// @todo Use DIC to simplify and autowire the following class compositions/dependencies.
$utils = new Formatters_Utils();