1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class for the hooks app. |
5
|
|
|
* |
6
|
|
|
* @package wordpoints-hooks-api |
7
|
|
|
* @since 1.0.0 |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Hooks app. |
12
|
|
|
* |
13
|
|
|
* The hooks API consists primarily of actions, events, reactors, args, and |
14
|
|
|
* other extensions. Events are "fired" at various reactors when actions occur. |
15
|
|
|
* The args that the event relates to is passed to any extensions, along with |
16
|
|
|
* the list of predefined reactions. The extensions can then analyse the args and |
17
|
|
|
* the reaction specifications to determine whether the reactor should "hit" or |
18
|
|
|
* "miss" the target entity. |
19
|
|
|
* |
20
|
|
|
* @since 1.0.0 |
21
|
|
|
* |
22
|
|
|
* @property-read WordPoints_Hook_Router $router The hook action router. |
23
|
|
|
* @property-read WordPoints_Hook_Actions $actions The actions registry. |
24
|
|
|
* @property-read WordPoints_Hook_Events $events The events registry. |
25
|
|
|
* @property-read WordPoints_Class_Registry_Persistent $firers The firers registry. |
26
|
|
|
* @property-read WordPoints_Class_Registry_Persistent $reactors The reactors registry. |
27
|
|
|
* @property-read WordPoints_Class_Registry_Persistent $extensions The extensions registry. |
28
|
|
|
* @property-read WordPoints_Class_Registry_Children $conditions The conditions registry. |
29
|
|
|
*/ |
30
|
|
|
class WordPoints_Hooks extends WordPoints_App { |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* The current mode of the API. |
34
|
|
|
* |
35
|
|
|
* @since 1.0.0 |
36
|
|
|
* |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
protected $current_mode; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Register the sub apps when the app is constructed. |
43
|
|
|
* |
44
|
|
|
* @since 1.0.0 |
45
|
|
|
*/ |
46
|
|
|
protected function init() { |
47
|
|
|
|
48
|
|
|
$sub_apps = $this->sub_apps; |
49
|
|
|
$sub_apps->register( 'router', 'WordPoints_Hook_Router' ); |
50
|
|
|
$sub_apps->register( 'actions', 'WordPoints_Hook_Actions' ); |
51
|
|
|
$sub_apps->register( 'events', 'WordPoints_Hook_Events' ); |
52
|
|
|
$sub_apps->register( 'firers', 'WordPoints_Class_Registry_Persistent' ); |
53
|
|
|
$sub_apps->register( 'reactors', 'WordPoints_Class_Registry_Persistent' ); |
54
|
|
|
$sub_apps->register( 'extensions', 'WordPoints_Class_Registry_Persistent' ); |
55
|
|
|
$sub_apps->register( 'conditions', 'WordPoints_Class_Registry_Children' ); |
56
|
|
|
|
57
|
|
|
parent::init(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Gets the current mode that the API is in. |
62
|
|
|
* |
63
|
|
|
* By default 'standard' mode is on, unless in network context (such as in the |
64
|
|
|
* network admin) on multisite, when 'network' mode is the default. |
65
|
|
|
* |
66
|
|
|
* The current mode is used by reactors to determine which reaction type to offer |
67
|
|
|
* access to through the $reactions property. This is allows for generic code for |
68
|
|
|
* handling reactions to reference the $reactions property of the reactor, and |
69
|
|
|
* what type of reactions it will get will be determined based on the current |
70
|
|
|
* mode that is set. |
71
|
|
|
* |
72
|
|
|
* @since 1.0.0 |
73
|
|
|
* |
74
|
|
|
* @return string The slug of the current mode. |
75
|
|
|
*/ |
76
|
|
|
public function get_current_mode() { |
77
|
|
|
|
78
|
|
|
if ( ! isset( $this->current_mode ) ) { |
79
|
|
|
$this->current_mode = ( wordpoints_is_network_context() ? 'network' : 'standard' ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $this->current_mode; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Sets the current mode of the API. |
87
|
|
|
* |
88
|
|
|
* This function should be used very sparingly. The default mode which is set by |
89
|
|
|
* WordPoints should work for you in most cases. The primary reason that you |
90
|
|
|
* would ever need to set the mode yourself is if you have created your own |
91
|
|
|
* custom mode. Otherwise you probably shouldn't be using this function. |
92
|
|
|
* |
93
|
|
|
* @since 1.0.0 |
94
|
|
|
* |
95
|
|
|
* @param string $mode The slug of the mode to set as the current mode. |
96
|
|
|
*/ |
97
|
|
|
public function set_current_mode( $mode ) { |
98
|
|
|
$this->current_mode = $mode; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
// EOF |
103
|
|
|
|