Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #153367 Reply
    David Jones
    Guest

    Hello W3 team,

    We are the developers of the Sirv WordPress plugin, https://wordpress.org/plugins/sirv/ which is used by many W3 Total Cache users.

    We found a bug with the wp_resource_hints hook in this W3 Total Cache file:

    /wp-content/plugins/w3-total-cache/UserExperience_Emoji_Extension.php

    The issue is with the function that disables emojis. Here is the code from the file:

    public function wp_resource_hints( $urls, $relation_type ) {
    if ( !is_array( $urls ) || $relation_type != 'dns-prefetch' ) {
    return $urls;
    }

    // remove s.w.org dns-prefetch used by emojis
    return array_filter( $urls,
    function( $v ) {
    return ( substr( $v, 0, 16) != 'https://s.w.org/' );
    }
    );
    }
    }

    The problem is that it does not work correctly with incoming parameters, as it can be an array of URLs or an array of resource attributes.

    The WordPress documentation recommends to use an array:

    wp_resource_hints

    Can you please update the file to use an array?

    We saw a similar issue in the Yoast SEO plugin and they fixed it like this:

    public function resource_hints_plain_cleanup( $hints ) {
    foreach ( $hints as $key => $hint ) {
    if ( \is_array( $hint ) && isset( $hint['href'] ) ) {
    if ( \strpos( $hint['href'], '//s.w.org' ) !== false ) {
    unset( $hints[ $key ] );
    }
    }
    elseif ( \strpos( $hint, '//s.w.org' ) !== false ) {
    unset( $hints[ $key ] );
    }
    }
    return $hints;
    }

    Without solving this issue, the following error occurs:

    Fatal error: Uncaught TypeError: substr(): Argument #1 ($string)
    must be of type string, array given in
    /home/mysitecom/website/web/wp-content/plugins/w3-total-cache/UserExperience_Emoji_Extension.php:45
    Stack trace: #0
    /home/mysitecom/website/web/wp-content/plugins/w3-total-cache/UserExperience_Emoji_Extension.php(45):
    substr(Array, 0, 16) #1 [internal function]:
    W3TC\UserExperience_Emoji_Extension->W3TC\{closure}(Array)
    #2 /home/mysitecom/website/web/wp-content/plugins/w3-total-cache/UserExperience_Emoji_Extension.php(43):
    array_filter(Array, Object(Closure))
    #3 /home/mysitecom/website/web/wp-includes/class-wp-hook.php(324):
    W3TC\UserExperience_Emoji_Extension->wp_resource_hints(Array, 'dns-prefetch')
    #4 /home/mysitecom/website/web/wp-includes/plugin.php(205):
    WP_Hook->apply_filters(Array, Array)
    #5 /home/mysitecom/website/web/wp-includes/general-template.php(3521):
    apply_filters('wp_resource_hin...', Array, 'dns-prefetch')
    #6 /home/mysitecom/website/web/wp-includes/class-wp-hook.php(324):
    wp_resource_hints('')
    #7 /home/mysitecom/website/web/wp-includes/class-wp-hook.php(348):
    WP_Hook->apply_filters('', Array)
    #8 /home/mysitecom/website/web/wp-includes/plugin.php(517):
    WP_Hook->do_action(Array)
    #9 /home/mysitecom/website/web/wp-admin/admin-header.php(132):
    do_action('admin_print_sty...')
    #10 /home/mysitecom/website/web/wp-admin/plugins.php(637):
    require_once('/home/heskinsco...')
    #11 {main} thrown in
    /home/mysitecom/website/web/wp-content/plugins/w3-total-cache/UserExperience_Emoji_Extension.php on line 45

    Looking forward to hearing from you.

    Thank you,

    The Sirv team
    sirv.com

    #153376 Reply

    Hello,

    Thank you for reaching out and for taking the time to report this.

    Let me share this with the team, and I’ll get back to you as soon as I have more information about this. Also, thank you for your time helping to improve the W3 Total Cache

    Thanks!

Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Issue in W3 Total Cache file and solution
Your information: