1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* XCloner - Backup and Restore backup plugin for Wordpress |
4
|
|
|
* |
5
|
|
|
* class-xcloner-loader.php |
6
|
|
|
* @author Liuta Ovidiu <[email protected]> |
7
|
|
|
* |
8
|
|
|
* This program is free software; you can redistribute it and/or modify |
9
|
|
|
* it under the terms of the GNU General Public License as published by |
10
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
11
|
|
|
* (at your option) any later version. |
12
|
|
|
* |
13
|
|
|
* This program is distributed in the hope that it will be useful, |
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16
|
|
|
* GNU General Public License for more details. |
17
|
|
|
* |
18
|
|
|
* You should have received a copy of the GNU General Public License |
19
|
|
|
* along with this program; if not, write to the Free Software |
20
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
21
|
|
|
* MA 02110-1301, USA. |
22
|
|
|
* |
23
|
|
|
* @link https://github.com/ovidiul/XCloner-Wordpress |
24
|
|
|
* |
25
|
|
|
* @modified 7/25/18 1:46 PM |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Register all actions and filters for the plugin. |
32
|
|
|
* |
33
|
|
|
* Maintain a list of all hooks that are registered throughout |
34
|
|
|
* the plugin, and register them with the WordPress API. Call the |
35
|
|
|
* run function to execute the list of actions and filters. |
36
|
|
|
* |
37
|
|
|
* @package Xcloner |
38
|
|
|
* @subpackage Xcloner/includes |
39
|
|
|
* @author Liuta Ovidiu <[email protected]> |
40
|
|
|
*/ |
41
|
|
|
class Xcloner_Loader |
42
|
|
|
{ |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The array of actions registered with WordPress. |
46
|
|
|
* |
47
|
|
|
* @since 1.0.0 |
48
|
|
|
* @access protected |
49
|
|
|
* @var array $actions The actions registered with WordPress to fire when the plugin loads. |
50
|
|
|
*/ |
51
|
|
|
protected $actions; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* The array of filters registered with WordPress. |
55
|
|
|
* |
56
|
|
|
* @since 1.0.0 |
57
|
|
|
* @access protected |
58
|
|
|
* @var array $filters The filters registered with WordPress to fire when the plugin loads. |
59
|
|
|
*/ |
60
|
|
|
protected $filters; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var Xcloner |
64
|
|
|
*/ |
65
|
|
|
private $xcloner_plugin; |
|
|
|
|
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @var Xcloner |
69
|
|
|
*/ |
70
|
|
|
private $xcloner_container; |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Initialize the collections used to maintain the actions and filters. |
75
|
|
|
* |
76
|
|
|
* Xcloner_Loader constructor. |
77
|
|
|
* @param Xcloner $xcloner_container |
78
|
|
|
*/ |
79
|
|
|
public function __construct(Xcloner $xcloner_container) |
80
|
|
|
{ |
81
|
|
|
|
82
|
|
|
$this->actions = array(); |
83
|
|
|
$this->filters = array(); |
84
|
|
|
|
85
|
|
|
$this->xcloner_container = $xcloner_container; |
86
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Add XCloner to Admin Menu |
91
|
|
|
*/ |
92
|
|
|
public function xcloner_backup_add_admin_menu() |
93
|
|
|
{ |
94
|
|
|
if (function_exists('add_menu_page')) { |
95
|
|
|
add_menu_page(__('Site Backup', 'xcloner-backup-and-restore'), |
96
|
|
|
__('Site Backup', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page', |
97
|
|
|
array($this->xcloner_container, 'xcloner_display'), 'dashicons-backup'); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if (function_exists('add_submenu_page')) { |
101
|
|
|
|
102
|
|
|
add_submenu_page('xcloner_init_page', __('XCloner Dashboard', 'xcloner-backup-and-restore'), |
103
|
|
|
__('Dashboard', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_init_page', |
104
|
|
|
array($this->xcloner_container, 'xcloner_display')); |
105
|
|
|
add_submenu_page('xcloner_init_page', __('XCloner Backup Settings', 'xcloner-backup-and-restore'), |
106
|
|
|
__('Settings', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_settings_page', |
107
|
|
|
array($this->xcloner_container, 'xcloner_display')); |
108
|
|
|
add_submenu_page('xcloner_init_page', __('Remote Storage Settings', 'xcloner-backup-and-restore'), |
109
|
|
|
__('Remote Storage', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_remote_storage_page', |
110
|
|
|
array($this->xcloner_container, 'xcloner_display')); |
111
|
|
|
add_submenu_page('xcloner_init_page', __('Manage Backups', 'xcloner-backup-and-restore'), |
112
|
|
|
__('Manage Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_manage_backups_page', |
113
|
|
|
array($this->xcloner_container, 'xcloner_display')); |
114
|
|
|
add_submenu_page('xcloner_init_page', __('Scheduled Backups', 'xcloner-backup-and-restore'), |
115
|
|
|
__('Scheduled Backups', 'xcloner-backup-and-restore'), 'manage_options', |
116
|
|
|
'xcloner_scheduled_backups_page', array($this->xcloner_container, 'xcloner_display')); |
117
|
|
|
add_submenu_page('xcloner_init_page', __('Generate Backups', 'xcloner-backup-and-restore'), |
118
|
|
|
__('Generate Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_generate_backups_page', |
119
|
|
|
array($this->xcloner_container, 'xcloner_display')); |
120
|
|
|
add_submenu_page('xcloner_init_page', __('Restore Backups', 'xcloner-backup-and-restore'), |
121
|
|
|
__('Restore Backups', 'xcloner-backup-and-restore'), 'manage_options', 'xcloner_restore_page', |
122
|
|
|
array($this->xcloner_container, 'xcloner_display')); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Add a new action to the collection to be registered with WordPress. |
130
|
|
|
* |
131
|
|
|
* @since 1.0.0 |
132
|
|
|
* @param string $hook The name of the WordPress action that is being registered. |
133
|
|
|
* @param object $component A reference to the instance of the object on which the action is defined. |
134
|
|
|
* @param string $callback The name of the function definition on the $component. |
135
|
|
|
* @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
136
|
|
|
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1. |
137
|
|
|
*/ |
138
|
|
|
public function add_action($hook, $component, $callback, $priority = 10, $accepted_args = 1) |
139
|
|
|
{ |
140
|
|
|
$this->actions = $this->add($this->actions, $hook, $component, $callback, $priority, $accepted_args); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Add a new filter to the collection to be registered with WordPress. |
145
|
|
|
* |
146
|
|
|
* @since 1.0.0 |
147
|
|
|
* @param string $hook The name of the WordPress filter that is being registered. |
148
|
|
|
* @param object $component A reference to the instance of the object on which the filter is defined. |
149
|
|
|
* @param string $callback The name of the function definition on the $component. |
150
|
|
|
* @param int $priority Optional. he priority at which the function should be fired. Default is 10. |
151
|
|
|
* @param int $accepted_args Optional. The number of arguments that should be passed to the $callback. Default is 1 |
152
|
|
|
*/ |
153
|
|
|
public function add_filter($hook, $component, $callback, $priority = 10, $accepted_args = 1) |
154
|
|
|
{ |
155
|
|
|
$this->filters = $this->add($this->filters, $hook, $component, $callback, $priority, $accepted_args); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* A utility function that is used to register the actions and hooks into a single |
160
|
|
|
* collection. |
161
|
|
|
* |
162
|
|
|
* @since 1.0.0 |
163
|
|
|
* @access private |
164
|
|
|
* @param array $hooks The collection of hooks that is being registered (that is, actions or filters). |
165
|
|
|
* @param string $hook The name of the WordPress filter that is being registered. |
166
|
|
|
* @param object $component A reference to the instance of the object on which the filter is defined. |
167
|
|
|
* @param string $callback The name of the function definition on the $component. |
168
|
|
|
* @param int $priority The priority at which the function should be fired. |
169
|
|
|
* @param int $accepted_args The number of arguments that should be passed to the $callback. |
170
|
|
|
* @return array The collection of actions and filters registered with WordPress. |
171
|
|
|
*/ |
172
|
|
|
private function add($hooks, $hook, $component, $callback, $priority, $accepted_args) |
173
|
|
|
{ |
174
|
|
|
|
175
|
|
|
$hooks[] = array( |
176
|
|
|
'hook' => $hook, |
177
|
|
|
'component' => $component, |
178
|
|
|
'callback' => $callback, |
179
|
|
|
'priority' => $priority, |
180
|
|
|
'accepted_args' => $accepted_args |
181
|
|
|
); |
182
|
|
|
|
183
|
|
|
return $hooks; |
184
|
|
|
|
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Register the filters and actions with WordPress. |
189
|
|
|
* |
190
|
|
|
* @since 1.0.0 |
191
|
|
|
*/ |
192
|
|
|
public function run() |
193
|
|
|
{ |
194
|
|
|
|
195
|
|
|
foreach ($this->filters as $hook) { |
196
|
|
|
add_filter($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], |
197
|
|
|
$hook['accepted_args']); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
foreach ($this->actions as $hook) { |
201
|
|
|
add_action($hook['hook'], array($hook['component'], $hook['callback']), $hook['priority'], |
202
|
|
|
$hook['accepted_args']); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
} |
208
|
|
|
|