PluginProbe
Defender Security – Malware Scanner, Login Security & Firewall / 6.3.0
Defender Security – Malware Scanner, Login Security & Firewall v6.3.0
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 / integrations / class-main-wp.php

class-main-wp.php in Defender Security – Malware Scanner, Login Security & Firewall 6.3.0, at src/integrations/class-main-wp.php

96 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handles interaction with MainWP
4 *
5 * @package WP_Defender\Integrations
6 * @since 5.0.2
7 */
8
9 namespace WP_Defender\Integrations;
10
11 use WP_Defender\Traits\IP;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 die;
15 }
16
17 /**
18 * MainWP plugin integration module.
19 *
20 * @since 5.0.2
21 */
22 class Main_Wp {
23 use IP;
24
25 /**
26 * The option name for the whitelist MainWP dashboard public IP.
27 */
28 public const WHITELIST_DASHBOARD_PUBLIC_IP_OPTION = 'wpdef_firewall_whitelist_mainwp_dashboard_public_ip';
29
30 /**
31 * Constructor for the class.
32 * Registers the hook.
33 *
34 * @return void
35 */
36 public function __construct() {
37 add_action( 'mainwp_child_site_stats', array( $this, 'set_whitelist_dashboard_public_ip' ) );
38 }
39
40 /**
41 * Is whitelisting the MainWP Dashboard's public IP enabled.
42 *
43 * @return bool
44 */
45 public function is_whitelist_dashboard_public_ip_enabled(): bool {
46 /**
47 * Filter to enable/disable whitelisting the MainWP Dashboard site's public IP.
48 *
49 * @param bool $enable True to enable whitelisting, false otherwise.
50 *
51 * @since 5.0.2
52 */
53 $enabled = apply_filters( 'wpdef_firewall_whitelist_mainwp_dashboard_public_ip_enabled', true );
54 return is_bool( $enabled ) ? $enabled : (bool) $enabled;
55 }
56
57 /**
58 * Whitelist MainWP dashboard site's public IP.
59 *
60 * @return void
61 */
62 public function set_whitelist_dashboard_public_ip(): void {
63 if ( ! $this->is_whitelist_dashboard_public_ip_enabled() ) {
64 return;
65 }
66
67 $ips = $this->get_user_ip();
68
69 if ( array() === $ips ) {
70 return;
71 }
72
73 $stored_ips = $this->get_whitelist_dashboard_public_ip();
74 $stored_ips = array_unique( $stored_ips );
75 $ips = array_unique( $ips );
76
77 sort( $stored_ips );
78 sort( $ips );
79
80 if ( $stored_ips !== $ips ) {
81 update_site_option( self::WHITELIST_DASHBOARD_PUBLIC_IP_OPTION, $ips );
82 }
83 }
84
85 /**
86 * Get the whitelisted MainWP dashboard site's public IP.
87 *
88 * @return array
89 */
90 public function get_whitelist_dashboard_public_ip(): array {
91 return $this->is_whitelist_dashboard_public_ip_enabled() ?
92 get_site_option( self::WHITELIST_DASHBOARD_PUBLIC_IP_OPTION, array() ) :
93 array();
94 }
95 }
96