File: /wordpress/plugins/wp-cloud-client/1.1.2/src/Handler/CheckUserHandler.php
<?php
declare(strict_types=1);
namespace VPlugins\WPCloudClient\Handler;
final class CheckUserHandler extends AbstractHandler {
/**
* Return the action name.
*
* @return string Action name.
*/
public function action(): string {
return 'check_user';
}
/**
* Check whether a user exists by email address.
*
* @param array<string, mixed> $params Action parameters.
* @return array<string, mixed> Result containing existence flag.
*
* @throws \InvalidArgumentException If required parameters are missing.
*/
public function execute( array $params ): array {
$this->requireParams( $params, 'email' );
global $wpdb;
$email = sanitize_email( $params['email'] );
$exists = (int) $wpdb->get_var(
$wpdb->prepare(
"SELECT COUNT(*) FROM {$wpdb->users} WHERE user_email = %s",
$email,
),
);
if ( $exists > 0 ) {
return [ 'exists' => true ];
}
$adminEmail = get_option( 'admin_email', '' );
if ( ! empty( $adminEmail ) && $adminEmail === $email ) {
return [ 'exists' => true ];
}
return [ 'exists' => false ];
}
}