1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class BackUpWordPress_Setup |
4
|
|
|
*/ |
5
|
|
|
class HMBKP_Setup { |
|
|
|
|
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Defines the minimum version of WordPress required by BWP. |
9
|
|
|
*/ |
10
|
|
|
const MIN_WP_VERSION = '3.9'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Defines the minimum version of PHP required by BWP. |
14
|
|
|
*/ |
15
|
|
|
const MIN_PHP_VERSION = '5.3.2'; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Setup the plugin defaults on activation |
19
|
|
|
*/ |
20
|
|
|
public static function activate() { |
21
|
|
|
|
22
|
|
|
if ( ! current_user_can( 'activate_plugins' ) ) { |
23
|
|
|
return; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// loads the translation files for the Error message in the wp_die call. |
27
|
|
|
load_plugin_textdomain( 'backupwordpress', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); |
28
|
|
|
|
29
|
|
|
if ( ! self::meets_requirements() ) { |
30
|
|
|
|
31
|
|
|
wp_die( self::get_notice_message(), __( 'BackUpWordPress', 'backupwordpress' ), array( 'back_link' => true ) ); |
32
|
|
|
|
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// Run deactivate on activation in-case it was deactivated manually |
36
|
|
|
self::deactivate(); |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Cleanup on plugin deactivation |
42
|
|
|
* |
43
|
|
|
* Removes options and clears all cron schedules |
44
|
|
|
*/ |
45
|
|
|
public static function deactivate() { |
46
|
|
|
|
47
|
|
|
if ( ! current_user_can( 'activate_plugins' ) ) { |
48
|
|
|
return; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
self::delete_schedules(); |
52
|
|
|
|
53
|
|
|
self::delete_transients(); |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Deletes the backup schedule database entries and WP Cron entries. |
59
|
|
|
*/ |
60
|
|
|
public static function delete_schedules() { |
61
|
|
|
|
62
|
|
|
// Delete Cron schedules. |
63
|
|
|
global $wpdb; |
|
|
|
|
64
|
|
|
|
65
|
|
|
$schedules = $wpdb->get_col( $wpdb->prepare( "SELECT option_name FROM $wpdb->options WHERE option_name LIKE %s", 'hmbkp_schedule_%' ) ); |
66
|
|
|
|
67
|
|
|
foreach ( array_map( array( 'self', 'trim_prefix' ), $schedules ) as $item ) { |
68
|
|
|
wp_clear_scheduled_hook( 'hmbkp_schedule_hook', array( 'id' => $item ) ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public static function trim_prefix( $item ) { |
75
|
|
|
return ltrim( $item, 'hmbkp_schedule_' ); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Deletes the plugin's transients from the database. |
80
|
|
|
*/ |
81
|
|
|
public static function delete_transients() { |
82
|
|
|
|
83
|
|
|
// Delete all transients |
84
|
|
|
$transients = array( |
85
|
|
|
'hmbkp_plugin_data', |
86
|
|
|
'hmbkp_directory_filesizes', |
87
|
|
|
'hmbkp_directory_filesizes_running', |
88
|
|
|
'hmbkp_wp_cron_test_beacon', |
89
|
|
|
'hm_backdrop', |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
array_map( 'delete_transient', $transients ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Deactivate BackUpWordPress. |
97
|
|
|
*/ |
98
|
|
|
public static function self_deactivate() { |
|
|
|
|
99
|
|
|
|
100
|
|
|
if ( ! current_user_can( 'activate_plugins' ) ) { |
101
|
|
|
return; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
if ( ! function_exists( 'deactivate_plugins' ) ) { |
105
|
|
|
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
deactivate_plugins( dirname( dirname(__FILE__ ) ) . '/backupwordpress.php' ); |
109
|
|
|
|
110
|
|
|
if ( isset( $_GET['activate'] ) ) { |
111
|
|
|
unset( $_GET['activate'] ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Determine if this WordPress install meets the minimum requirements for BWP to run. |
118
|
|
|
* |
119
|
|
|
* @return bool |
120
|
|
|
*/ |
121
|
|
|
public static function meets_requirements() { |
122
|
|
|
|
123
|
|
|
if ( false === self::is_supported_php_version() ) { |
124
|
|
|
return false; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
if ( false === self::is_supported_wp_version() ) { |
|
|
|
|
128
|
|
|
return false; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
return true; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Checks the current PHP version against the required version. |
136
|
|
|
* |
137
|
|
|
* @return bool 'Operator' parameter specified, returns a boolean. |
138
|
|
|
*/ |
139
|
|
|
protected static function is_supported_php_version() { |
140
|
|
|
|
141
|
|
|
return version_compare( phpversion(), self::MIN_PHP_VERSION, '>=' ); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Checks the current WordPress version against the required version. |
146
|
|
|
* |
147
|
|
|
* @return bool 'Operator' parameter specified, returns a boolean. |
148
|
|
|
*/ |
149
|
|
|
protected static function is_supported_wp_version() { |
150
|
|
|
|
151
|
|
|
return version_compare( get_bloginfo( 'version' ), self::MIN_WP_VERSION, '>=' ); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* Displays a user friendly message in the WordPress admin. |
156
|
|
|
*/ |
157
|
|
|
public static function display_admin_notices() { |
158
|
|
|
|
159
|
|
|
echo '<div class="error"><p>' . self::get_notice_message() . '</p></div>'; |
160
|
|
|
|
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Returns a localized user friendly error message. |
165
|
|
|
* |
166
|
|
|
* @return string |
167
|
|
|
*/ |
168
|
|
|
public static function get_notice_message() { |
169
|
|
|
|
170
|
|
|
return sprintf( |
171
|
|
|
__( 'BackUpWordPress requires PHP version %1$s or later and WordPress version %2$s or later to run. It has not been activated. %3$s%4$s%5$sLearn more%6$s', 'backupwordpress' ), |
172
|
|
|
self::MIN_PHP_VERSION, |
173
|
|
|
self::MIN_WP_VERSION, |
174
|
|
|
'<a href="', |
175
|
|
|
'https://bwp.hmn.md/unsupported-php-version-error/', |
176
|
|
|
'">', |
177
|
|
|
'</a>' |
178
|
|
|
); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
} |
182
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.