Fatal Error Fix: PHP 8.x fatal error upon saving custom admin color scheme
-
It looks like https://www.ads-software.com/support/topic/it-only-gives-critical-error-when-saving/ & others might also be encountering this issue as well as myself. However, I think I’ve found the issue and have some possible fixes to consider.
It seems the
lib/phpsass
library (last updated 5 years ago, it seems) needs to be updated to a new version or otherwise patched to avoid a fatal PHP error when saving a color scheme for those using PHP 8.0+.The exact errors appear to be:
Fatal error: An error of type E_COMPILE_ERROR was caused in line 133 of the file /wp-content/plugins/admin-color-schemer/lib/phpsass/tree/SassRuleNode.php. Error message: Array and string offset access syntax with curly braces is no longer supported
Fatal error: Uncaught Error: count(): Argument #1 ($value) must be of type Countable|array, string given in /wp-content/plugins/admin-color-schemer/lib/phpsass/tree/SassMixinNode.php on line 66
Fatal error: Uncaught Error: strlen(): Argument #1 ($str) must be of type string, array given in /wp-content/plugins/admin-color-schemer/lib/phpsass/script/SassScriptFunction.php on line 207
Ideally, there’s a new version of that PHPSass library that can be dropped in to replace the old one which accommodates modern PHP.
Otherwise, it appears those 3 errors can be patched while leaving the rest as-is to get things back into working order on PHP 8.0 from what I’ve tested:
- Replace those 2 sets of curly braces with square brackets
- Add
if(gettype($this->args) == 'string'){ $this->args = array($this->args); }
before$argc = count($this->args);
- Add
$string = ''.$string;
before$strlen = strlen($string);
for the 3 respective files & errors above.
Additionally, it’d probably be good to update/add to the plugin’s data in the main plugin file & readme info for mentioning the required PHP version (currently missing but 5.6 might be a fine option [haven’t tested to be sure] unless 7.0 or something is a better option since those still on 5.6 are likely already needing to use old versions of plugins anyway & would be easier to test/guarantee), required WordPress version (3.8+ might be fine as-is), and the WordPress version it’s been tested up to (currently missing while it can now be 6.2.2 to get rid of that warning on https://www.ads-software.com/plugins/admin-color-schemer/ that says the plugin hasn’t been tested with modern WP versions) while also updating the plugin version, changelog, etc. accordingly.
*Keeping in mind that https://core.trac.www.ads-software.com/ticket/48881 might also still be happening for anyone with checkboxes that don’t show up. I wonder if there’s a good way where the checkbox just isn’t given a custom style unless it’s been specifically set in the custom admin color scheme setting for that one item to help avoid oddities regarding this.
I’ve also posted this at https://github.com/helen/admin-color-schemer/issues/34 if it’s seen as beneficial to discuss/track things further there.
- The topic ‘Fatal Error Fix: PHP 8.x fatal error upon saving custom admin color scheme’ is closed to new replies.