PluginProbe
WPComplete / 1.2
WPComplete v1.2
2.9.5.7 2.9.5.6 trunk 1.0 1.1 1.2 1.4 1.4.6 2.3 2.9.1 2.9.2 2.9.5 2.9.5.1 2.9.5.3 2.9.5.4 2.9.5.5
wpcomplete / includes / class-wpcomplete-loader.php

class-wpcomplete-loader.php in WPComplete 1.2, at includes/class-wpcomplete-loader.php

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