← All changes
|
jetpack_vendor/automattic/jetpack-plugins-installer/src/class-plugins-installer.php
+12
-48
12.1.3
→
16.3-beta
View file →
| @@ -73,8 +73,11 @@ | ||
| 73 | 73 | if ( is_multisite() && ! current_user_can( 'manage_network' ) ) { |
| 74 | 74 | return new WP_Error( 'not_allowed', __( 'You are not allowed to install plugins on this site.', 'jetpack-plugins-installer' ) ); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | + // Initialize admin filters to make sure WordPress post-install hooks run. Handles things like language packs. | |
| 78 | + include_once ABSPATH . '/wp-admin/includes/admin-filters.php'; | |
| 79 | + | |
| 77 | 80 | $skin = new Automatic_Install_Skin(); |
| 78 | 81 | $upgrader = new Plugin_Upgrader( $skin ); |
| 79 | 82 | $zip_url = self::generate_wordpress_org_plugin_download_link( $slug ); |
| 80 | 83 | $mc_stats = new A8c_Mc_Stats(); |
| @@ -92,10 +95,10 @@ | ||
| 92 | 95 | $error = __( 'There was an error installing your plugin', 'jetpack-plugins-installer' ); |
| 93 | 96 | } |
| 94 | 97 | |
| 95 | 98 | if ( ! $result ) { |
| 96 | - $error_code = $upgrader->skin->get_main_error_code(); | |
| 97 | - $message = $upgrader->skin->get_main_error_message(); | |
| 99 | + $error_code = $skin->get_main_error_code(); | |
| 100 | + $message = $skin->get_main_error_message(); | |
| 98 | 101 | $error = $message ? $message : __( 'An unknown error occurred during installation', 'jetpack-plugins-installer' ); |
| 99 | 102 | } |
| 100 | 103 | |
| 101 | 104 | if ( ! empty( $error ) ) { |
| @@ -185,9 +188,9 @@ | ||
| 185 | 188 | |
| 186 | 189 | /** |
| 187 | 190 | * Safely checks if the plugin is active |
| 188 | 191 | * |
| 189 | - * @since $next-version$ | |
| 192 | + * @since 0.1.0 | |
| 190 | 193 | * |
| 191 | 194 | * @param string $plugin_file The plugin file to check. |
| 192 | 195 | * @return bool |
| 193 | 196 | */ |
| @@ -198,9 +201,9 @@ | ||
| 198 | 201 | |
| 199 | 202 | /** |
| 200 | 203 | * Safely checks if the plugin is active for network |
| 201 | 204 | * |
| 202 | - * @since $next-version$ | |
| 205 | + * @since 0.1.0 | |
| 203 | 206 | * |
| 204 | 207 | * @param string $plugin_file The plugin file to check. |
| 205 | 208 | * @return bool |
| 206 | 209 | */ |
| @@ -238,54 +241,15 @@ | ||
| 238 | 241 | |
| 239 | 242 | /** |
| 240 | 243 | * Determine if the current request is activating a plugin from the plugins page. |
| 241 | 244 | * |
| 245 | + * @deprecated 0.4.0 | |
| 246 | + * @see Paths::is_current_request_activating_plugin_from_plugins_screen() | |
| 247 | + * | |
| 242 | 248 | * @param string $plugin Plugin file path to check. |
| 243 | 249 | * @return bool |
| 244 | 250 | */ |
| 245 | 251 | public static function is_current_request_activating_plugin_from_plugins_screen( $plugin ) { |
| 246 | - // Filter out common async request contexts | |
| 247 | - if ( | |
| 248 | - wp_doing_ajax() || | |
| 249 | - ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || | |
| 250 | - ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) || | |
| 251 | - ( defined( 'WP_CLI' ) && WP_CLI ) | |
| 252 | - ) { | |
| 253 | - return false; | |
| 254 | - } | |
| 255 | - | |
| 256 | - if ( isset( $_SERVER['SCRIPT_NAME'] ) ) { | |
| 257 | - $request_file = esc_url_raw( wp_unslash( $_SERVER['SCRIPT_NAME'] ) ); | |
| 258 | - } elseif ( isset( $_SERVER['REQUEST_URI'] ) ) { | |
| 259 | - list( $request_file ) = explode( '?', esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); | |
| 260 | - } else { | |
| 261 | - return false; | |
| 262 | - } | |
| 263 | - | |
| 264 | - // Not the plugins page | |
| 265 | - if ( strpos( $request_file, 'wp-admin/plugins.php' ) === false ) { | |
| 266 | - return false; | |
| 267 | - } | |
| 268 | - | |
| 269 | - // Same method to get the action as used by plugins.php | |
| 270 | - $wp_list_table = _get_list_table( 'WP_Plugins_List_Table' ); | |
| 271 | - $action = $wp_list_table->current_action(); | |
| 272 | - | |
| 273 | - // Not a singular activation | |
| 274 | - // This also means that if the plugin is activated as part of a group ( bulk activation ), this function will return false here. | |
| 275 | - if ( 'activate' !== $action ) { | |
| 276 | - return false; | |
| 277 | - } | |
| 278 | - | |
| 279 | - // Check the nonce associated with the plugin activation | |
| 280 | - // We are not changing any data here, so this is not super necessary, it's just a best practice before using the form data from $_REQUEST. | |
| 281 | - check_admin_referer( 'activate-plugin_' . $plugin ); | |
| 282 | - | |
| 283 | - // Not the right plugin | |
| 284 | - $requested_plugin = isset( $_REQUEST['plugin'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['plugin'] ) ) : null; | |
| 285 | - if ( $requested_plugin !== $plugin ) { | |
| 286 | - return false; | |
| 287 | - } | |
| 288 | - | |
| 289 | - return true; | |
| 252 | + _deprecated_function( __METHOD__, '0.4.0', 'Automattic\\Jetpack\\Paths::is_current_request_activating_plugin_from_plugins_screen()' ); | |
| 253 | + return ( new Paths() )->is_current_request_activating_plugin_from_plugins_screen( $plugin ); | |
| 290 | 254 | } |
| 291 | 255 | } |