wp/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
--- a/wp/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php	Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/rest-api/endpoints/class-wp-rest-plugins-controller.php	Tue Sep 27 16:37:53 2022 +0200
@@ -265,10 +265,14 @@
 	 *
 	 * @since 5.5.0
 	 *
+	 * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
+	 *
 	 * @param WP_REST_Request $request Full details about the request.
 	 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
 	 */
 	public function create_item( $request ) {
+		global $wp_filesystem;
+
 		require_once ABSPATH . 'wp-admin/includes/file.php';
 		require_once ABSPATH . 'wp-admin/includes/plugin.php';
 		require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php';
@@ -329,19 +333,32 @@
 		}
 
 		if ( is_null( $result ) ) {
-			global $wp_filesystem;
 			// Pass through the error from WP_Filesystem if one was raised.
-			if ( $wp_filesystem instanceof WP_Filesystem_Base && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors() ) {
-				return new WP_Error( 'unable_to_connect_to_filesystem', $wp_filesystem->errors->get_error_message(), array( 'status' => 500 ) );
+			if ( $wp_filesystem instanceof WP_Filesystem_Base
+				&& is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->has_errors()
+			) {
+				return new WP_Error(
+					'unable_to_connect_to_filesystem',
+					$wp_filesystem->errors->get_error_message(),
+					array( 'status' => 500 )
+				);
 			}
 
-			return new WP_Error( 'unable_to_connect_to_filesystem', __( 'Unable to connect to the filesystem. Please confirm your credentials.' ), array( 'status' => 500 ) );
+			return new WP_Error(
+				'unable_to_connect_to_filesystem',
+				__( 'Unable to connect to the filesystem. Please confirm your credentials.' ),
+				array( 'status' => 500 )
+			);
 		}
 
 		$file = $upgrader->plugin_info();
 
 		if ( ! $file ) {
-			return new WP_Error( 'unable_to_determine_installed_plugin', __( 'Unable to determine what plugin was installed.' ), array( 'status' => 500 ) );
+			return new WP_Error(
+				'unable_to_determine_installed_plugin',
+				__( 'Unable to determine what plugin was installed.' ),
+				array( 'status' => 500 )
+			);
 		}
 
 		if ( 'inactive' !== $request['status'] ) {
@@ -364,7 +381,7 @@
 		$installed_locales = apply_filters( 'plugins_update_check_locales', $installed_locales );
 
 		$language_packs = array_map(
-			function( $item ) {
+			static function( $item ) {
 				return (object) $item;
 			},
 			$api->language_packs
@@ -372,7 +389,7 @@
 
 		$language_packs = array_filter(
 			$language_packs,
-			function( $pack ) use ( $installed_locales ) {
+			static function( $pack ) use ( $installed_locales ) {
 				return in_array( $pack->language, $installed_locales, true );
 			}
 		);