PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 3.13.1
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v3.13.1
3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 2.8.17 2.8.18 All 259 releases
wpfunnels / includes / utils / class-wpfnl-loader.php

class-wpfnl-loader.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 3.13.1, at includes/utils/class-wpfnl-loader.php

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