PluginProbe
WpStream – Live Streaming, Video on Demand, Pay Per View / 4.14.0
WpStream – Live Streaming, Video on Demand, Pay Per View v4.14.0
4.14.1 4.14.0 4.13.2 4.13.1 4.13 4.12.5 4.12.4 4.12.3 4.12.2 4.12.1 4.12 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5 4.5.1 4.5.11 4.5.11.1 4.5.11.2 4.5.11.4 4.5.11.5 4.5.11.6 All 181 releases
wpstream / includes / class-wpstream-loader.php

class-wpstream-loader.php in WpStream – Live Streaming, Video on Demand, Pay Per View 4.14.0, at includes/class-wpstream-loader.php

147 lines 5.8 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 http://wpstream.net
7 * @since 3.0.1
8 *
9 * @package Wpstream
10 * @subpackage Wpstream/includes
11 */
12
13
14 // Exit if accessed directly.
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 /**
20 * Register all actions and filters for the plugin.
21 *
22 * Maintain a list of all hooks that are registered throughout
23 * the plugin, and register them with the WordPress API. Call the
24 * run function to execute the list of actions and filters.
25 *
26 * @package Wpstream
27 * @subpackage Wpstream/includes
28 * @author wpstream <office@wpstream.net>
29 */
30 class Wpstream_Loader {
31
32 /**
33 * The array of actions registered with WordPress.
34 *
35 * @since 3.0.1
36 * @access protected
37 * @var array $actions The actions registered with WordPress to fire when the plugin loads.
38 */
39 protected $actions;
40
41 /**
42 * The array of filters registered with WordPress.
43 *
44 * @since 3.0.1
45 * @access protected
46 * @var array $filters The filters registered with WordPress to fire when the plugin loads.
47 */
48 protected $filters;
49
50 /**
51 * Initialize the collections used to maintain the actions and filters.
52 *
53 * @since 3.0.1
54 */
55 public function __construct() {
56
57 // Start with an empty queue of actions; hooks get appended via add_action().
58 $this->actions = array();
59 // Start with an empty queue of filters; hooks get appended via add_filter().
60 $this->filters = array();
61
62 }
63
64 /**
65 * Add a new action to the collection to be registered with WordPress.
66 *
67 * @since 3.0.1
68 * @param string $hook The name of the WordPress action that is being registered.
69 * @param object $component A reference to the instance of the object on which the action is defined.
70 * @param string $callback The name of the function definition on the $component.
71 * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
72 * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
73 */
74 public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
75 // Append the action to the internal collection via the shared add() helper.
76 $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
77 }
78
79 /**
80 * Add a new filter to the collection to be registered with WordPress.
81 *
82 * @since 3.0.1
83 * @param string $hook The name of the WordPress filter that is being registered.
84 * @param object $component A reference to the instance of the object on which the filter is defined.
85 * @param string $callback The name of the function definition on the $component.
86 * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
87 * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1
88 */
89 public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
90 // Append the filter to the internal collection via the shared add() helper.
91 $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
92 }
93
94 /**
95 * A utility function that is used to register the actions and hooks into a single
96 * collection.
97 *
98 * @since 3.0.1
99 * @access private
100 * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
101 * @param string $hook The name of the WordPress filter that is being registered.
102 * @param object $component A reference to the instance of the object on which the filter is defined.
103 * @param string $callback The name of the function definition on the $component.
104 * @param int $priority The priority at which the function should be fired.
105 * @param int $accepted_args The number of arguments that should be passed to the $callback.
106 * @return array The collection of actions and filters registered with WordPress.
107 */
108 private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
109
110 // Push one normalized record onto the collection, capturing everything
111 // WordPress needs later to wire the callback up in run().
112 $hooks[] = array(
113 'hook' => $hook, // WordPress hook name to attach to
114 'component' => $component, // object instance owning the callback
115 'callback' => $callback, // method name on that object
116 'priority' => $priority, // execution priority for this hook
117 'accepted_args' => $accepted_args // number of args passed to the callback
118 );
119
120 // Return the grown collection so the caller can reassign its property.
121 return $hooks;
122
123 }
124
125 /**
126 * Register the filters and actions with WordPress.
127 *
128 * @since 3.0.1
129 */
130 public function run() {
131
132 // Register every queued filter with WordPress core.
133 foreach ( $this->filters as $hook ) {
134 // Bind the stored component/callback pair at its recorded priority and arg count.
135 add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
136 }
137
138 // Register every queued action with WordPress core.
139 foreach ( $this->actions as $hook ) {
140 // Bind the stored component/callback pair at its recorded priority and arg count.
141 add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
142 }
143
144 }
145
146 }
147