← All changes
|
src/component/two-factor/providers/class-backup-codes.php
+8
-7
5.6.0
→
6.3.0
View file →
| @@ -89,9 +89,9 @@ | ||
| 89 | 89 | * @param WP_User $user The user object. |
| 90 | 90 | */ |
| 91 | 91 | public function init_provider( WP_User $user ): void { |
| 92 | 92 | $this->is_activated = get_user_meta( $user->ID, self::BACKUP_CODE_START, true ); |
| 93 | - $this->description = empty( $this->is_activated ) | |
| 93 | + $this->description = 1 !== $this->is_activated | |
| 94 | 94 | ? esc_html__( 'Generate non-expirable backup codes that can be used to log in once.', 'defender-security' ) |
| 95 | 95 | : esc_html__( 'Each backup code can only be used to log in once.', 'defender-security' ); |
| 96 | 96 | } |
| 97 | 97 | |
| @@ -170,9 +170,9 @@ | ||
| 170 | 170 | * @return int |
| 171 | 171 | */ |
| 172 | 172 | public static function get_unused_codes_for_user( WP_User $user ): int { |
| 173 | 173 | $backup_codes = get_user_meta( $user->ID, self::BACKUP_CODE_VALUES, true ); |
| 174 | - if ( is_array( $backup_codes ) && ! empty( $backup_codes ) ) { | |
| 174 | + if ( is_array( $backup_codes ) && array() !== $backup_codes ) { | |
| 175 | 175 | return count( $backup_codes ); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | return 0; |
| @@ -203,9 +203,9 @@ | ||
| 203 | 203 | if ( ! is_object( $user ) ) { |
| 204 | 204 | return; |
| 205 | 205 | } |
| 206 | 206 | // Is User role from common list checked? |
| 207 | - if ( empty( array_intersect( $user->roles, $this->get_model()->user_roles ) ) ) { | |
| 207 | + if ( array() === array_intersect( $user->roles, $this->get_model()->user_roles ) ) { | |
| 208 | 208 | return; |
| 209 | 209 | } |
| 210 | 210 | // Return if the provider is not enabled. |
| 211 | 211 | if ( ! in_array( self::$slug, $this->get_component()->get_enabled_providers_for_user( $user->ID ), true ) ) { |
| @@ -246,9 +246,9 @@ | ||
| 246 | 246 | $cond = $this->get_component()->is_checked_enabled_provider_by_slug( $user, self::$slug ) |
| 247 | 247 | && $this->is_available_for_user( $user ); |
| 248 | 248 | $attr = $cond ? '' : ' disabled'; |
| 249 | 249 | // Check whether codes were generated before or not. |
| 250 | - if ( empty( $this->is_activated ) ) { | |
| 250 | + if ( 1 !== $this->is_activated ) { | |
| 251 | 251 | $button_text = esc_html__( 'Generate Backup Codes', 'defender-security' ); |
| 252 | 252 | $class = 'hidden'; |
| 253 | 253 | $count = 0; |
| 254 | 254 | $show_notice = 'no'; |
| @@ -304,9 +304,10 @@ | ||
| 304 | 304 | } else { |
| 305 | 305 | $num_codes = self::BACKUP_CODE_COUNT; |
| 306 | 306 | } |
| 307 | 307 | // Add a flag if it haven't existed yet. |
| 308 | - if ( empty( get_user_meta( $user->ID, self::BACKUP_CODE_START, true ) ) ) { | |
| 308 | + $backup_code_start = get_user_meta( $user->ID, self::BACKUP_CODE_START, true ); | |
| 309 | + if ( in_array( $backup_code_start, array( false, '', array() ), true ) ) { | |
| 309 | 310 | update_user_meta( $user->ID, self::BACKUP_CODE_START, 1 ); |
| 310 | 311 | } |
| 311 | 312 | if ( isset( $args['method'] ) && 'append' === $args['method'] ) { |
| 312 | 313 | $codes_hashed = (array) get_user_meta( $user->ID, self::BACKUP_CODE_VALUES, true ); |
| @@ -368,9 +369,9 @@ | ||
| 368 | 369 | */ |
| 369 | 370 | protected function validate_code( WP_User $user, string $code ) { |
| 370 | 371 | $backup_codes = get_user_meta( $user->ID, self::BACKUP_CODE_VALUES, true ); |
| 371 | 372 | |
| 372 | - if ( is_array( $backup_codes ) && ! empty( $backup_codes ) ) { | |
| 373 | + if ( is_array( $backup_codes ) && array() !== $backup_codes ) { | |
| 373 | 374 | foreach ( $backup_codes as $code_hashed ) { |
| 374 | 375 | if ( wp_check_password( $code, $code_hashed, $user->ID ) ) { |
| 375 | 376 | $this->delete_code( $user, $code_hashed ); |
| 376 | 377 | |
| @@ -382,9 +383,9 @@ | ||
| 382 | 383 | $lockout_message = $this->get_component()->verify_attempt( $user->ID, self::$slug ); |
| 383 | 384 | |
| 384 | 385 | return new WP_Error( |
| 385 | 386 | 'opt_fail', |
| 386 | - empty( $lockout_message ) ? esc_html__( 'ERROR: Invalid verification code.', 'defender-security' ) : $lockout_message | |
| 387 | + '' === $lockout_message ? esc_html__( 'ERROR: Invalid verification code.', 'defender-security' ) : $lockout_message | |
| 387 | 388 | ); |
| 388 | 389 | } |
| 389 | 390 | |
| 390 | 391 | /** |