From d45c765c3220d4a9516d7ad0e65c96f943a4bb83 Mon Sep 17 00:00:00 2001 From: Malith Senaweera <6216000+malithsen@users.noreply.github.com> Date: Mon, 15 May 2023 11:14:48 -0500 Subject: [PATCH] Bring back the rest-user-exists-controller file (#6303) Co-authored-by: Shendy <73803630+shendy-a8c@users.noreply.github.com> --- changelog/fix-plugin-upgrade | 5 ++ .../class-wc-rest-user-exists-controller.php | 78 +++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 changelog/fix-plugin-upgrade create mode 100644 includes/admin/class-wc-rest-user-exists-controller.php 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, + ] + ); + } +} +