| @@ -37,9 +37,9 @@ | ||
| 37 | 37 | */ |
| 38 | 38 | public function get_all_bot_ips(): array { |
| 39 | 39 | $data = array(); |
| 40 | 40 | |
| 41 | - foreach ( $this->providers as $provider ) { | |
| 41 | + foreach ( $this->get_providers() as $provider ) { | |
| 42 | 42 | if ( $provider instanceof Bots_Interface ) { |
| 43 | 43 | $name = $provider->get_name(); |
| 44 | 44 | $data[ $name ] = $this->get_or_set_bot_ips( $provider ); |
| 45 | 45 | } |
| @@ -80,6 +80,33 @@ | ||
| 80 | 80 | $key = 'wpdef_known_bot_ips_' . $name; |
| 81 | 81 | $ips = get_site_transient( $key ); |
| 82 | 82 | |
| 83 | 83 | return is_array( $ips ) && array() !== $ips ? $ips : array(); |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Returns the registered bot providers. | |
| 88 | + * | |
| 89 | + * @return Bots_Interface[] | |
| 90 | + */ | |
| 91 | + public function get_providers(): array { | |
| 92 | + return $this->providers; | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * Checks if the given IP and user agent match any registered known bot. | |
| 97 | + * | |
| 98 | + * @param string $ip The IP address to check. | |
| 99 | + * @param string $user_agent Optional user agent string. | |
| 100 | + * | |
| 101 | + * @return bool | |
| 102 | + */ | |
| 103 | + public function is_known_bot( string $ip, string $user_agent = '' ): bool { | |
| 104 | + foreach ( $this->get_providers() as $provider ) { | |
| 105 | + if ( $provider instanceof Bots_Interface && $provider->is_ua( $user_agent ) && $provider->is_ip( $ip ) ) { | |
| 106 | + return true; | |
| 107 | + } | |
| 108 | + } | |
| 109 | + | |
| 110 | + return false; | |
| 84 | 111 | } |
| 85 | 112 | } |