| 1 |
<?php |
| 2 |
|
| 3 |
namespace ImportWP\Common\Addon; |
| 4 |
|
| 5 |
/** |
| 6 |
* @deprecated 2.14.0 |
| 7 |
*/ |
| 8 |
class AddonBaseData |
| 9 |
{ |
| 10 |
/** |
| 11 |
* @var callable |
| 12 |
*/ |
| 13 |
protected $_run_conditions; |
| 14 |
|
| 15 |
protected $_data; |
| 16 |
|
| 17 |
/** |
| 18 |
* @var AddonBase |
| 19 |
*/ |
| 20 |
protected $_addon; |
| 21 |
|
| 22 |
public function __construct($addon, $data) |
| 23 |
{ |
| 24 |
$this->_data = $data; |
| 25 |
$this->_addon = $addon; |
| 26 |
} |
| 27 |
|
| 28 |
public function addon() |
| 29 |
{ |
| 30 |
return $this->_addon; |
| 31 |
} |
| 32 |
|
| 33 |
public function data($key = false) |
| 34 |
{ |
| 35 |
if ($key) { |
| 36 |
return isset($this->_data[$key]) ? $this->_data[$key] : false; |
| 37 |
} |
| 38 |
|
| 39 |
return $this->_data; |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* When should the addon run? |
| 44 |
* |
| 45 |
* @param callable $callback |
| 46 |
*/ |
| 47 |
public function enabled($callback) |
| 48 |
{ |
| 49 |
$this->_run_conditions = $callback; |
| 50 |
return $this; |
| 51 |
} |
| 52 |
|
| 53 |
/** |
| 54 |
* Is field allowed to be output? |
| 55 |
* |
| 56 |
* @param \ImportWP\Common\Importer\Template\Template $template |
| 57 |
* @param \ImportWP\Common\Model\ImporterModel $importer_model |
| 58 |
* @return bool |
| 59 |
*/ |
| 60 |
public function _is_allowed($template, $importer_model) |
| 61 |
{ |
| 62 |
if (!is_null($this->_run_conditions) && is_callable($this->_run_conditions) && !call_user_func_array($this->_run_conditions, [$template, $importer_model])) { |
| 63 |
return false; |
| 64 |
} |
| 65 |
|
| 66 |
return true; |
| 67 |
} |
| 68 |
} |
| 69 |
|