Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/worker/src/MWP/Action
File: Definition.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
* This file is part of the ManageWP Worker plugin.
[2] Fix | Delete
*
[3] Fix | Delete
* (c) ManageWP LLC <contact@managewp.com>
[4] Fix | Delete
*
[5] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[6] Fix | Delete
* file that was distributed with this source code.
[7] Fix | Delete
*/
[8] Fix | Delete
[9] Fix | Delete
class MWP_Action_Definition
[10] Fix | Delete
{
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* @var callable
[14] Fix | Delete
*/
[15] Fix | Delete
private $callback;
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* @var array
[19] Fix | Delete
*/
[20] Fix | Delete
private $options;
[21] Fix | Delete
[22] Fix | Delete
private static $defaultOptions = array(
[23] Fix | Delete
'hook_name' => null,
[24] Fix | Delete
'hook_priority' => 10,
[25] Fix | Delete
);
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* First parameter is callback to be executed.
[29] Fix | Delete
* Second parameter accepts the following option names:
[30] Fix | Delete
* - 'hook_name' - WordPress hook to attach the action to.
[31] Fix | Delete
* - 'hook_priority' - WordPress hook priority; used only when 'hook_name' is set.
[32] Fix | Delete
*
[33] Fix | Delete
* @param callable $callback
[34] Fix | Delete
* @param array $options
[35] Fix | Delete
*/
[36] Fix | Delete
public function __construct($callback, array $options = array())
[37] Fix | Delete
{
[38] Fix | Delete
$this->validateOptions($options);
[39] Fix | Delete
$options += self::$defaultOptions;
[40] Fix | Delete
[41] Fix | Delete
$this->callback = $callback;
[42] Fix | Delete
$this->options = $options;
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
private function validateOptions(array $options)
[46] Fix | Delete
{
[47] Fix | Delete
foreach ($options as $optionName => $optionDefault) {
[48] Fix | Delete
if (!array_key_exists($optionName, self::$defaultOptions)) {
[49] Fix | Delete
throw new InvalidArgumentException(sprintf('Option "%s" is not registered, valid options are "%s"', $optionName, implode('", "', array_keys(self::$defaultOptions))));
[50] Fix | Delete
}
[51] Fix | Delete
}
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
/**
[55] Fix | Delete
* @return callable
[56] Fix | Delete
*/
[57] Fix | Delete
public function getCallback()
[58] Fix | Delete
{
[59] Fix | Delete
return $this->callback;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
public function getOption($name)
[63] Fix | Delete
{
[64] Fix | Delete
if (!array_key_exists($name, $this->options)) {
[65] Fix | Delete
throw new InvalidArgumentException(sprintf('Option "%s" is not recognized', $name));
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
return $this->options[$name];
[69] Fix | Delete
}
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function