[Resolved] Fatal Error with Toolset Views and PHP 8.1
This thread is resolved. Here is a description of the problem and solution.
Problem:
The customer was attempting to upgrade their website to PHP 8.1 but encountered a fatal error that disappeared when Toolset Views was disabled. The error prevented the homepage from displaying images and text properly.
Solution:
After investigating, it was determined that the error was related to a specific line in a Toolset View, particularly concerning the sm-homepage-image field. Testing on a minimal setup confirmed that the issue persisted even with only Toolset plugins enabled.
Further investigation revealed that switching to a different theme caused additional errors due to an undefined function (create_function()) in the custom functions file of the theme. The customer was advised to back up the custom-functions.php file before switching themes to avoid losing custom settings.
The root cause was identified as a custom uploads location on the server, which led to an error within the Toolset plugin. A temporary workaround was implemented by modifying the Attachments.php file in the Toolset Blocks plugin, allowing the site to function correctly again.
The customer was informed that this fix would be included in an upcoming Toolset version, but they might need to reapply the workaround after future updates until the official fix is released.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
The issue is more specifically related with the field: sm-homepage-image.
Trying to edit one of the posts loaded in the loop throws the error as well: hidden link
Given this is a staging environment, before taking a local copy of your site, I took the liberty of testing on minimal minimal, with default theme and only Toolset plugins enabled, and the issue happens as well.
However, after I tried to re-enable the theme 'Dynamik-Gen' it started showing this error and having issues with the style in the front end:
Fatal error: Uncaught Error: Call to undefined function create_function() in /wp-content/uploads/dynamik-gen/theme/custom-functions.php
It looks like this is related to some generated content in the wp-uploads folder. After switching themes, there might me some steps we don't know in order for theme to work properly.
Can you please review it and restore the site's theme? We'll proceed with working locally after it is corrected.
Okay, we have fixed the theme. If you switch to another theme, make a copy of custom-functions.php in wp-content\uploads\dynamik-gen\theme\ before you switch and then replace it when you switch back. That should help.
I have escalated this ticket to our 2nd tier of support where our 2nd tier specialists will take a deeper look at this issue and will try to find a solution.
I will get back to you as soon as I get an answer from them.
We've identified that the issue is due to a custom uploads location being used on your server, which causes a specific error in the Toolset plugin. We've implemented a workaround on your site that resolves the problem. Please test it again and confirm it.
The workaround involves editing the code at plugins/toolset-blocks/vendor/toolset/toolset-common/inc/autoloaded/utils/Attachments.php, replacing this at line 67-68:
// Split the $url into two parts with the upload directory as the separator.
$parsed_url = explode( wp_parse_url( $this->get_base_upload_directory(), PHP_URL_PATH ), $url );
While we're planning to include this fix in an upcoming version of Toolset, there's a possibility that it might not be ready in time for the next release. In that case, you may need to reapply the workaround after any future updates until the fix is officially included.
Please let us know if you need further assistance.