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
← All changes | src/traits/defender-dashboard-client.php +90 -36 5.6.2 → 6.3.0 View file →
@@ -20,9 +20,9 @@
20 20 *
21 21 * @return bool
22 22 */
23 23 public function is_pro(): bool {
24 - return $this->get_apikey() !== false;
24 + return class_exists( '\WPMUDEV_Dashboard' ) && method_exists( $this, 'get_apikey' ) && $this->get_apikey() !== false;
25 25 }
26 26
27 27 /**
28 28 * Check if user is a paid one in WPMU DEV.
@@ -48,9 +48,13 @@
48 48 * @return bool
49 49 * @since 2.6.3
50 50 */
51 51 public function is_wpmu_dev_admin(): bool {
52 - if ( $this->is_dash_activated() && method_exists( 'WPMUDEV_Dashboard_Site', 'allowed_user' ) ) {
52 + if (
53 + 'dashboard' === $this->resolve_connection_mode() &&
54 + is_object( WPMUDEV_Dashboard::$site ) &&
55 + method_exists( WPMUDEV_Dashboard::$site, 'allowed_user' )
56 + ) {
53 57 return WPMUDEV_Dashboard::$site->allowed_user( get_current_user_id() );
54 58 }
55 59
56 60 return false;
@@ -56,25 +60,46 @@
56 60 return false;
57 61 }
58 62
59 63 /**
60 - * Bring the plugin menu title.
64 + * Returns whether the current install is a Pro version.
61 65 *
66 + * @return bool
67 + */
68 + protected function is_pro_install(): bool {
69 + require_once ABSPATH . 'wp-admin/includes/plugin.php';
70 + $is_pro = file_exists( $this->get_abs_plugin_path_by_slug( WP_DEFENDER_PRO_PATH ) )
71 + && is_plugin_active( WP_DEFENDER_PRO_PATH );
72 +
73 + return $is_pro;
74 + }
75 +
76 + /**
77 + * Returns the page title.
78 + *
79 + * @return string Page title.
80 + */
81 + public function get_page_title(): string {
82 + return $this->is_pro_install()
83 + ? esc_html__( 'Defender Pro', 'defender-security' )
84 + : esc_html__( 'Defender', 'defender-security' );
85 + }
86 +
87 + /**
88 + * Returns the sidebar menu title, including a "Pro" badge span when on a Pro install.
89 + *
62 90 * @return string Menu title.
63 91 */
64 92 public function get_menu_title(): string {
65 - if ( $this->is_pro() ) {
66 - $menu_title = esc_html__( 'Defender Pro', 'defender-security' );
67 - } else {
68 - // Check if it's Pro but user logged the WPMU DEV Dashboard out.
69 - require_once ABSPATH . 'wp-admin/includes/plugin.php';
70 - $menu_title = file_exists( $this->get_abs_plugin_path_by_slug( WP_DEFENDER_PRO_PATH ) )
71 - && is_plugin_active( WP_DEFENDER_PRO_PATH )
72 - ? esc_html__( 'Defender Pro', 'defender-security' )
73 - : esc_html__( 'Defender', 'defender-security' );
93 + if ( $this->is_pro_install() ) {
94 + return sprintf(
95 + '%1$s<span class="defender-admin-menu-pro-tag">%2$s</span>',
96 + esc_html__( 'Defender', 'defender-security' ),
97 + esc_html__( 'Pro', 'defender-security' )
98 + );
74 99 }
75 100
76 - return $menu_title;
101 + return esc_html__( 'Defender', 'defender-security' );
77 102 }
78 103
79 104 /**
80 105 * Return icon svg image.
@@ -83,12 +108,10 @@
83 108 */
84 109 public function get_menu_icon(): string {
85 110 ob_start();
86 111 ?>
87 - <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
88 - <path fill-rule="evenodd" clip-rule="evenodd"
89 - d="M9.99999 2.08899L3 4.21792V9.99502H9.99912V18.001H10C13.47 18.001 17 13.9231 17 11.0045V9.99501H9.99999V2.08899ZM10 0L1 2.73862V11.0045C1 15.1125 5.49 20 10 20C14.51 20 19 15.1225 19 11.0045V2.73862L10 0Z"
90 - fill="#F0F6FC"/>
112 + <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
113 + <path d="M7.44 1.12125L2.94 2.43125C2.09 2.68125 1.5 3.46125 1.5 4.35125V8.66125C1.5 11.5312 4.72 14.9612 8 14.9612C11.28 14.9612 14.5 11.5312 14.5 8.66125V4.35125C14.5 3.46125 13.91 2.68125 13.06 2.43125L8.56 1.12125C8.2 1.01125 7.81 1.01125 7.44 1.12125ZM13.06 8.66125C13.06 10.6912 10.53 13.5612 8 13.5612V7.96125H2.94V3.90125L8 2.43125V7.96125H13.06V8.66125Z" fill="#F0F6FC"/>
91 114 </svg>
92 115 <?php
93 116 $svg = ob_get_clean();
94 117
@@ -126,12 +149,16 @@
126 149 * @since 3.4.0
127 150 */
128 151 public function is_site_connected_to_hub(): bool {
129 152 // The case if Pro version is activated, it is TFH account and a site is from 3rd party hosting.
130 - if ( WP_DEFENDER_PRO_PATH === DEFENDER_PLUGIN_BASENAME && $this->is_another_hosted_site_connected_to_tfh() ) {
153 + if (
154 + WP_DEFENDER_PRO_PATH === DEFENDER_PLUGIN_BASENAME
155 + && method_exists( $this, 'is_another_hosted_site_connected_to_tfh' )
156 + && $this->is_another_hosted_site_connected_to_tfh()
157 + ) {
131 158 return '' !== $this->get_api_key();
132 159 } else {
133 - $hub_site_id = $this->get_site_id();
160 + $hub_site_id = method_exists( $this, 'get_site_id' ) ? $this->get_site_id() : null;
134 161
135 162 return is_int( $hub_site_id ) && $hub_site_id > 0;
136 163 }
137 164 }
@@ -141,9 +168,9 @@
141 168 *
142 169 * @return bool
143 170 */
144 171 public function is_disabled_hub_option(): bool {
145 - return ! $this->is_dash_activated() || ! $this->is_site_connected_to_hub();
172 + return 'none' === $this->resolve_connection_mode();
146 173 }
147 174
148 175 /**
149 176 * Get remote access.
@@ -148,8 +175,12 @@
148 175 /**
149 176 * Get remote access.
150 177 */
151 178 public function get_remote_access() {
179 + if ( ! class_exists( 'WPMUDEV_Dashboard' ) ) {
180 + return false;
181 + }
182 +
152 183 // Use backward compatibility.
153 184 if ( WPMUDEV_Dashboard::$version > '4.11.9' ) {
154 185 return WPMUDEV_Dashboard::$settings->get( 'remote_access' );
155 186 } else {
@@ -156,30 +187,51 @@
156 187 return WPMUDEV_Dashboard::$site->get_option( 'remote_access' );
157 188 }
158 189 }
159 190 /**
160 - * Checks if the Hub connector is connected.
191 + * Checks if the Hub connector module (HCM) is connected.
161 192 *
162 193 * @return bool True if connected, false otherwise.
163 194 */
164 - public static function get_status(): bool {
165 - return API::get()->is_logged_in();
195 + public static function get_hcm_status(): bool {
196 + return class_exists( 'WPMUDEV\Hub\Connector\API' ) && API::get()->is_logged_in();
166 197 }
167 198
168 199 /**
200 + * Checks if the Dashboard plugin has a usable Hub connection.
201 + *
202 + * @return bool
203 + */
204 + protected function is_dashboard_connected(): bool {
205 + return $this->is_dash_activated()
206 + && is_object( WPMUDEV_Dashboard::$api )
207 + && WPMUDEV_Dashboard::$api->has_key()
208 + && (int) WPMUDEV_Dashboard::$api->get_site_id() > 0;
209 + }
210 +
211 + /**
212 + * Resolve the active Hub connection mode for this request.
213 + *
214 + * @return string 'dashboard' | 'hub_connector' | 'none'
215 + * @since 6.0.0
216 + */
217 + public function resolve_connection_mode(): string {
218 + if ( $this->is_dashboard_connected() ) {
219 + return 'dashboard';
220 + } elseif ( self::get_hcm_status() ) {
221 + return 'hub_connector';
222 + }
223 +
224 + return 'none';
225 + }
226 +
227 + /**
169 228 * Checks if Hub Connector is connected. If Dash plugin is not installed Hub connector can take over.
170 229 *
171 230 * @return bool
172 231 */
173 232 public function hub_connector_connected(): bool {
174 - if ( $this->is_dash_activated() ) {
175 - $dash_api = WPMUDEV_Dashboard::$api;
176 - $connected = (bool) $dash_api->has_key();
177 - } else {
178 - $connected = self::get_status();
179 - }
180 -
181 - return $connected;
233 + return 'none' !== $this->resolve_connection_mode();
182 234 }
183 235
184 236 /**
185 237 * Upgrade the method to get api key from Dashboard plugin or Hub Connector module.
@@ -186,12 +238,14 @@
186 238 *
187 239 * @return string
188 240 */
189 241 public function get_api_key(): string {
190 - if ( $this->is_dash_activated() ) {
242 + if ( 'dashboard' === $this->resolve_connection_mode() ) {
191 243 $api_key = WPMUDEV_Dashboard::$api->get_key();
244 + } elseif ( class_exists( 'WPMUDEV\Hub\Connector\API' ) ) {
245 + $api_key = API::get()->get_api_key();
192 246 } else {
193 - $api_key = API::get()->get_api_key();
247 + $api_key = '';
194 248 }
195 249
196 250 return $api_key;
197 251 }
@@ -201,11 +255,11 @@
201 255 *
202 256 * @return string
203 257 */
204 258 public function get_membership_type() {
205 - if ( $this->is_dash_activated() ) {
259 + if ( 'dashboard' === $this->resolve_connection_mode() ) {
206 260 return WPMUDEV_Dashboard::$api->get_membership_status();
207 - } elseif ( self::get_status() ) {
261 + } elseif ( self::get_hcm_status() ) {
208 262 return Data::get()->membership_type();
209 263 }
210 264 return 'free';
211 265 }
@@ -233,7 +287,7 @@
233 287 *
234 288 * @return bool
235 289 */
236 290 public function is_site_connected_to_hub_via_hcm_or_dash(): bool {
237 - return $this->hub_connector_connected() || self::get_status();
291 + return $this->hub_connector_connected() || self::get_hcm_status();
238 292 }
239 293 }