- This topic has 5 replies, 2 voices, and was last updated 3 years, 3 months ago by
David.
-
AuthorPosts
-
January 12, 2023 at 11:06 pm #2493782
Gevorg
Hello,
We have LearnDash installed and its quizzes break after upgrading to PHP 8. I have contacted their support and after checking the error logs, they suggested contacting the GP support.
I would really appreciate it if you could take a look at this and see if there is a fix.
You can find more information in the form below.Thank you.
January 13, 2023 at 4:07 am #2494053David
StaffCustomer SupportHi there,
the Stack Trace points to line 32 of the
content-single.phptemplate in your child theme.This line:
$mainCategorySlug = str_replace(' ', '-', strtolower($mainCategory));For reference in this part of the code:
if ( $mainCategory == '' ) { $mainCategory = get_the_category_by_ID($subcategory->category_parent); $mainCategorySlug = str_replace(' ', '-', strtolower($mainCategory)); }The
strtolowerfunction is expecting$mainCategoryto be a string and for whatever reason it is not.To debug comment out that line and
var_dumpthe variable eg.if ( $mainCategory == '' ) { $mainCategory = get_the_category_by_ID($subcategory->category_parent); //$mainCategorySlug = str_replace(' ', '-', strtolower($mainCategory)); var_dump($mainCategory); }It may give you some idea of whats going wrong.
January 13, 2023 at 4:50 am #2494091Gevorg
Hi David,
As always your codes are spot on and solve the problem. Thank you so much!
The only issue now is that there is an error message on the quiz pages:
object(WP_Error)#5500 (3) { [“errors”]=> array(1) { [“invalid_term”]=> array(1) { [0]=> string(11) “Empty Term.” } } [“error_data”]=> array(0) { } [“additional_data”:protected]=> array(0) { } }
Is there a way to get rid of that?
January 13, 2023 at 6:59 am #2494217David
StaffCustomer SupportSo thats what
var_dumpis doing which we can use to debug the issue.Ill try and explain, so in your code:
if ( $mainCategory == '' ) { $mainCategory = get_the_category_by_ID($subcategory->category_parent); $mainCategorySlug = str_replace(' ', '-', strtolower($mainCategory)); }This line:
$mainCategory = get_the_category_by_ID($subcategory->category_parent);is loading the$mainCategorywith a category term that is returned by theget_the_category_by_IDfunction.
Theget_the_category_by_IDwill either return the correct term name as astringor awp_error as an arrayThis line uses:
$mainCategorySlug = str_replace(' ', '-', strtolower($mainCategory));then uses the
strtolowerfunction to convert the$mainCategory stringto lower case.But as
var_dumpshows us the$mainCategoryis returning an wp_error array so thestrtolowerfunction fails as it wants a string.Try changing that code to:
if ( $mainCategory == '' ) { $mainCategory = get_the_category_by_ID($subcategory->category_parent); if ( ! is_wp_error( $mainCategory ) ) { $mainCategorySlug = str_replace(' ', '-', strtolower($mainCategory)); } }This will check to make sure there is ! (not) a wp_error before doing the string replace.
January 13, 2023 at 7:14 am #2494233Gevorg
David,
Thank you so much for your help! It works now. I appreciate it.
Have a great day.
January 13, 2023 at 7:53 am #2494369David
StaffCustomer SupportYou’re welcome.
-
AuthorPosts
- You must be logged in to reply to this topic.