PluginProbe
Siteimprove / 2.1.2
Siteimprove v2.1.2
2.1.4 trunk 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1.0 2.1.1 2.1.2 2.1.3
siteimprove / includes / class-siteimprove-loader.php

class-siteimprove-loader.php in Siteimprove 2.1.2, at includes/class-siteimprove-loader.php

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