PluginProbe
MailerLite – WooCommerce integration / 3.1.27
MailerLite – WooCommerce integration v3.1.27
3.1.27 3.1.25 3.1.26 3.1.24 3.1.23 3.1.22 3.1.21 3.1.20 3.1.19 3.1.18 3.1.17 3.1.16 3.1.15 1.8.7 1.8.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 All 148 releases
woo-mailerlite / includes / WooMailerLiteLoader.php

WooMailerLiteLoader.php in MailerLite – WooCommerce integration 3.1.27, at includes/WooMailerLiteLoader.php

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