PluginProbe
Essential Widgets / 3.0
Essential Widgets v3.0
3.2.1 3.3 3.2 trunk 1.0.0 1.0.1 1.1 1.2 1.2.1 1.2.2 1.3 1.4 1.4.1 1.5 1.6 1.7 1.7.1 1.7.2 1.7.3 1.7.4 1.8 1.9 2.0 2.1 2.2 All 31 releases
essential-widgets / includes / class-essential-widgets-loader.php

class-essential-widgets-loader.php in Essential Widgets 3.0, at includes/class-essential-widgets-loader.php

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