From c28c37b3267d12ca9c445ba2f3e79db5c0a95e9e Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Fri, 8 Sep 2017 13:04:29 -0700 Subject: [PATCH] Improve message format and support translation --- includes/run.php | 13 +++++++------ wp-cli-cron-control-offload.php | 3 ++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/includes/run.php b/includes/run.php index f49859e..9066658 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 eb89d84..40d30f9 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'; -- GitLab