From 3658a3cee9879e2c037dec5fa0108091803fadef Mon Sep 17 00:00:00 2001
From: Erick Hitter <git-contrib@ethitter.com>
Date: Fri, 8 Sep 2017 14:18:13 -0700
Subject: [PATCH] Fix variable naming to reflect what it actually is

---
 includes/functions.php | 34 ++++++++++++++++++----------------
 includes/run.php       |  2 +-
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/includes/functions.php b/includes/functions.php
index 1067645..da0ed95 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -5,22 +5,24 @@ namespace Automattic\WP\WP_CLI_Cron_Control_Offload;
 /**
  * Create cron event for a given WP-CLI command
  *
- * @param string $args
+ * @param string $command
  * @param int $timestamp Optional.
  * @return bool|\WP_Error
  */
-function schedule_cli_command( $args, $timestamp = null ) {
-	$event_args = validate_args( $args );
+function schedule_cli_command( $command, $timestamp = null ) {
+	$command = validate_command( $command );
 
-	if ( is_wp_error( $event_args ) ) {
-		return $event_args;
+	if ( is_wp_error( $command ) ) {
+		return $command;
 	}
 
 	if ( ! is_int( $timestamp ) ) {
 		$timestamp = strtotime( '+30 seconds' );
 	}
 
-	$scheduled = wp_schedule_single_event( $timestamp, ACTION, array( 'command' => $event_args ) );
+	$event_args = array( 'command' => $command, );
+
+	$scheduled = wp_schedule_single_event( $timestamp, ACTION, $event_args );
 
 	return false !== $scheduled;
 }
@@ -31,32 +33,32 @@ function schedule_cli_command( $args, $timestamp = null ) {
  * @param string $args
  * @return array|\WP_Error
  */
-function validate_args( $args ) {
+function validate_command( $command ) {
 	// Strip `wp` if included
-	if ( 0 === stripos( $args, 'wp' ) ) {
-		$args = trim( substr( $args, 2 ) );
+	if ( 0 === stripos( $command, 'wp' ) ) {
+		$command = trim( substr( $command, 2 ) );
 	}
 
 	// Block disallowed commands
-	$command = explode( ' ', $args );
-	$command = array_shift( $command );
-	if ( ! is_command_allowed( $command ) ) {
-		return new \WP_Error( "$command not allowed" );
+	$first_command = explode( ' ', $command );
+	$first_command = array_shift( $first_command );
+	if ( ! is_command_allowed( $first_command ) ) {
+		return new \WP_Error( sprintf( __( '%1$s: `%2$s` not allowed', 'wp-cli-cron-control-offload' ), MESSAGE_PREFIX, $first_command ) );
 	}
 
 	// Don't worry about the user WP-CLI runs as
-	if ( false === stripos( $args, '--allow-root' ) ) {
+	if ( false === stripos( $command, '--allow-root' ) ) {
 		$args .= ' --allow-root';
 	}
 
 	// TODO: validate further
 
 	// Nothing to run
-	if ( empty( $args ) ) {
+	if ( empty( $command ) ) {
 		return new \WP_Error( 'Invalid command provided' );
 	}
 
-	return $args;
+	return $command;
 }
 
 /**
diff --git a/includes/run.php b/includes/run.php
index 9066658..8e6c834 100644
--- a/includes/run.php
+++ b/includes/run.php
@@ -15,7 +15,7 @@ function run_event( $command ) {
 		return;
 	}
 
-	if ( ! validate_args( $command ) ) {
+	if ( ! validate_command( $command ) ) {
 		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;
 	}
-- 
GitLab