diff --git a/changelog/fix-plugin-upgrade b/changelog/fix-plugin-upgrade new file mode 100644 index 00000000000..4f4b515c90b --- /dev/null +++ b/changelog/fix-plugin-upgrade @@ -0,0 +1,5 @@ +Significance: patch +Type: fix +Comment: Temporary fix to hide an error notice that's printed during the plugin upgrade + + diff --git a/includes/admin/class-wc-rest-user-exists-controller.php b/includes/admin/class-wc-rest-user-exists-controller.php new file mode 100644 index 00000000000..920b1f09459 --- /dev/null +++ b/includes/admin/class-wc-rest-user-exists-controller.php @@ -0,0 +1,78 @@ +namespace, + '/' . $this->rest_base, + [ + 'methods' => WP_REST_Server::CREATABLE, + 'callback' => [ $this, 'user_exists' ], + 'permission_callback' => '__return_true', + 'args' => [ + 'email' => [ + 'required' => true, + 'description' => __( 'Email address.', 'woocommerce-payments' ), + 'type' => 'string', + 'format' => 'email', + ], + ], + ] + ); + } + + /** + * Retrieve if a user exists by email address. + * + * @param WP_REST_Request $request Full details about the request. + * + * @return WP_REST_Response + */ + public function user_exists( WP_REST_Request $request ): WP_REST_Response { + $email = $request->get_param( 'email' ); + $email_exists = ! empty( email_exists( $email ) ); + $message = null; + + if ( $email_exists ) { + // Use this function to show the core error message. + $error = wc_create_new_customer( $email ); + $message = $error->get_error_message(); + } + + return new WP_REST_Response( + [ + 'user-exists' => $email_exists, + 'message' => $message, + ] + ); + } +} +