| 1 |
<?php |
| 2 |
|
| 3 |
namespace Hostinger; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
class Loader { |
| 8 |
protected array $actions; |
| 9 |
protected array $filters; |
| 10 |
|
| 11 |
public function __construct() { |
| 12 |
$this->actions = array(); |
| 13 |
$this->filters = array(); |
| 14 |
} |
| 15 |
|
| 16 |
public function add_action( string $hook, $component, string $callback, int $priority = 10, int $accepted_args = 1 ) { |
| 17 |
$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
| 18 |
} |
| 19 |
|
| 20 |
public function add_filter( string $hook, $component, string $callback, int $priority = 10, int $accepted_args = 1 ) { |
| 21 |
$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
| 22 |
} |
| 23 |
|
| 24 |
|
| 25 |
private function add( |
| 26 |
array $hooks, |
| 27 |
string $hook, |
| 28 |
$component, |
| 29 |
string $callback, |
| 30 |
int $priority, |
| 31 |
int $accepted_args |
| 32 |
): array { |
| 33 |
$hooks[] = array( |
| 34 |
'hook' => $hook, |
| 35 |
'component' => $component, |
| 36 |
'callback' => $callback, |
| 37 |
'priority' => $priority, |
| 38 |
'accepted_args' => $accepted_args, |
| 39 |
); |
| 40 |
|
| 41 |
return $hooks; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @return void |
| 46 |
*/ |
| 47 |
public function run(): void { |
| 48 |
foreach ( $this->filters as $hook ) { |
| 49 |
add_filter( |
| 50 |
$hook['hook'], |
| 51 |
array( $hook['component'], $hook['callback'] ), |
| 52 |
$hook['priority'], |
| 53 |
$hook['accepted_args'] |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
foreach ( $this->actions as $hook ) { |
| 58 |
add_action( |
| 59 |
$hook['hook'], |
| 60 |
array( $hook['component'], $hook['callback'] ), |
| 61 |
$hook['priority'], |
| 62 |
$hook['accepted_args'] |
| 63 |
); |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|