PluginProbe
ChatHelp – Click to Chat Button, WooCommerce Chat to Order & Floating Chat Form / trunk
ChatHelp – Click to Chat Button, WooCommerce Chat to Order & Floating Chat Form vtrunk
3.5.9 3.5.8 3.5.7 3.5.6 3.5.5 3.5.4 3.5.3 3.5.2 3.5.0 3.5.1 3.4.2 3.4.1 3.4.0 3.3.2 trunk 1.6.1 1.6.2 1.6.3 1.6.4 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 All 76 releases
chat-help / src / Includes / Loader.php

Loader.php in ChatHelp – Click to Chat Button, WooCommerce Chat to Order & Floating Chat Form trunk, at src/Includes/Loader.php

157 lines 5.9 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 improved by ThemeAtelier.
4 *
5 * @link https://themeatelier.net
6 * @since 1.0.0
7 *
8 * @package chat-help
9 * @subpackage chat-help/includes
10 */
11
12 namespace ThemeAtelier\ChatHelp\Includes;
13 if (! defined('ABSPATH')) {
14 die;
15 } // Cannot access directly.
16 /**
17 * Register all actions and filters for the plugin.
18 *
19 * Maintain a list of all hooks that are registered throughout
20 * the plugin, and register them with the WordPress API. Call the
21 * run function to execute the list of actions and filters.
22 *
23 * @package chat-help
24 * @subpackage chat-help/includes
25 * @author ThemeAtelier <themeatelierbd@gmail.com>
26 */
27 class Loader {
28
29 /**
30 * The array of actions registered with WordPress.
31 *
32 * @since 1.0.0
33 * @access protected
34 * @var array $actions The actions registered with WordPress to fire when the plugin loads.
35 */
36 protected $actions;
37
38 /**
39 * The array of filters registered with WordPress.
40 *
41 * @since 1.0.0
42 * @access protected
43 * @var array $filters The filters registered with WordPress to fire when the plugin loads.
44 */
45 protected $filters;
46
47 /**
48 * The array of shortcode registered with WordPress.
49 *
50 * @since 1.0.0
51 * @access protected
52 * @var array $shortcodes The Shortcodes registered with WordPress to add shortcode to the plugin.
53 */
54 protected $shortcodes;
55
56 /**
57 * Initialize the collections used to maintain the actions and filters.
58 *
59 * @since 1.0.0
60 */
61 public function __construct() {
62 $this->actions = array();
63 $this->filters = array();
64 $this->shortcodes = array();
65 }
66
67 /**
68 * Add a new action to the collection to be registered with WordPress.
69 *
70 * @since 1.0.0
71 * @param string $hook The name of the WordPress action that is being registered.
72 * @param object $component A reference to the instance of the object on which the action is defined.
73 * @param string $callback The name of the function definition on the $component.
74 * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
75 * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
76 */
77 public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
78 $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
79 }
80
81 /**
82 * Add a new filter to the collection to be registered with WordPress.
83 *
84 * @since 1.0.0
85 * @param string $hook The name of the WordPress filter that is being registered.
86 * @param object $component A reference to the instance of the object on which the filter is defined.
87 * @param string $callback The name of the function definition on the $component.
88 * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
89 * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
90 */
91 public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
92 $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
93 }
94
95 /**
96 * Add new shortcode to the collection to be registered with the WordPress.
97 *
98 * @since 3.0.0
99 * @param string $tag The name of the shortcode that is being registered.
100 * @param object $component The reference to the instance of the object on which the shortcode is defined.
101 * @param string $callback The name of the function definition on the $component.
102 * @param integer $priority Optional. The priority at which the function should be fired. Default is 10.
103 * @param integer $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
104 * @return void
105 */
106 public function add_shortcode( $tag, $component, $callback, $priority = 10, $accepted_args = 1 ) {
107 $this->shortcodes = $this->add( $this->shortcodes, $tag, $component, $callback, $priority, $accepted_args );
108 }
109
110 /**
111 * A utility function that is used to register the actions and hooks into a single
112 * collection.
113 *
114 * @since 1.0.0
115 * @access private
116 * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
117 * @param string $hook The name of the WordPress filter that is being registered.
118 * @param object $component A reference to the instance of the object on which the filter is defined.
119 * @param string $callback The name of the function definition on the $component.
120 * @param int $priority The priority at which the function should be fired.
121 * @param int $accepted_args The number of arguments that should be passed to the $callback.
122 * @return array The collection of actions and filters registered with WordPress.
123 */
124 private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
125
126 $hooks[] = array(
127 'hook' => $hook,
128 'component' => $component,
129 'callback' => $callback,
130 'priority' => $priority,
131 'accepted_args' => $accepted_args,
132 );
133
134 return $hooks;
135 }
136
137 /**
138 * Register the filters and actions with WordPress.
139 *
140 * @since 1.0.0
141 */
142 public function run() {
143
144 foreach ( $this->filters as $hook ) {
145 add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
146 }
147
148 foreach ( $this->actions as $hook ) {
149 add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
150 }
151
152 foreach ( $this->shortcodes as $hook ) {
153 add_shortcode( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
154 }
155 }
156 }
157