PluginProbe
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards / 2.0.13
WP Data Access – App Builder for Tables, Forms, Charts, Maps & Dashboards v2.0.13
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 2.0.13, at includes/class-wp-data-access-loader.php

120 lines 3.3 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 * @package plugin\includes
14 * @author Peter Schulz
15 * @since 1.0.0
16 */
17 class WP_Data_Access_Loader {
18
19 /**
20 * Registered plugin actions
21 *
22 * @var array
23 */
24 protected $actions = [];
25
26 /**
27 * Registered plugin filters
28 *
29 * @var array
30 */
31 protected $filters = [];
32
33 /**
34 * Adds an action to the action array
35 *
36 * Calls method add the create array element to be added to action array.
37 *
38 * @since 1.0.0
39 *
40 * @see WP_Data_Access_Loader::add()
41 *
42 * @param string $hook Action name to be registered.
43 * @param object $component Reference to object to which the action will be applied.
44 * @param string $callback Callback function: method of $component object.
45 * @param int $priority Priority of the action (default = 10).
46 * @param int $accepted_args Number of accepted arguments of callback (default = 1).
47 */
48 public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
49
50 $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
51
52 }
53
54 /**
55 * Create action or filter element
56 *
57 * Generic creation of an element that can be added to the action array or filter array.
58 *
59 * @since 1.0.0
60 *
61 * @param array $hooks Action or filter array to which the hook is added.
62 * @param string $hook Action or filter name to be registered.
63 * @param object $component Reference to object to which the action or filter will be applied.
64 * @param string $callback Callback function: method of $component object.
65 * @param int $priority Priority of the action or action.
66 * @param int $accepted_args Number of accepted arguments of callback.
67 * @return array
68 */
69 protected function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
70
71 $hooks[] = [
72 'hook' => $hook,
73 'component' => $component,
74 'callback' => $callback,
75 'priority' => $priority,
76 'accepted_args' => $accepted_args,
77 ];
78
79 return $hooks;
80
81 }
82
83 /**
84 * Adds a filter to the filter array
85 *
86 * Calls method add the create array element to be added to filter array.
87 *
88 * @since 1.0.0
89 *
90 * @see WP_Data_Access_Loader::add()
91 *
92 * @param string $hook Filter name to be registered.
93 * @param object $component Reference to object to which the filter will be applied.
94 * @param string $callback Callback function: method of $component object.
95 * @param int $priority Priority of the filter (default = 10).
96 * @param int $accepted_args Number of accepted arguments of callback (default = 1).
97 */
98 public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
99 $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
100 }
101
102 /**
103 * Registration of filters and actions
104 *
105 * @since 1.0.0
106 */
107 public function run() {
108
109 foreach ( $this->filters as $hook ) {
110 add_filter( $hook['hook'], [ $hook['component'], $hook['callback'] ], $hook['priority'], $hook['accepted_args'] );
111 }
112
113 foreach ( $this->actions as $hook ) {
114 add_action( $hook['hook'], [ $hook['component'], $hook['callback'] ], $hook['priority'], $hook['accepted_args'] );
115 }
116
117 }
118
119 }
120