Myslideshow_Loader::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * Register all actions and filters for the plugin
5
 *
6
 * @link       rahicodes.wordpress.com
7
 * @since      1.0.0
8
 *
9
 * @package    Myslideshow
10
 * @subpackage Myslideshow/includes
11
 */
12
13
/**
14
 * Register all actions and filters for the plugin.
15
 *
16
 * Maintain a list of all hooks that are registered throughout
17
 * the plugin, and register them with the WordPress API. Call the
18
 * run function to execute the list of actions and filters.
19
 *
20
 * @package    Myslideshow
21
 * @subpackage Myslideshow/includes
22
 * @author     Rahi Prajapati <[email protected]>
23
 */
24
class Myslideshow_Loader {
25
26
	/**
27
	 * The array of actions registered with WordPress.
28
	 *
29
	 * @since    1.0.0
30
	 * @access   protected
31
	 * @var      array    $actions    The actions registered with WordPress to fire when the plugin loads.
32
	 */
33
	protected $actions;
34
35
	/**
36
	 * The array of filters registered with WordPress.
37
	 *
38
	 * @since    1.0.0
39
	 * @access   protected
40
	 * @var      array    $filters    The filters registered with WordPress to fire when the plugin loads.
41
	 */
42
	protected $filters;
43
44
	/**
45
	 * Initialize the collections used to maintain the actions and filters.
46
	 *
47
	 * @since    1.0.0
48
	 */
49
	public function __construct() {
50
51
		$this->actions = array();
52
		$this->filters = array();
53
54
	}
55
56
	/**
57
	 * Add a new action to the collection to be registered with WordPress.
58
	 *
59
	 * @since    1.0.0
60
	 * @param    string               $hook             The name of the WordPress action that is being registered.
61
	 * @param    object               $component        A reference to the instance of the object on which the action is defined.
62
	 * @param    string               $callback         The name of the function definition on the $component.
63
	 * @param    int                  $priority         Optional. The priority at which the function should be fired. Default is 10.
64
	 * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1.
65
	 */
66
	public function add_action( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
67
		$this->actions = $this->add( $this->actions, $hook, $component, $callback, $priority, $accepted_args );
68
	}
69
70
	/**
71
	 * Add a new filter to the collection to be registered with WordPress.
72
	 *
73
	 * @since    1.0.0
74
	 * @param    string               $hook             The name of the WordPress filter that is being registered.
75
	 * @param    object               $component        A reference to the instance of the object on which the filter is defined.
76
	 * @param    string               $callback         The name of the function definition on the $component.
77
	 * @param    int                  $priority         Optional. The priority at which the function should be fired. Default is 10.
78
	 * @param    int                  $accepted_args    Optional. The number of arguments that should be passed to the $callback. Default is 1
79
	 */
80
	public function add_filter( $hook, $component, $callback, $priority = 10, $accepted_args = 1 ) {
81
		$this->filters = $this->add( $this->filters, $hook, $component, $callback, $priority, $accepted_args );
82
	}
83
84
	/**
85
	 * A utility function that is used to register the actions and hooks into a single
86
	 * collection.
87
	 *
88
	 * @since    1.0.0
89
	 * @access   private
90
	 * @param    array                $hooks            The collection of hooks that is being registered (that is, actions or filters).
91
	 * @param    string               $hook             The name of the WordPress filter that is being registered.
92
	 * @param    object               $component        A reference to the instance of the object on which the filter is defined.
93
	 * @param    string               $callback         The name of the function definition on the $component.
94
	 * @param    int                  $priority         The priority at which the function should be fired.
95
	 * @param    int                  $accepted_args    The number of arguments that should be passed to the $callback.
96
	 * @return   array                                  The collection of actions and filters registered with WordPress.
97
	 */
98
	private function add( $hooks, $hook, $component, $callback, $priority, $accepted_args ) {
99
100
		$hooks[] = array(
101
			'hook'          => $hook,
102
			'component'     => $component,
103
			'callback'      => $callback,
104
			'priority'      => $priority,
105
			'accepted_args' => $accepted_args
106
		);
107
108
		return $hooks;
109
110
	}
111
112
	/**
113
	 * Register the filters and actions with WordPress.
114
	 *
115
	 * @since    1.0.0
116
	 */
117
	public function run() {
118
119
		foreach ( $this->filters as $hook ) {
120
			add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
0 ignored issues
show
Bug introduced by
The function add_filter was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

120
			/** @scrutinizer ignore-call */ 
121
   add_filter( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
Loading history...
121
		}
122
123
		foreach ( $this->actions as $hook ) {
124
			add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
0 ignored issues
show
Bug introduced by
The function add_action was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
			/** @scrutinizer ignore-call */ 
125
   add_action( $hook['hook'], array( $hook['component'], $hook['callback'] ), $hook['priority'], $hook['accepted_args'] );
Loading history...
125
		}
126
127
	}
128
129
}
130