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