PluginProbe
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels / trunk
Automatic YouTube Gallery – Embed Auto-Updating YouTube Video Galleries, Feeds, Playlists & Channels vtrunk
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 trunk, at includes/loader.php

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