Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with PHP 8.1 #37

Closed
RogerKIWI opened this issue Dec 28, 2022 · 5 comments · Fixed by #42
Closed

Issue with PHP 8.1 #37

RogerKIWI opened this issue Dec 28, 2022 · 5 comments · Fixed by #42

Comments

@RogerKIWI
Copy link

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

@mbrsolution
Copy link

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.

@RogerKIWI
Copy link
Author

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

@mbrsolution
Copy link

mbrsolution commented Jan 2, 2023

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

Kind regards,

@RogerKIWI
Copy link
Author

RogerKIWI commented Jan 2, 2023

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)

@mbrsolution
Copy link

mbrsolution commented Jan 2, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants