Admin
2 months ago
Cli
2 weeks ago
LlmsTxtGenerator
2 weeks ago
Mcp
11 months ago
Preview
1 year ago
Rest
10 months ago
Views
1 year ago
Activator.php
1 year ago
Bootstrap.php
9 months ago
Cli.php
9 months ago
ComingSoon.php
2 months ago
Deactivator.php
1 year ago
DefaultOptions.php
2 months ago
Errors.php
1 year ago
Helper.php
9 months ago
Hooks.php
2 months ago
Hostinger.php
2 months ago
I18n.php
1 year ago
LlmsTxtGenerator.php
1 year ago
Loader.php
1 year ago
Settings.php
1 year ago
Loader.php
94 lines
| 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 | /** |
| 17 | * @param string $hook |
| 18 | * @param mixed $component |
| 19 | * @param string $callback |
| 20 | * @param int $priority |
| 21 | * @param int $accepted_args |
| 22 | * |
| 23 | * @return void |
| 24 | */ |
| 25 | public function add_action( string $hook, $component, string $callback, int $priority = 10, int $accepted_args = 1 ) { |
| 26 | $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @param string $hook |
| 31 | * @param mixed $component |
| 32 | * @param string $callback |
| 33 | * @param int $priority |
| 34 | * @param int $accepted_args |
| 35 | * |
| 36 | * @return void |
| 37 | */ |
| 38 | public function add_filter( string $hook, $component, string $callback, int $priority = 10, int $accepted_args = 1 ) { |
| 39 | $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @param array $hooks |
| 44 | * @param string $hook |
| 45 | * @param mixed $component |
| 46 | * @param string $callback |
| 47 | * @param int $priority |
| 48 | * @param int $accepted_args |
| 49 | * |
| 50 | * @return array |
| 51 | */ |
| 52 | private function add( |
| 53 | array $hooks, |
| 54 | string $hook, |
| 55 | $component, |
| 56 | string $callback, |
| 57 | int $priority, |
| 58 | int $accepted_args |
| 59 | ): array { |
| 60 | $hooks[] = array( |
| 61 | 'hook' => $hook, |
| 62 | 'component' => $component, |
| 63 | 'callback' => $callback, |
| 64 | 'priority' => $priority, |
| 65 | 'accepted_args' => $accepted_args, |
| 66 | ); |
| 67 | |
| 68 | return $hooks; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return void |
| 73 | */ |
| 74 | public function run(): void { |
| 75 | foreach ( $this->filters as $hook ) { |
| 76 | add_filter( |
| 77 | $hook['hook'], |
| 78 | array( $hook['component'], $hook['callback'] ), |
| 79 | $hook['priority'], |
| 80 | $hook['accepted_args'] |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | foreach ( $this->actions as $hook ) { |
| 85 | add_action( |
| 86 | $hook['hook'], |
| 87 | array( $hook['component'], $hook['callback'] ), |
| 88 | $hook['priority'], |
| 89 | $hook['accepted_args'] |
| 90 | ); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 |