| @@ -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 | |
| @@ -293,11 +295,13 @@ | ||
| 293 | 295 | */ |
| 294 | 296 | function defender_white_label_status() { |
| 295 | 297 | /* translators: %s: heart icon */ |
| 296 | 298 | $footer_text = sprintf( esc_html__( 'Made with %s by WPMU DEV', 'defender-security' ), '<i class="sui-icon-heart"></i>' ); |
| 297 | - $custom_image = (string) apply_filters( 'wpmudev_branding_hero_image', '' ); | |
| 299 | + $custom_image = apply_filters( 'wpmudev_branding_hero_image', '' ); | |
| 300 | + $custom_image = is_string( $custom_image ) ? $custom_image : (string) $custom_image; | |
| 298 | 301 | $custom_image = trim( $custom_image ); |
| 299 | - $whitelabled = (bool) apply_filters( 'wpmudev_branding_hide_branding', false ); | |
| 302 | + $whitelabeled = apply_filters( 'wpmudev_branding_hide_branding', false ); | |
| 303 | + $whitelabeled = is_bool( $whitelabeled ) ? $whitelabeled : (bool) $whitelabeled; | |
| 300 | 304 | |
| 301 | 305 | return array( |
| 302 | 306 | 'hide_branding' => apply_filters( 'wpmudev_branding_hide_branding', false ), |
| 303 | 307 | 'hide_doc_link' => apply_filters( 'wpmudev_branding_hide_doc_link', false ), |
| @@ -303,14 +307,94 @@ | ||
| 303 | 307 | 'hide_doc_link' => apply_filters( 'wpmudev_branding_hide_doc_link', false ), |
| 304 | 308 | 'footer_text' => apply_filters( 'wpmudev_branding_footer_text', $footer_text ), |
| 305 | 309 | 'hero_image' => $custom_image, |
| 306 | 310 | 'change_footer' => apply_filters( 'wpmudev_branding_change_footer', false ), |
| 307 | - 'is_unbranded' => '' === $custom_image && $whitelabled, | |
| 308 | - 'is_rebranded' => '' !== $custom_image && $whitelabled, | |
| 311 | + 'is_unbranded' => '' === $custom_image && $whitelabeled, | |
| 312 | + 'is_rebranded' => '' !== $custom_image && $whitelabeled, | |
| 309 | 313 | ); |
| 310 | 314 | } |
| 311 | 315 | |
| 312 | 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 | +/** | |
| 313 | 397 | * Indicate this is not fresh setup. |
| 314 | 398 | * |
| 315 | 399 | * @since 2.5.5 |
| 316 | 400 | */ |
| @@ -607,43 +691,8 @@ | ||
| 607 | 691 | |
| 608 | 692 | return false !== strpos( $request_uri, $rest_prefix ); |
| 609 | 693 | } |
| 610 | 694 | |
| 611 | -/** | |
| 612 | - * Handle deprecated functions by logging or triggering actions. | |
| 613 | - * This function is a wrapper for WordPress's _deprecated_function() function. | |
| 614 | - * It is used to handle deprecated functions by either logging a deprecation | |
| 615 | - * message or triggering an action. It checks if the current request is an AJAX | |
| 616 | - * request or a REST API request and acts accordingly. | |
| 617 | - * | |
| 618 | - * @param string $function_name The function that was called. | |
| 619 | - * @param string $version The version number that deprecated the function. | |
| 620 | - * @param string $replacement (Optional) The function that should be used instead. | |
| 621 | - * | |
| 622 | - * @return void | |
| 623 | - * @since 4.2.0 | |
| 624 | - */ | |
| 625 | -function defender_deprecated_function( string $function_name, string $version, string $replacement = '' ): void { | |
| 626 | - /** | |
| 627 | - * Filters whether to trigger an error for deprecated functions. | |
| 628 | - * | |
| 629 | - * @param bool $trigger Whether to trigger the error for deprecated functions. Default false. | |
| 630 | - * | |
| 631 | - * @since 4.2.1 | |
| 632 | - */ | |
| 633 | - if ( WP_DEBUG && apply_filters( 'defender_deprecated_function_trigger_error', false ) ) { | |
| 634 | - if ( wp_doing_ajax() || defender_is_rest_api_request() ) { | |
| 635 | - do_action( 'deprecated_function_run', $function_name, $replacement, $version ); | |
| 636 | - | |
| 637 | - $log_string = "Function {$function_name} is deprecated since version {$version}!"; | |
| 638 | - $log_string .= '' !== $replacement ? " Use {$replacement} instead." : ''; | |
| 639 | - wp_die( esc_html( $log_string ) ); | |
| 640 | - } else { | |
| 641 | - _deprecated_function( esc_html( $function_name ), esc_html( $version ), esc_html( $replacement ) ); | |
| 642 | - } | |
| 643 | - } | |
| 644 | -} | |
| 645 | - | |
| 646 | 695 | if ( ! function_exists( 'defender_get_data_from_request' ) ) { |
| 647 | 696 | /** |
| 648 | 697 | * Retrieves the value of a specific server data key after sanitizing it. |
| 649 | 698 | * |
| @@ -749,8 +798,17 @@ | ||
| 749 | 798 | return ''; |
| 750 | 799 | } |
| 751 | 800 | |
| 752 | 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; | |
| 808 | +} | |
| 809 | + | |
| 810 | +/** | |
| 753 | 811 | * Get an internal log file name. |
| 754 | 812 | * |
| 755 | 813 | * @return string |
| 756 | 814 | */ |
| @@ -762,9 +820,9 @@ | ||
| 762 | 820 | * Retrieves the current time, allowing overrides for testing. |
| 763 | 821 | * |
| 764 | 822 | * @return int The current timestamp. |
| 765 | 823 | */ |
| 766 | -function defender_get_current_time() { | |
| 824 | +function defender_get_current_time(): int { | |
| 767 | 825 | /** |
| 768 | 826 | * Filter the current time. |
| 769 | 827 | * |
| 770 | 828 | * @since 5.2.0 |
| @@ -799,9 +857,10 @@ | ||
| 799 | 857 | * @return string The filtered domain name. |
| 800 | 858 | * |
| 801 | 859 | * @since 5.2.0 |
| 802 | 860 | */ |
| 803 | - $domain = (string) apply_filters( 'wpdef_current_site_domain', $domain ); | |
| 861 | + $domain = apply_filters( 'wpdef_current_site_domain', $domain ); | |
| 862 | + $domain = is_string( $domain ) ? $domain : (string) $domain; | |
| 804 | 863 | |
| 805 | 864 | return esc_html( $domain ); |
| 806 | 865 | } |
| 807 | 866 | |