sayontan/suffusion

Issue with PHP 8.1

Closed this issue · 5 comments

I've got a site running WordPress 6.1 and Suffusion 4.5.7 on PHP 8.1.3. I'm seeing these errors in the error_log file

PHP Deprecated: Optional parameter $depth declared before required parameter $output is implicitly treated as a required parameter in /home/xxxxx/xxxxxx/wp/wp-content/themes/suffusion/library/suffusion-walkers.php on line 27

Has anyone developed a fix for this?

Thanks

Roger

Hi,

Has anyone developed a fix for this?

Unfortunately no.

The good news is that PHP Deprecated: is a warning and not an error. The theme will still function with PHP 8.1.3. The following links have more information regarding this deprecation.

https://www.php.net/manual/en/migration80.deprecated.php
and
https://php.watch/versions/8.0/deprecate-required-param-after-optional

Kind regards.

Thanks.

I've "fixed" it for now, by deleting the optional parameter in the function call

// function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) { function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) {

from the variable $depth. That has stopped the warnings filling up the log and the site still seems to work OK.

Roger

Do you mean to say you rem // the function? Or did you actually delete the function altogether from the code?

Kind regards,

I duplicated the function line, then changed the argument for the $depth variable in the second active line and commented out the first original line, so the whole section of suffusion-walkers.php is now

// Roger - next line modified to remove warnings about $depth
// function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, &$output) {
function display_element($element, &$children_elements, $max_depth, $depth, $args, &$output) {
// For nested levels we want to check if the parent is mega-menu enabled. If so, we shouldn't print the children.
if ($depth == 1) {
$parent_id = $element->menu_item_parent;
$selection = get_post_meta($parent_id, 'suf_mm_warea', true);
if (isset($selection) && $selection != '') {
return;
}
}
// If not a mega-menu, display as you would
parent::display_element($element, $children_elements, $max_depth, $depth, $args, $output);
}
}

From a suggestion i found on StackExchange that it would probably work OK without the " = 0" after $depth

Roger

(Sorry - don't know why the block of code isn't displaying correctly)

From a suggestion i found on StackExchange that it would probably work OK without the " = 0" after $depth

Yes, that is correct. I also read in one of the StackExchange support the same information; remove the "= 0" would do the trick. Which is also mentioned in the following link https://www.php.net/manual/en/migration80.deprecated.php. Although in this link it refers to removing the "= null".

If your code is good why don't you submit a Pull request?

In actual fact there are 2 more deprecations in Suffusion. Here are the other 2.

Deprecated: Required parameter $current_comment follows optional parameter $custom_options in F:\xampp8.0.19\htdocs\tipstrickses\wp-content\themes\suffusion\functions\filters.php on line 48

Deprecated: Required parameter $current_post follows optional parameter $custom_options in F:\xampp8.0.19\htdocs\tipstrickses\wp-content\themes\suffusion\functions\filters.php on line 48

I have created my own updated version 4.5.8, which has a few fixes including the following pull request.

#31

Kind regards.