PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 5.2
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v5.2
5.5.83 5.5.82 5.5.81 5.5.80 5.5.79 5.5.77 5.5.76 5.5.75 5.5.73 5.5.72 5.5.22 5.5.23 5.5.29 5.5.3 5.5.31 5.5.32 5.5.34 5.5.35 5.5.36 5.5.37 5.5.4 5.5.40 5.5.41 5.5.42 5.5.43 All 159 releases
wp-data-access / includes / class-wp-data-access-loader.php

class-wp-data-access-loader.php in WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards 5.2, at includes/class-wp-data-access-loader.php

129 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Suppress "error - 0 - No summary was found for this file" on phpdoc generation
4 *
5 * @package plugin\includes
6 */
7
8 /**
9 * Class WP_Data_Access_Loader
10 *
11 * Adds and activates plugin filters and actions.
12 *
13 * @author Peter Schulz
14 * @since 1.0.0
15 */
16 class WP_Data_Access_Loader {
17
18 /**
19 * Registered plugin actions
20 *
21 * @var array
22 */
23 protected $actions = array();
24
25 /**
26 * Registered plugin filters
27 *
28 * @var array
29 */
30 protected $filters = array();
31
32 /**
33 * Adds an action to the action array
34 *
35 * Calls method add the create array element to be added to action array.
36 *
37 * @param string $hook Action name to be registered.
38 * @param object $component Reference to object to which the action will be applied.
39 * @param string $callback Callback function: method of $component object.
40 * @param int $priority Priority of the action (default = 10).
41 * @param int $accepted_args Number of accepted arguments of callback (default = 1).
42 *
43 * @see WP_Data_Access_Loader::add()
44 *
45 * @since 1.0.0
46 */
47 public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
48 $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
49 }
50
51 /**
52 * Create action or filter element
53 *
54 * Generic creation of an element that can be added to the action array or filter array.
55 *
56 * @param array $hooks Action or filter array to which the hook is added.
57 * @param string $hook Action or filter name to be registered.
58 * @param object $component Reference to object to which the action or filter will be applied.
59 * @param string $callback Callback function: method of $component object.
60 * @param int $priority Priority of the action or action.
61 * @param int $accepted_args Number of accepted arguments of callback.
62 *
63 * @return array
64 * @since 1.0.0
65 */
66 protected function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
67 $hooks[] = array(
68 'hook' => $hook,
69 'component' => $component,
70 'callback' => $callback,
71 'priority' => $priority,
72 'accepted_args' => $accepted_args,
73 );
74
75 return $hooks;
76 }
77
78 /**
79 * Adds a filter to the filter array
80 *
81 * Calls method add the create array element to be added to filter array.
82 *
83 * @param string $hook Filter name to be registered.
84 * @param object $component Reference to object to which the filter will be applied.
85 * @param string $callback Callback function: method of $component object.
86 * @param int $priority Priority of the filter (default = 10).
87 * @param int $accepted_args Number of accepted arguments of callback (default = 1).
88 *
89 * @see WP_Data_Access_Loader::add()
90 *
91 * @since 1.0.0
92 */
93 public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
94 $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
95 }
96
97 /**
98 * Registration of filters and actions
99 *
100 * @since 1.0.0
101 */
102 public function run() {
103 foreach ( $this->filters as $hook ) {
104 add_filter(
105 $hook['hook'],
106 array(
107 $hook['component'],
108 $hook['callback'],
109 ),
110 $hook['priority'],
111 $hook['accepted_args']
112 );
113 }
114
115 foreach ( $this->actions as $hook ) {
116 add_action(
117 $hook['hook'],
118 array(
119 $hook['component'],
120 $hook['callback'],
121 ),
122 $hook['priority'],
123 $hook['accepted_args']
124 );
125 }
126 }
127
128 }
129