PluginProbe ʕ •ᴥ•ʔ
XML Feed for Skroutz & BestPrice for WooCommerce / 1.0.3
XML Feed for Skroutz & BestPrice for WooCommerce v1.0.3
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 1.2.1 1.2.3 1.2.4
xml-feed-for-skroutz-for-woocommerce / includes / class-dc-skroutz-feed-loader.php
xml-feed-for-skroutz-for-woocommerce / includes Last commit date
class-dc-skroutz-feed-activator.php 1 year ago class-dc-skroutz-feed-cli.php 1 year ago class-dc-skroutz-feed-i18n.php 1 year ago class-dc-skroutz-feed-loader.php 1 year ago class-dc-skroutz-feed.php 1 year ago dicha-skroutz-feed-create-cron.php 1 year ago index.php 1 year ago
class-dc-skroutz-feed-loader.php
97 lines
1 <?php
2
3 /**
4 * Register all actions and filters for the plugin
5 */
6 class Dicha_Skroutz_Feed_Loader {
7
8 /**
9 * The array of actions registered with WordPress.
10 *
11 * @var array $actions The actions registered with WordPress to fire when the plugin loads.
12 */
13 protected $actions;
14
15 /**
16 * The array of filters registered with WordPress.
17 *
18 * @var array $filters The filters registered with WordPress to fire when the plugin loads.
19 */
20 protected $filters;
21
22 /**
23 * Initialize the collections used to maintain the actions and filters.
24 */
25 public function __construct() {
26
27 $this->actions = [];
28 $this->filters = [];
29 }
30
31 /**
32 * Add a new action to the collection to be registered with WordPress.
33 *
34 * @param string $hook The name of the WordPress action that is being registered.
35 * @param object $component A reference to the instance of the object on which the action is defined.
36 * @param string $callback The name of the function definition on the $component.
37 * @param int $priority Optional. The priority at which the function should be fired. Default is 10.
38 * @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1.
39 */
40 public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
41 $this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
42 }
43
44 /**
45 * Add a new filter to the collection to be registered with WordPress.
46 *
47 * @param string $hook The name of the WordPress filter that is being registered.
48 * @param object $component A reference to the instance of the object on which the filter is defined.
49 * @param string $callback The name of the function definition on the $component.
50 * @param int $priority Optional. The 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_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
54 $this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
55 }
56
57 /**
58 * A utility function that is used to register the actions and hooks into a single
59 * collection.
60 *
61 * @param array $hooks The collection of hooks that is being registered (that is, actions or filters).
62 * @param string $hook The name of the WordPress filter that is being registered.
63 * @param object $component A reference to the instance of the object on which the filter is defined.
64 * @param string $callback The name of the function definition on the $component.
65 * @param int $priority The priority at which the function should be fired.
66 * @param int $accepted_args The number of arguments that should be passed to the $callback.
67 *
68 * @return array The collection of actions and filters registered with WordPress.
69 */
70 private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
71
72 $hooks[] = [
73 'hook' => $hook,
74 'component' => $component,
75 'callback' => $callback,
76 'priority' => $priority,
77 'accepted_args' => $accepted_args
78 ];
79
80 return $hooks;
81 }
82
83 /**
84 * Register the filters and actions with WordPress.
85 */
86 public function run() {
87
88 foreach ( $this->filters as $hook ) {
89 add_filter( $hook['hook'], [ $hook['component'], $hook['callback'] ], $hook['priority'], $hook['accepted_args'] );
90 }
91
92 foreach ( $this->actions as $hook ) {
93 add_action( $hook['hook'], [ $hook['component'], $hook['callback'] ], $hook['priority'], $hook['accepted_args'] );
94 }
95 }
96 }
97