HEX
Server: nginx
System: Linux pool195-106-36.bur.atomicsites.net 6.12.57+deb12-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.57-1~bpo12+1 (2025-11-17) x86_64
User: (0)
PHP: 8.3.32
Disabled: pcntl_fork
Upload Files
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 ];
	}
}