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/functions.php +96 -40 5.9.0 → 6.3.0 View file →
@@ -9,9 +9,11 @@
9 9 use WP_Defender\Component\Crypt;
10 10 use WP_Defender\Component\Two_Fa;
11 11 use WP_Defender\Behavior\WPMUDEV;
12 12 use WP_Defender\Component\User_Agent;
13 +use WP_Defender\Component\Config\Config_Hub_Helper;
13 14 use WP_Defender\Controller\Two_Factor;
15 +use WP_Defender\Integrations\Dashboard_Whitelabel;
14 16 use WP_Defender\Model\Setting\Main_Setting;
15 17 use WP_Defender\Helper\Request;
16 18
17 19 if ( ! defined( 'ABSPATH' ) ) {
@@ -99,9 +101,9 @@
99 101
100 102 /**
101 103 * Returns the global DI container for the WP Defender plugin.
102 104 *
103 - * @return \WPMU_DEV\Defender\Vendor\DI\Container The global DI container.
105 + * @return \WP_Defender\Component\Container The global DI container.
104 106 */
105 107 function wd_di() {
106 108 global $wp_defender_di;
107 109
@@ -296,10 +298,10 @@
296 298 $footer_text = sprintf( esc_html__( 'Made with %s by WPMU DEV', 'defender-security' ), '<i class="sui-icon-heart"></i>' );
297 299 $custom_image = apply_filters( 'wpmudev_branding_hero_image', '' );
298 300 $custom_image = is_string( $custom_image ) ? $custom_image : (string) $custom_image;
299 301 $custom_image = trim( $custom_image );
300 - $whitelabled = apply_filters( 'wpmudev_branding_hide_branding', false );
301 - $whitelabled = is_bool( $whitelabled ) ? $whitelabled : (bool) $whitelabled;
302 + $whitelabeled = apply_filters( 'wpmudev_branding_hide_branding', false );
303 + $whitelabeled = is_bool( $whitelabeled ) ? $whitelabeled : (bool) $whitelabeled;
302 304
303 305 return array(
304 306 'hide_branding' => apply_filters( 'wpmudev_branding_hide_branding', false ),
305 307 'hide_doc_link' => apply_filters( 'wpmudev_branding_hide_doc_link', false ),
@@ -305,14 +307,94 @@
305 307 'hide_doc_link' => apply_filters( 'wpmudev_branding_hide_doc_link', false ),
306 308 'footer_text' => apply_filters( 'wpmudev_branding_footer_text', $footer_text ),
307 309 'hero_image' => $custom_image,
308 310 'change_footer' => apply_filters( 'wpmudev_branding_change_footer', false ),
309 - 'is_unbranded' => '' === $custom_image && $whitelabled,
310 - 'is_rebranded' => '' !== $custom_image && $whitelabled,
311 + 'is_unbranded' => '' === $custom_image && $whitelabeled,
312 + 'is_rebranded' => '' !== $custom_image && $whitelabeled,
311 313 );
312 314 }
313 315
314 316 /**
317 + * Get data of the whitelabel feature, e.g. hide_branding, hide_doc_link, footer_text, hero_image, change_footer.
318 + *
319 + * @return array
320 + * @since 6.0.0
321 + */
322 +function defender_whitelabel_data(): array {
323 + $data = array(
324 + 'is_enabled' => false,
325 + );
326 +
327 + if ( wd_di()->get( WPMUDEV::class )->is_whitelabel_enabled() ) {
328 + /* translators: %s: heart icon */
329 + $footer_text = sprintf( esc_html__( 'Made with %s by WPMU DEV', 'defender-security' ), '<i class="sui-icon-heart"></i>' );
330 + $custom_image = apply_filters( 'wpmudev_branding_hero_image', '' );
331 + $custom_image = is_string( $custom_image ) ? $custom_image : (string) $custom_image;
332 + $custom_image = trim( $custom_image );
333 + $whitelabeled = apply_filters( 'wpmudev_branding_hide_branding', false );
334 + $whitelabeled = is_bool( $whitelabeled ) ? $whitelabeled : (bool) $whitelabeled;
335 + $whitelabel = new Dashboard_Whitelabel();
336 + $plugin_name = $whitelabel->can_whitelabel() ? $whitelabel->get_plugin_name( Config_Hub_Helper::WDP_ID ) : false;
337 +
338 + $plugin_icon_url = '';
339 + $plugin_icon_class = '';
340 + $plugin_icon_type = 'default';
341 +
342 + if ( $whitelabel->can_whitelabel() ) {
343 + $wl_settings = WPMUDEV_Dashboard::$whitelabel->get_settings();
344 + $pid = Config_Hub_Helper::WDP_ID;
345 + $labels_networkwide = (bool) ( $wl_settings['labels_networkwide'] ?? true );
346 + $labels_subsites = array_map( 'intval', (array) ( $wl_settings['labels_subsites'] ?? array() ) );
347 + $apply_labels = ! is_multisite()
348 + || is_network_admin()
349 + || $labels_networkwide
350 + || in_array( get_current_blog_id(), $labels_subsites, true );
351 +
352 + if ( $apply_labels && isset( $wl_settings['labels_config'][ $pid ] ) ) {
353 + $cfg = $wl_settings['labels_config'][ $pid ];
354 + $plugin_icon_type = sanitize_key( $cfg['icon_type'] ?? 'default' );
355 +
356 + switch ( $plugin_icon_type ) {
357 + case 'dashicon':
358 + $plugin_icon_class = sanitize_html_class( $cfg['icon_class'] ?? '' );
359 + break;
360 + case 'upload':
361 + $thumb_id = (int) ( $cfg['thumb_id'] ?? 0 );
362 + if ( $thumb_id ) {
363 + $url = wp_get_attachment_image_url( $thumb_id, 'thumbnail', true );
364 + $plugin_icon_url = $url ? $url : '';
365 + }
366 + break;
367 + case 'link':
368 + $plugin_icon_url = esc_url_raw( $cfg['icon_url'] ?? '' );
369 + break;
370 + case 'none':
371 + $plugin_icon_url = null;
372 + break;
373 + }
374 + }
375 + }
376 +
377 + $data = array(
378 + 'is_enabled' => true,
379 + 'hide_branding' => apply_filters( 'wpmudev_branding_hide_branding', false ),
380 + 'hide_doc_link' => apply_filters( 'wpmudev_branding_hide_doc_link', false ),
381 + 'footer_text' => apply_filters( 'wpmudev_branding_footer_text', $footer_text ),
382 + 'hero_image' => $custom_image,
383 + 'change_footer' => apply_filters( 'wpmudev_branding_change_footer', false ),
384 + 'is_unbranded' => '' === $custom_image && $whitelabeled,
385 + 'is_rebranded' => '' !== $custom_image && $whitelabeled,
386 + 'plugin_name' => is_string( $plugin_name ) && '' !== trim( $plugin_name ) ? $plugin_name : '',
387 + 'plugin_icon_url' => $plugin_icon_url,
388 + 'plugin_icon_class' => $plugin_icon_class,
389 + 'plugin_icon_type' => $plugin_icon_type,
390 + );
391 + }
392 +
393 + return $data;
394 +}
395 +
396 +/**
315 397 * Indicate this is not fresh setup.
316 398 *
317 399 * @since 2.5.5
318 400 */
@@ -609,43 +691,8 @@
609 691
610 692 return false !== strpos( $request_uri, $rest_prefix );
611 693 }
612 694
613 -/**
614 - * Handle deprecated functions by logging or triggering actions.
615 - * This function is a wrapper for WordPress's _deprecated_function() function.
616 - * It is used to handle deprecated functions by either logging a deprecation
617 - * message or triggering an action. It checks if the current request is an AJAX
618 - * request or a REST API request and acts accordingly.
619 - *
620 - * @param string $function_name The function that was called.
621 - * @param string $version The version number that deprecated the function.
622 - * @param string $replacement (Optional) The function that should be used instead.
623 - *
624 - * @return void
625 - * @since 4.2.0
626 - */
627 -function defender_deprecated_function( string $function_name, string $version, string $replacement = '' ): void {
628 - /**
629 - * Filters whether to trigger an error for deprecated functions.
630 - *
631 - * @param bool $trigger Whether to trigger the error for deprecated functions. Default false.
632 - *
633 - * @since 4.2.1
634 - */
635 - if ( WP_DEBUG && apply_filters( 'defender_deprecated_function_trigger_error', false ) ) {
636 - if ( wp_doing_ajax() || defender_is_rest_api_request() ) {
637 - do_action( 'deprecated_function_run', $function_name, $replacement, $version );
638 -
639 - $log_string = "Function {$function_name} is deprecated since version {$version}!";
640 - $log_string .= '' !== $replacement ? " Use {$replacement} instead." : '';
641 - wp_die( esc_html( $log_string ) );
642 - } else {
643 - _deprecated_function( esc_html( $function_name ), esc_html( $version ), esc_html( $replacement ) );
644 - }
645 - }
646 -}
647 -
648 695 if ( ! function_exists( 'defender_get_data_from_request' ) ) {
649 696 /**
650 697 * Retrieves the value of a specific server data key after sanitizing it.
651 698 *
@@ -748,8 +795,17 @@
748 795 return isset( $states[ $feature_key ] ) ? $states[ $feature_key ] : '';
749 796 }
750 797
751 798 return '';
799 +}
800 +
801 +/**
802 + * Is a site is from WPMU DEV unlimited hosting?
803 + *
804 + * @return bool
805 + */
806 +function defender_is_unlimited_hosting(): bool {
807 + return defined( 'WPMUDEV_HOSTING_WEBSITE_ID' ) && '' !== WPMUDEV_HOSTING_WEBSITE_ID;
752 808 }
753 809
754 810 /**
755 811 * Get an internal log file name.