| 1 |
<?php |
| 2 |
if (!defined('ABSPATH')) die('No direct access allowed'); |
| 3 |
|
| 4 |
/** |
| 5 |
* This is a small glue class, which makes available all the commands in WP_Optimize_Commands, and translates the response from WP_Optimize_Commands (which is either data to return, or a WP_Error) into the format used by UpdraftCentral. |
| 6 |
*/ |
| 7 |
class UpdraftCentral_WP_Optimize_Commands extends UpdraftCentral_Commands { |
| 8 |
|
| 9 |
private $commands; |
| 10 |
|
| 11 |
private $wp_optimize_updraftcentral_commands; |
| 12 |
|
| 13 |
/** |
| 14 |
* Class constructor |
| 15 |
*/ |
| 16 |
public function __construct() { |
| 17 |
$this->commands = new WP_Optimize_Commands(); |
| 18 |
$this->wp_optimize_updraftcentral_commands = new WP_Optimize_UpdraftCentral_Commands(); |
| 19 |
} |
| 20 |
|
| 21 |
/** |
| 22 |
* Magic method to pass on the command to WP_Optimize_Commands |
| 23 |
* |
| 24 |
* @param string $name - command name |
| 25 |
* @param array $arguments - command parameters |
| 26 |
* |
| 27 |
* @return array - response |
| 28 |
*/ |
| 29 |
public function __call($name, $arguments) { |
| 30 |
|
| 31 |
if (is_callable(array($this->wp_optimize_updraftcentral_commands, $name))) { |
| 32 |
$this->commands = $this->wp_optimize_updraftcentral_commands; |
| 33 |
} elseif (!is_callable(array($this->commands, $name))) { |
| 34 |
return $this->_generic_error_response('wp_optimize_no_such_command', $name); |
| 35 |
} |
| 36 |
|
| 37 |
if (count($arguments) > 0) { |
| 38 |
$arguments[0] = $arguments[0] ?? array(); |
| 39 |
} |
| 40 |
|
| 41 |
$result = call_user_func_array(array($this->commands, $name), $arguments); |
| 42 |
|
| 43 |
if (is_wp_error($result)) { |
| 44 |
return $this->_generic_error_response($result->get_error_code(), $result->get_error_data()); |
| 45 |
} else { |
| 46 |
return $this->_response($result); |
| 47 |
} |
| 48 |
} |
| 49 |
} |
| 50 |
|