PluginProbe
Hostinger Tools / 3.0.76
Hostinger Tools v3.0.76
3.0.77 3.0.76 3.0.75 3.0.74 3.0.73 3.0.72 3.0.71 3.0.70 3.0.69 3.0.68 3.0.67 3.0.66 1.8.1 1.8.2 1.8.3 1.9.1 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.4 All 108 releases
hostinger / includes / Loader.php

Loader.php in Hostinger Tools 3.0.76, at includes/Loader.php

94 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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