PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / 1.1.0
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels v1.1.0
2.9.1 2.9.0 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.4.0 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 2.0.0 2.1.0 2.2.0 2.3.2 2.3.3 2.3.5 2.3.6 2.3.8 2.3.9 2.4.3 All 37 releases
automatic-youtube-gallery / includes / loader.php

loader.php in Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels 1.1.0, at includes/loader.php

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