| @@ -369,10 +369,10 @@ | ||
| 369 | 369 | * |
| 370 | 370 | * @return array |
| 371 | 371 | */ |
| 372 | 372 | public function get_access_status( $ua ): array { |
| 373 | - $blocklist = str_replace( '#', '\#', $this->get_all_selected_blocklist_ua() ); | |
| 374 | - $allowlist = str_replace( '#', '\#', $this->get_lockout_list( 'allowlist' ) ); | |
| 373 | + $blocklist = $this->get_all_selected_blocklist_ua(); | |
| 374 | + $allowlist = $this->get_lockout_list( 'allowlist' ); | |
| 375 | 375 | |
| 376 | 376 | // Escape regex special characters in each item before building the pattern. |
| 377 | 377 | $blocklist_escaped = array_map( 'preg_quote', $blocklist, array_fill( 0, count( $blocklist ), '#' ) ); |
| 378 | 378 | $allowlist_escaped = array_map( 'preg_quote', $allowlist, array_fill( 0, count( $allowlist ), '#' ) ); |
| @@ -379,12 +379,12 @@ | ||
| 379 | 379 | |
| 380 | 380 | $blocklist_regex_pattern = '#' . implode( '|', $blocklist_escaped ) . '#i'; |
| 381 | 381 | $allowlist_regex_pattern = '#' . implode( '|', $allowlist_escaped ) . '#i'; |
| 382 | 382 | |
| 383 | - $blocklist_match = preg_match( $blocklist_regex_pattern, $ua ); | |
| 384 | - $allowlist_match = preg_match( $allowlist_regex_pattern, $ua ); | |
| 383 | + $blocklist_match = count( $blocklist ) > 0 && 1 === preg_match( $blocklist_regex_pattern, $ua ); | |
| 384 | + $allowlist_match = count( $allowlist ) > 0 && 1 === preg_match( $allowlist_regex_pattern, $ua ); | |
| 385 | 385 | |
| 386 | - if ( 1 !== $blocklist_match && 1 !== $allowlist_match ) { | |
| 386 | + if ( ! $blocklist_match && ! $allowlist_match ) { | |
| 387 | 387 | return array( 'na' ); |
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | $result = array(); |
| @@ -389,14 +389,14 @@ | ||
| 389 | 389 | |
| 390 | 390 | $result = array(); |
| 391 | 391 | |
| 392 | 392 | // Check blocklist first - if it matches, add 'banned'. |
| 393 | - if ( 1 === $blocklist_match ) { | |
| 393 | + if ( $blocklist_match ) { | |
| 394 | 394 | $result[] = 'banned'; |
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // Check allowlist - if it matches, add 'allowlist'. |
| 398 | - if ( 1 === $allowlist_match ) { | |
| 398 | + if ( $allowlist_match ) { | |
| 399 | 399 | $result[] = 'allowlist'; |
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | return $result; |