PluginProbe
Search & Replace Everything – Quick and Easy Way to Find and Replace Text, Links / trunk
Search & Replace Everything – Quick and Easy Way to Find and Replace Text, Links vtrunk
1.5.2 1.5.0 1.5.1 1.4.7 1.4.6 1.4.4 1.4.5 1.4.3 trunk 1.0.2 1.0.3 1.0.4 1.0.4.1 1.1 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.2 1.2.3 1.2.4 1.2.5 All 34 releases
update-urls / lite / includes / Loader.php

Loader.php in Search & Replace Everything – Quick and Easy Way to Find and Replace Text, Links trunk, at lite/includes/Loader.php

161 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Register all actions and filters for the plugin
5 *
6 * @link https://kaizencoders.com
7 * @since 1.2
8 *
9 * @package UpdateURLS
10 * @subpackage UpdateURLS/includes
11 */
12
13 namespace KaizenCoders\UpdateURLS;
14
15 /**
16 * Register all actions and filters for the plugin.
17 *
18 * Maintain a list of all hooks that are registered throughout
19 * the plugin, and register them with the WordPress API. Call the
20 * run function to execute the list of actions and filters.
21 *
22 * @package UpdateURLS
23 * @subpackage UpdateURLS/includes
24 * @author KaizenCoders <hello@kaizencoders.com>
25 */
26 class Loader {
27
28 /**
29 * The array of actions registered with WordPress.
30 *
31 * @since 1.2
32 * @access protected
33 * @var array $actions The actions registered with WordPress to fire when the plugin loads.
34 */
35 protected $actions;
36
37 /**
38 * The array of filters registered with WordPress.
39 *
40 * @since 1.2
41 * @access protected
42 * @var array $filters The filters registered with WordPress to fire when the plugin loads.
43 */
44 protected $filters;
45
46 /**
47 * @since 1.8.0
48 * @var array $classes The classes registered with WordPress to fire when the plugin loads.
49 */
50 protected $classes = [];
51
52 /**
53 * Initialize the collections used to maintain the actions and filters.
54 *
55 * @since 1.2
56 */
57 public function __construct() {
58 $this->actions = [];
59 $this->filters = [];
60 }
61
62 /**
63 * Add a new action to the collection to be registered with WordPress.
64 *
65 * @since 1.2
66 *
67 * @param string $hook The name of the WordPress action that is being registered.
68 * @param object $component A reference to the instance of the object on which the action is defined.
69 * @param string $callback The name of the function definition on the $component.
70 * @param int Optional $priority The priority at which the function should be fired.
71 * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
72 */
73 public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
74 $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
75 }
76
77 /**
78 * Add a new filter to the collection to be registered with WordPress.
79 *
80 * @since 1.2
81 *
82 * @param string $hook The name of the WordPress filter that is being registered.
83 * @param object $component A reference to the instance of the object on which the filter is defined.
84 * @param string $callback The name of the function definition on the $component.
85 * @param int Optional $priority The priority at which the function should be fired.
86 * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
87 */
88 public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
89 $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
90 }
91
92 /**
93 * @since 1.0.0
94 *
95 * @param $class
96 *
97 */
98 public function add_class( $class ) {
99 $this->classes[] = $class;
100 }
101
102 /**
103 * A utility function that is used to register the actions and hooks into a single
104 * collection.
105 *
106 * @since 1.2
107 * @access private
108 *
109 * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
110 * @param string $hook The name of the WordPress filter that is being registered.
111 * @param object $component A reference to the instance of the object on which the filter is defined.
112 * @param string $callback The name of the function definition on the $component.
113 * @param int Optional $priority The priority at which the function should be fired.
114 * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
115 *
116 * @return type The collection of actions and filters registered with WordPress.
117 */
118 private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
119 $hooks[] = [
120 'hook' => $hook,
121 'component' => $component,
122 'callback' => $callback,
123 'priority' => $priority,
124 'accepted_args' => $accepted_args,
125 ];
126
127 return $hooks;
128
129 }
130
131 /**
132 * Register the filters and actions with WordPress.
133 *
134 * @since 1.2
135 */
136 public function run() {
137 foreach ( $this->filters as $hook ) {
138 \add_filter( $hook['hook'], [
139 $hook['component'],
140 $hook['callback'],
141 ], $hook['priority'], $hook['accepted_args'] );
142 }
143
144 foreach ( $this->actions as $hook ) {
145 \add_action( $hook['hook'], [
146 $hook['component'],
147 $hook['callback'],
148 ], $hook['priority'], $hook['accepted_args'] );
149 }
150
151 foreach ( $this->classes as $class ) {
152 if ( class_exists( $class ) ) {
153
154 // Fix Creation of dynamic property
155 $object = new $class();
156 $object->init();
157 }
158 }
159 }
160 }
161