* : User ID, login, or email. * * @when after_wp_load */ public function status( $args ) { $user = $this->resolve( $args[0] ); if ( ! $user ) { \WP_CLI::error( 'User not found.' ); } $plugin = wpcev(); $flag = get_user_meta( $user->ID, WPCEV_Tokens::META_VERIFIED, true ); $sent = (int) get_user_meta( $user->ID, WPCEV_Tokens::META_SENT_AT, true ); $exempt = $plugin->tokens->is_role_exempt( $user->ID ); if ( '' === $flag ) { $state = 'grandfathered (no meta — treated as verified)'; } elseif ( '1' === (string) $flag ) { $state = 'verified'; } else { $state = 'unverified'; } \WP_CLI::log( sprintf( 'User: %s <%s> (#%d)', $user->user_login, $user->user_email, $user->ID ) ); \WP_CLI::log( sprintf( 'Roles: %s', implode( ', ', $user->roles ) ) ); \WP_CLI::log( sprintf( 'Status: %s', $state ) ); \WP_CLI::log( sprintf( 'Exempt: %s', $exempt ? 'yes' : 'no' ) ); \WP_CLI::log( sprintf( 'Last email sent: %s', $sent ? gmdate( 'Y-m-d H:i:s', $sent ) . ' UTC' : '—' ) ); } /** * Mark a user as verified manually. * * ## OPTIONS * * * : User ID, login, or email. * * @when after_wp_load */ public function verify( $args ) { $user = $this->resolve( $args[0] ); if ( ! $user ) { \WP_CLI::error( 'User not found.' ); } wpcev()->tokens->mark_verified( $user->ID, 'admin' ); \WP_CLI::success( sprintf( 'User %d marked verified.', $user->ID ) ); } /** * Revoke a user's verification (issues a fresh token + sends a new email). * * ## OPTIONS * * * : User ID, login, or email. * * [--no-email] * : Skip sending the verification email; just flip the flag. * * @when after_wp_load */ public function unverify( $args, $assoc ) { $user = $this->resolve( $args[0] ); if ( ! $user ) { \WP_CLI::error( 'User not found.' ); } $plugin = wpcev(); $plugin->tokens->unmark_verified( $user->ID, 'admin' ); if ( empty( $assoc['no-email'] ) ) { $result = $plugin->mailer->send_verification( $user->ID, false ); \WP_CLI::log( sprintf( 'Email send result: %s', $result ) ); } \WP_CLI::success( sprintf( 'User %d marked unverified.', $user->ID ) ); } /** * Send a fresh verification email. * * ## OPTIONS * * * : User ID, login, or email. * * [--force] * : Bypass the resend wait (setting "Resend wait", default 60 seconds). * * @when after_wp_load */ public function resend( $args, $assoc ) { $user = $this->resolve( $args[0] ); if ( ! $user ) { \WP_CLI::error( 'User not found.' ); } $throttle = empty( $assoc['force'] ); $result = wpcev()->mailer->send_verification( $user->ID, $throttle ); switch ( $result ) { case 'sent': \WP_CLI::success( sprintf( 'Verification email sent to %s.', $user->user_email ) ); break; case 'throttled': \WP_CLI::warning( 'Throttled — pass --force to override.' ); break; case 'failed': \WP_CLI::error( 'wp_mail() returned false.' ); break; default: \WP_CLI::error( 'Send result: ' . $result ); } } }