Categories
Useful Wordpress

W3 Total Cache HTTP ERROR 500, Call to undefined function W3TC\wp_unslash()

At the last update for W3 Total Cahe to Version 2.2.3 we reached the situation that the site no longer works, it returns a classic HTTP ERROR 500 error.

w3tc error 500

The only solution to restore operation was to manually delete the entire cache plugin folder /wp-content/plugins/w3-total-cache and the object-cache.php + db.php files from /wp-content/ folder.

The error in the server logs was as follows:

[Sun Jul 10 07:40:25.623603 2022] [proxy_fcgi:error] [pid 866364:tid 140138650781440] [client 172.70.90.88:12722] AH01071: Got error ‘PHP message: PHP Fatal error: Uncaught Error: Call to undefined function W3TC\\wp_unslash() in /var/www/clients/client0
/web6/web/wp-content/plugins/w3-total-cache/DbCache_WpdbInjection_QueryCaching.php:562\nStack trace:\n#0 /var/www/clients/client0/web6/web/wp-content/plugins/w3-total-cache/DbCache_WpdbInjection_QueryCaching.php(507): W3TC\\DbCache_WpdbInjection_QueryCac
hing->_check_request_uri()\n#1 /var/www/clients/client0/web6/web/wp-content/plugins/w3-total-cache/DbCache_WpdbInjection_QueryCaching.php(424): W3TC\\DbCache_WpdbInjection_QueryCaching->_can_cache_once_per_request()\n#2 /var/www/clients/client0/web6/web/
wp-content/plugins/w3-total-cache/DbCache_WpdbInjection_QueryCaching.php(123): W3TC\\DbCache_WpdbInjection_QueryCaching->_can_cache()\n#3 /var/www/clients/client0/web6/web/wp-content/plugins/w3-total-cache/DbCache_WpdbLegacy.php(122): W3TC\\DbCache_WpdbI
njection_QueryCaching->query()\n#4 /var/www/clients/client0/web6/web/wp-includes/wp-db.php(2496): W3TC\\DbCache_WpdbLegacy->query()\n#5 /var/ww…’, referer: https://ipfail.org/wp-admin/?swcfpc=1

But after a short online search, I found a temporary fix, at least until the plugin developers update the code with a correct one, which still had to be done ASAP, not to be left until the next version.

Temporary solution: Change the following lines in wp-content/plugins/w3-total-cache/DbCache_WpdbInjection_QueryCaching.php

Line 218
from
esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '',
to
esc_url_raw( stripslashes( $_SERVER['REQUEST_URI'] ) ) : '',

and also line 562

from
filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : '';
to:
filter_var( stripslashes( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL ) : '';

via https://wordpress.org/support/topic/fatal-error-4193/

Leave a Reply

Your email address will not be published. Required fields are marked *