PluginProbe
Protect Uploads / 0.4
Protect Uploads v0.4
0.7.1 trunk 0.1 0.2 0.3 0.4 0.5.1 0.5.2 0.6.0 0.7.0
protect-uploads / includes / class-protect-uploads-loader.php

class-protect-uploads-loader.php in Protect Uploads 0.4, at includes/class-protect-uploads-loader.php

100 lines 4.3 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 * from : https://github.com/DevinVinson/WordPress-Plugin-Boilerplate
6 *
7 * Maintain a list of all hooks that are registered throughout
8 * the plugin, and register them with the WordPress API. Call the
9 * run function to execute the list of actions and filters.
10 */
11 class Alti_ProtectUploads_Loader {
12
13 /**
14 * The array of actions registered with WordPress.
15 * @var array $actions The actions registered with WordPress to fire when the plugin loads.
16 */
17 protected $actions;
18
19 /**
20 * The array of filters registered with WordPress.
21 * @var array $filters The filters registered with WordPress to fire when the plugin loads.
22 */
23 protected $filters;
24
25 /**
26 * Initialize the collections used to maintain the actions and filters.
27 */
28 public function __construct() {
29
30 $this->actions = array();
31 $this->filters = array();
32
33 }
34
35 /**
36 * Add a new action to the collection to be registered with WordPress.
37 * @param string $hook The name of the WordPress action that is being registered.
38 * @param object $component A reference to the instance of the object on which the action is defined.
39 * @param string $callback The name of the function definition on the $component.
40 * @param int Optional $priority The priority at which the function should be fired.
41 * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
42 */
43 public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
44 $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
45 }
46
47 /**
48 * Add a new filter to the collection to be registered with WordPress.
49 * @param string $hook The name of the WordPress filter that is being registered.
50 * @param object $component A reference to the instance of the object on which the filter is defined.
51 * @param string $callback The name of the function definition on the $component.
52 * @param int Optional $priority The priority at which the function should be fired.
53 * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
54 */
55 public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
56 $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
57 }
58
59 /**
60 * A utility function that is used to register the actions and hooks into a single
61 * collection.
62 * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
63 * @param string $hook The name of the WordPress filter that is being registered.
64 * @param object $component A reference to the instance of the object on which the filter is defined.
65 * @param string $callback The name of the function definition on the $component.
66 * @param int Optional $priority The priority at which the function should be fired.
67 * @param int Optional $accepted_args The number of arguments that should be passed to the $callback.
68 * @return type The collection of actions and filters registered with WordPress.
69 */
70 private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
71
72 $hooks[] = array(
73 'hook' => $hook,
74 'component' => $component,
75 'callback' => $callback,
76 'priority' => $priority,
77 'accepted_args' => $accepted_args
78 );
79
80 return $hooks;
81
82 }
83
84 /**
85 * Register the filters and actions with WordPress.
86 */
87 public function run() {
88
89 foreach ( $this->filters as $hook ) {
90 add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
91 }
92
93 foreach ( $this->actions as $hook ) {
94 add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
95 }
96
97 }
98
99 }
100