function test_is_a8c_email()
 {
     $a8c_emails = array('*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
     foreach ($a8c_emails as $a8c_email) {
         $this->assertTrue(WPCOM_VIP_Support_User::init()->is_a8c_email($a8c_email));
     }
     $non_a8c_emails = array('*****@*****.**', '*****@*****.**', '*****@*****.**', 'someone@automattic', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**');
     foreach ($non_a8c_emails as $non_a8c_email) {
         $this->assertFalse(WPCOM_VIP_Support_User::init()->is_a8c_email($non_a8c_email));
     }
 }
 /**
  * Marks the user with the provided ID as having a verified email.
  *
  *
  * <user-id>
  * : The WP User ID to mark as having a verified email address
  *
  * @subcommand verify
  *
  * ## EXAMPLES
  *
  *     wp vipsupport verify 99
  *
  */
 public function verify($args, $assoc_args)
 {
     $user_id = absint($args[0]);
     if (!$user_id) {
         \WP_CLI::error("Please provide the ID of the user to verify");
     }
     $user = get_user_by('id', $user_id);
     if (!$user) {
         \WP_CLI::error("Could not find a user with ID {$user_id}");
     }
     WPCOM_VIP_Support_User::init()->mark_user_email_verified($user->user_id, $user->user_email);
     // Print a success message
     \WP_CLI::success("Verified user {$user_id} with email {$user->user_email}, you can now change their role to VIP Support");
 }
/**
 * Is the given user an automattician?
 *
 * Note: This does a relatively weak check based on email address and their
 * VIP Support email address verification status (separate from other email verification)
 * It's possible to fake that data (it's just meta and user_email), so don't use this
 * for protecting sensitive info or performing sensitive tasks
 *
 * @param int The WP User id
 * @return bool Bool indicating if user is an Automattician
 */
function is_automattician($user_id = false)
{
    if ($user_id) {
        $user = new WP_User($user_id);
    } else {
        $user = wp_get_current_user();
    }
    if (!isset($user->ID) || !$user->ID) {
        return false;
    }
    // Check that their address is an a8c one, *and* they have validated that address
    if (!class_exists('WPCOM_VIP_Support_User')) {
        return false;
    }
    // $vip_support = WPCOM_VIP_Support_User::init();
    if (WPCOM_VIP_Support_User::is_verified_automattician($user->ID)) {
        return true;
    }
    return false;
}
 /**
  * Marks the user with the provided ID as having a verified email.
  *
  *
  * <user-id>
  * : The WP User ID to mark as having a verified email address
  *
  * @subcommand verify
  *
  * ## EXAMPLES
  *
  *     wp vipsupport verify 99
  *
  */
 public function verify($args)
 {
     $user_id = absint($args[0]);
     if (!$user_id) {
         \WP_CLI::error("Please provide the ID of the user to verify");
     }
     $user = get_user_by('id', $user_id);
     if (!$user) {
         \WP_CLI::error("Could not find a user with ID {$user_id}");
     }
     // If this is a multisite, commence super powers!
     if (is_multisite()) {
         grant_super_admin($user->ID);
     }
     WPCOM_VIP_Support_User::init()->mark_user_email_verified($user->ID, $user->user_email);
     // Print a success message
     \WP_CLI::success("Verified user {$user_id} with email {$user->user_email}, you can now change their role to VIP Support");
 }
     * @param string $user_email The email of the user to generate the hash for
     *
     * @return string The check hash for the values passed
     */
    protected function create_check_hash($user_id, $verification_code, $user_email)
    {
        return wp_hash($user_id . $verification_code . $user_email);
    }
    /**
     * @TODO Write a method description
     *
     * @param int $user_id The ID of the user to mark as having a verified email
     * @param string $user_email The email which has been verified
     */
    public function mark_user_email_verified($user_id, $user_email)
    {
        update_user_meta($user_id, self::META_EMAIL_VERIFIED, $user_email);
        delete_user_meta($user_id, self::META_VERIFICATION_DATA);
        delete_user_meta($user_id, self::META_EMAIL_NEEDS_VERIFICATION);
    }
    /**
     * @param int $user_id The ID of the user to mark as NOT (any longer) having a verified email
     */
    protected function mark_user_email_unverified($user_id)
    {
        update_user_meta($user_id, self::META_EMAIL_VERIFIED, false);
        update_user_meta($user_id, self::META_EMAIL_NEEDS_VERIFICATION, false);
    }
}
WPCOM_VIP_Support_User::init();