PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 2.4.15
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v2.4.15
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / includes / class-smart-post-show-loader.php

class-smart-post-show-loader.php in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 2.4.15, at includes/class-smart-post-show-loader.php

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