Skip to content
Snippets Groups Projects
Commit c28c37b3 authored by Erick Hitter's avatar Erick Hitter
Browse files

Improve message format and support translation

parent d87e7c10
No related branches found
No related tags found
No related merge requests found
......@@ -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 );
}
......
......@@ -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';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment