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

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

97 lines 2.0 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 return (bool) apply_filters( 'wpdef_firewall_whitelist_mainwp_dashboard_public_ip_enabled', true );
54 }
55
56 /**
57 * Whitelist MainWP dashboard site's public IP.
58 *
59 * @return bool
60 */
61 public function set_whitelist_dashboard_public_ip(): bool {
62 if ( ! $this->is_whitelist_dashboard_public_ip_enabled() ) {
63 return false;
64 }
65
66 $ips = $this->get_user_ip();
67
68 if ( array() === $ips ) {
69 return false;
70 }
71
72 $stored_ips = $this->get_whitelist_dashboard_public_ip();
73 $stored_ips = array_unique( $stored_ips );
74 $ips = array_unique( $ips );
75
76 sort( $stored_ips );
77 sort( $ips );
78
79 if ( $stored_ips !== $ips ) {
80 update_site_option( self::WHITELIST_DASHBOARD_PUBLIC_IP_OPTION, $ips );
81 }
82
83 return true;
84 }
85
86 /**
87 * Get the whitelisted MainWP dashboard site's public IP.
88 *
89 * @return array
90 */
91 public function get_whitelist_dashboard_public_ip(): array {
92 return $this->is_whitelist_dashboard_public_ip_enabled() ?
93 get_site_option( self::WHITELIST_DASHBOARD_PUBLIC_IP_OPTION, array() ) :
94 array();
95 }
96 }
97