This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Class BackUpWordPress_Setup |
||
4 | */ |
||
5 | class HMBKP_Setup { |
||
0 ignored issues
–
show
|
|||
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; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
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 | public static function trim_prefix( $item ) { |
||
73 | return ltrim( $item, 'hmbkp_schedule_' ); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * Deletes the plugin's transients from the database. |
||
78 | */ |
||
79 | public static function delete_transients() { |
||
80 | |||
81 | // Delete all transients |
||
82 | $transients = array( |
||
83 | 'hmbkp_plugin_data', |
||
84 | 'hmbkp_directory_filesizes', |
||
85 | 'hmbkp_directory_filesizes_running', |
||
86 | 'hmbkp_wp_cron_test_beacon', |
||
87 | 'hm_backdrop', |
||
88 | ); |
||
89 | |||
90 | array_map( 'delete_transient', $transients ); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Deactivate BackUpWordPress. |
||
95 | */ |
||
96 | public static function self_deactivate() { |
||
97 | |||
98 | if ( ! current_user_can( 'activate_plugins' ) ) { |
||
99 | return; |
||
100 | } |
||
101 | |||
102 | if ( ! function_exists( 'deactivate_plugins' ) ) { |
||
103 | require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); |
||
104 | } |
||
105 | |||
106 | deactivate_plugins( dirname( dirname( __FILE__ ) ) . '/backupwordpress.php' ); |
||
107 | |||
108 | if ( isset( $_GET['activate'] ) ) { |
||
109 | unset( $_GET['activate'] ); |
||
110 | } |
||
111 | |||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Determine if this WordPress install meets the minimum requirements for BWP to run. |
||
116 | * |
||
117 | * @return bool |
||
118 | */ |
||
119 | public static function meets_requirements() { |
||
120 | |||
121 | if ( false === self::is_supported_php_version() ) { |
||
122 | return false; |
||
123 | } |
||
124 | |||
125 | if ( false === self::is_supported_wp_version() ) { |
||
126 | return false; |
||
127 | } |
||
128 | |||
129 | return true; |
||
130 | } |
||
131 | |||
132 | /** |
||
133 | * Checks the current PHP version against the required version. |
||
134 | * |
||
135 | * @return bool 'Operator' parameter specified, returns a boolean. |
||
136 | */ |
||
137 | protected static function is_supported_php_version() { |
||
138 | |||
139 | return version_compare( phpversion(), self::MIN_PHP_VERSION, '>=' ); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Checks the current WordPress version against the required version. |
||
144 | * |
||
145 | * @return bool 'Operator' parameter specified, returns a boolean. |
||
146 | */ |
||
147 | protected static function is_supported_wp_version() { |
||
148 | |||
149 | return version_compare( get_bloginfo( 'version' ), self::MIN_WP_VERSION, '>=' ); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * Displays a user friendly message in the WordPress admin. |
||
154 | */ |
||
155 | public static function display_admin_notices() { |
||
156 | |||
157 | echo '<div class="error"><p>' . self::get_notice_message() . '</p></div>'; |
||
158 | |||
159 | } |
||
160 | |||
161 | /** |
||
162 | * Returns a localized user friendly error message. |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | public static function get_notice_message() { |
||
167 | |||
168 | return sprintf( |
||
169 | __( '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' ), |
||
170 | self::MIN_PHP_VERSION, |
||
171 | self::MIN_WP_VERSION, |
||
172 | '<a href="', |
||
173 | 'https://bwp.hmn.md/unsupported-php-version-error/', |
||
174 | '">', |
||
175 | '</a>' |
||
176 | ); |
||
177 | } |
||
178 | } |
||
179 |
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.