diff --git a/includes/run.php b/includes/run.php index f49859e7bfb818486d2419b0bcc3c5e32ff80c55..90666587f1df5b6b3a291fbbce545c8ee94d7a6e 100644 --- a/includes/run.php +++ b/includes/run.php @@ -11,12 +11,12 @@ namespace Automattic\WP\WP_CLI_Cron_Control_Offload; function run_event( $command ) { if ( ! defined( 'WP_CLI' ) || ! \WP_CLI ) { // TODO: reschedule at least once or twice - trigger_error( 'Attempted to run event without WP-CLI loaded. (' . var_export( $command, true ) . ')', E_USER_WARNING ); + trigger_error( sprintf( __( '%1$s: Attempted to run event without WP-CLI loaded. (%2$s)', 'wp-cli-cron-control-offload' ), MESSAGE_PREFIX, var_export( $command, true ) ), E_USER_WARNING ); return; } if ( ! validate_args( $command ) ) { - trigger_error( 'Attempted to run blocked WP-CLI command. (' . var_export( $command, true ) . ')', E_USER_WARNING ); + trigger_error( sprintf( __( '%1$s: Attempted to run blocked WP-CLI command. (%2$s)', 'wp-cli-cron-control-offload' ), MESSAGE_PREFIX, var_export( $command, true ) ), E_USER_WARNING ); return; } @@ -32,9 +32,10 @@ function run_event( $command ) { // Command failed if ( ! is_object( $output ) || is_wp_error( $output ) ) { - // TODO: message consistency, revisit using ACTION as the "key", seems wrong - trigger_error( 'WP-CLI command failed. (' . var_export( $command, true ) . ')', E_USER_WARNING ); - trigger_error( var_export( $output, true ), E_USER_WARNING ); + trigger_error( sprintf( __( '%1$s: WP-CLI command failed. (%2$s)', 'wp-cli-cron-control-offload' ), MESSAGE_PREFIX, var_export( $command, true ) ), E_USER_WARNING ); + + $message = is_wp_error( $output ) ? $output->get_error_message() : var_export( $output, true ); + trigger_error( $message, E_USER_WARNING ); return; } @@ -45,7 +46,7 @@ function run_event( $command ) { $output->duration = $end - $start; $output = var_export( $output, true ); - $output = ACTION . ":\n{$output}"; + $output = MESSAGE_PREFIX . ":\n{$output}"; error_log( $output ); } diff --git a/wp-cli-cron-control-offload.php b/wp-cli-cron-control-offload.php index eb89d844342e7684c8a9da0bf35175afdf1f351a..40d30f94d960000fa4705c79473548e40236f116 100644 --- a/wp-cli-cron-control-offload.php +++ b/wp-cli-cron-control-offload.php @@ -14,7 +14,8 @@ namespace Automattic\WP\WP_CLI_Cron_Control_Offload; -const ACTION = 'wp_cli_cron_control_offload'; +const ACTION = 'wp_cli_cron_control_offload'; +const MESSAGE_PREFIX = 'WP-CLI via Cron'; require_once __DIR__ . '/includes/functions.php'; require_once __DIR__ . '/includes/schedule.php';