Tagged: W3 Total Cache
- AuthorPosts
- January 30, 2025 at 8:52 am #153367
David Jones
GuestHello 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:
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 45Looking forward to hearing from you.
Thank you,
The Sirv team
sirv.comJanuary 30, 2025 at 8:54 am #153376Marko Vasiljevic
KeymasterHello,
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!
January 31, 2025 at 10:12 am #153415Marko Vasiljevic
KeymasterHello David,
Thank you for your patience
I’ve created a GitHub issue for this in our repository
Please make sure to track the progress of the ticket regularly and add any additional information if neededThanks!
- AuthorPosts
- The topic ‘Issue in W3 Total Cache file and solution’ is closed to new replies.