I have recently discovered that my website is not working due to an upgrade to PHP 8.1 from my hosting service. The problem I am facing is that the website is old and there no more updates on the template.
Here is one of the error but they all are similar:
Deprecated: Optional parameter $content declared before required parameter $tag is implicitly treated as a required parameter in /home1/bici/public_html/font/wp-content/plugins/motopress-content-editor-lite/includes/ce/shortcode/ShortcodeCommon.php on line 395
This is the code in line 395
function mp_span($atts, $content = null, $tag) {
extract(shortcode_atts(self::addStyleAtts(self::getAtts($tag)), $atts));
if (!empty($classes)) $classes = ' ' . $classes;
if (!empty($mp_style_classes)) $mp_style_classes = ' ' . $mp_style_classes;
if (!empty($style)) $style = ' style="' . $style . '"';
$spanClasses = "motopress-clmn mp-span{$col} " . self::handleCustomStyles( $mp_custom_style, $tag ) . $classes .
self::getMarginClasses( $margin ) . self::getBasicClasses( $tag, true ) . $mp_style_classes;
return '<div class="' . $spanClasses . '"' . $style . '>' . do_shortcode( $content ) . '</div>';
}
I have also had other problems with cherry plugin and PHP 8 that I have solved thanks to this link.
I am probably redoing the website new from scratch as this is a big issue in all the items also on the backend. But is it possible for anyone to help and fix it while I create the new one?
2
Answers
Youre issue has to do with addition of stricter rules about function parameter arrangement (since PHP 8.1). Default values have to be after the required parameters:
You can read about that here (Example #4 Use of default parameters in functions)
You are encountering a PHP deprecation warning after upgrading your PHP version to 8.1. The error message you’re seeing is:
This happens because PHP 8.1 introduces stricter rules on function parameter ordering. Specifically, optional parameters (those with default values, like $content = null) cannot come before required parameters (like $tag in your function).
In your mp_span function, $content is declared as an optional parameter with a default value of null, but $tag is a required parameter. This causes the deprecation notice because in PHP 8.1, an optional parameter cannot be listed before a required one.
Reordering the function parameters to ensure that required parameters come before optional ones fixes the deprecation warning in PHP 8.1. Make this change to your code, and it will be fully compatible with PHP 8.1 and beyond.