| @@ -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 | |
| @@ -236,11 +238,19 @@ | ||
| 236 | 238 | // Remove percent signs that are not part of an octet. |
| 237 | 239 | $title = str_replace( '%', '', $title ); |
| 238 | 240 | // Restore octets. |
| 239 | 241 | $title = preg_replace( '|---([a-fA-F0-9][a-fA-F0-9])---|', '%$1', $title ); |
| 240 | - | |
| 241 | - if ( seems_utf8( $title ) ) { | |
| 242 | - $title = utf8_uri_encode( $title, 200 ); | |
| 242 | + // Support for WordPress 6.9+ and older versions. | |
| 243 | + if ( function_exists( 'wp_is_valid_utf8' ) ) { | |
| 244 | + // New function since WP 6.9.0. | |
| 245 | + if ( wp_is_valid_utf8( $title ) ) { | |
| 246 | + $title = utf8_uri_encode( $title, 200 ); | |
| 247 | + } | |
| 248 | + } elseif ( function_exists( 'seems_utf8' ) ) { | |
| 249 | + // Old method (before WP 6.9.0). | |
| 250 | + if ( seems_utf8( $title ) ) { // phpcs:ignore WordPress.WP.DeprecatedFunctions.seems_utf8Found | |
| 251 | + $title = utf8_uri_encode( $title, 200 ); | |
| 252 | + } | |
| 243 | 253 | } |
| 244 | 254 | |
| 245 | 255 | // Kill entities. |
| 246 | 256 | $title = preg_replace( '/&.+?;/', '', $title ); |
| @@ -285,11 +295,13 @@ | ||
| 285 | 295 | */ |
| 286 | 296 | function defender_white_label_status() { |
| 287 | 297 | /* translators: %s: heart icon */ |
| 288 | 298 | $footer_text = sprintf( esc_html__( 'Made with %s by WPMU DEV', 'defender-security' ), '<i class="sui-icon-heart"></i>' ); |
| 289 | - $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; | |
| 290 | 301 | $custom_image = trim( $custom_image ); |
| 291 | - $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; | |
| 292 | 304 | |
| 293 | 305 | return array( |
| 294 | 306 | 'hide_branding' => apply_filters( 'wpmudev_branding_hide_branding', false ), |
| 295 | 307 | 'hide_doc_link' => apply_filters( 'wpmudev_branding_hide_doc_link', false ), |
| @@ -295,20 +307,100 @@ | ||
| 295 | 307 | 'hide_doc_link' => apply_filters( 'wpmudev_branding_hide_doc_link', false ), |
| 296 | 308 | 'footer_text' => apply_filters( 'wpmudev_branding_footer_text', $footer_text ), |
| 297 | 309 | 'hero_image' => $custom_image, |
| 298 | 310 | 'change_footer' => apply_filters( 'wpmudev_branding_change_footer', false ), |
| 299 | - 'is_unbranded' => '' === $custom_image && $whitelabled, | |
| 300 | - 'is_rebranded' => '' !== $custom_image && $whitelabled, | |
| 311 | + 'is_unbranded' => '' === $custom_image && $whitelabeled, | |
| 312 | + 'is_rebranded' => '' !== $custom_image && $whitelabeled, | |
| 301 | 313 | ); |
| 302 | 314 | } |
| 303 | 315 | |
| 304 | 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 | +/** | |
| 305 | 397 | * Indicate this is not fresh setup. |
| 306 | 398 | * |
| 307 | 399 | * @since 2.5.5 |
| 308 | 400 | */ |
| 309 | 401 | function defender_no_fresh_install() { |
| 310 | - if ( ! get_site_option( 'wd_nofresh_install' ) ) { | |
| 402 | + if ( false === get_site_option( 'wd_nofresh_install', false ) ) { | |
| 311 | 403 | update_site_option( 'wd_nofresh_install', true ); |
| 312 | 404 | } |
| 313 | 405 | } |
| 314 | 406 | |
| @@ -599,43 +691,8 @@ | ||
| 599 | 691 | |
| 600 | 692 | return false !== strpos( $request_uri, $rest_prefix ); |
| 601 | 693 | } |
| 602 | 694 | |
| 603 | -/** | |
| 604 | - * Handle deprecated functions by logging or triggering actions. | |
| 605 | - * This function is a wrapper for WordPress's _deprecated_function() function. | |
| 606 | - * It is used to handle deprecated functions by either logging a deprecation | |
| 607 | - * message or triggering an action. It checks if the current request is an AJAX | |
| 608 | - * request or a REST API request and acts accordingly. | |
| 609 | - * | |
| 610 | - * @param string $function_name The function that was called. | |
| 611 | - * @param string $version The version number that deprecated the function. | |
| 612 | - * @param string $replacement (Optional) The function that should be used instead. | |
| 613 | - * | |
| 614 | - * @return void | |
| 615 | - * @since 4.2.0 | |
| 616 | - */ | |
| 617 | -function defender_deprecated_function( string $function_name, string $version, string $replacement = '' ): void { | |
| 618 | - /** | |
| 619 | - * Filters whether to trigger an error for deprecated functions. | |
| 620 | - * | |
| 621 | - * @param bool $trigger Whether to trigger the error for deprecated functions. Default false. | |
| 622 | - * | |
| 623 | - * @since 4.2.1 | |
| 624 | - */ | |
| 625 | - if ( WP_DEBUG && apply_filters( 'defender_deprecated_function_trigger_error', false ) ) { | |
| 626 | - if ( wp_doing_ajax() || defender_is_rest_api_request() ) { | |
| 627 | - do_action( 'deprecated_function_run', $function_name, $replacement, $version ); | |
| 628 | - | |
| 629 | - $log_string = "Function {$function_name} is deprecated since version {$version}!"; | |
| 630 | - $log_string .= '' !== $replacement ? " Use {$replacement} instead." : ''; | |
| 631 | - wp_die( esc_html( $log_string ) ); | |
| 632 | - } else { | |
| 633 | - _deprecated_function( esc_html( $function_name ), esc_html( $version ), esc_html( $replacement ) ); | |
| 634 | - } | |
| 635 | - } | |
| 636 | -} | |
| 637 | - | |
| 638 | 695 | if ( ! function_exists( 'defender_get_data_from_request' ) ) { |
| 639 | 696 | /** |
| 640 | 697 | * Retrieves the value of a specific server data key after sanitizing it. |
| 641 | 698 | * |
| @@ -741,8 +798,17 @@ | ||
| 741 | 798 | return ''; |
| 742 | 799 | } |
| 743 | 800 | |
| 744 | 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 | +/** | |
| 745 | 811 | * Get an internal log file name. |
| 746 | 812 | * |
| 747 | 813 | * @return string |
| 748 | 814 | */ |
| @@ -754,9 +820,9 @@ | ||
| 754 | 820 | * Retrieves the current time, allowing overrides for testing. |
| 755 | 821 | * |
| 756 | 822 | * @return int The current timestamp. |
| 757 | 823 | */ |
| 758 | -function defender_get_current_time() { | |
| 824 | +function defender_get_current_time(): int { | |
| 759 | 825 | /** |
| 760 | 826 | * Filter the current time. |
| 761 | 827 | * |
| 762 | 828 | * @since 5.2.0 |
| @@ -764,9 +830,10 @@ | ||
| 764 | 830 | * @param int $time The current timestamp. |
| 765 | 831 | * |
| 766 | 832 | * @return int The current/filtered timestamp. |
| 767 | 833 | */ |
| 768 | - return (int) apply_filters( 'wpdef_current_time', time() ); | |
| 834 | + $current_time = apply_filters( 'wpdef_current_time', time() ); | |
| 835 | + return ! is_int( $current_time ) ? (int) $current_time : $current_time; | |
| 769 | 836 | } |
| 770 | 837 | |
| 771 | 838 | /** |
| 772 | 839 | * Get the current site domain. |
| @@ -790,9 +857,10 @@ | ||
| 790 | 857 | * @return string The filtered domain name. |
| 791 | 858 | * |
| 792 | 859 | * @since 5.2.0 |
| 793 | 860 | */ |
| 794 | - $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; | |
| 795 | 863 | |
| 796 | 864 | return esc_html( $domain ); |
| 797 | 865 | } |
| 798 | 866 | |