PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.2.2
Defender Security – Malware Scanner, Login Security & Firewall v6.2.2
6.3.0 6.2.3 6.2.4 6.2.0 6.2.1 6.2.2 6.1.0 5.3.1 5.4.0 5.4.1 5.5.0 5.5.1 5.6.0 5.6.1 5.6.2 5.7.0 5.7.1 5.7.2 5.8.0 5.8.1 5.9.0 6.0.0 6.0.1 3.0.1 3.1.0 All 141 releases
defender-security / src / component / known-bots / bots / class-google-bot.php

class-google-bot.php in Defender Security – Malware Scanner, Login Security & Firewall 6.2.2, at src/component/known-bots/bots/class-google-bot.php

52 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles Google Bot IPs.
4 *
5 * @package WP_Defender\Component\Known_Bots\Bots
6 */
7
8 namespace WP_Defender\Component\Known_Bots\Bots;
9
10 /**
11 * This class is responsible for fetching and managing Google Bot IPs.
12 */
13 class Google_Bot implements Bots_Interface {
14 /**
15 * Returns the name of the bot.
16 *
17 * @return string The name of the bot.
18 */
19 public function get_name(): string {
20 return 'googlebot';
21 }
22
23 /**
24 * Fetches the IPs for Google Bot.
25 *
26 * This method retrieves the IP ranges used by Google Bot from a remote JSON endpoint.
27 * It returns an array of IP addresses in both IPv4 and IPv6 formats.
28 *
29 * @return array An array of IP addresses used by Google Bot.
30 */
31 public function fetch_ips(): array {
32 $url = 'https://developers.google.com/static/search/apis/ipranges/googlebot.json';
33 $ips = array();
34
35 $response = wp_remote_get( $url );
36 if ( is_array( $response ) && ! is_wp_error( $response ) ) {
37 $data = json_decode( wp_remote_retrieve_body( $response ), true );
38 foreach ( $data['prefixes'] ?? array() as $entry ) {
39 if ( isset( $entry['ipv4Prefix'] ) ) {
40 $ips[] = $entry['ipv4Prefix'];
41 }
42
43 if ( isset( $entry['ipv6Prefix'] ) ) {
44 $ips[] = $entry['ipv6Prefix'];
45 }
46 }
47 }
48
49 return $ips;
50 }
51 }
52