fix: prevent clean_nav_menu crash on PHP 8.5 and reduce theme breakage#22
Conversation
…akage The clean_nav_menu optimization called array_intersect() on the nav_menu_css_class filter assuming $classes is always an array. Some page builders pass a string, which fatals with a TypeError on PHP 8.5+ and white-screens the whole frontend. - Guard the filter callback with is_array(), returning the value unchanged when it is not an array. - Stop forcing nav_menu_item_id to null so menu item IDs are preserved for JS/anchor/accessibility targeting. - Make the optimization opt-in (default false) so it no longer breaks themes that rely on custom menu classes out of the box. Existing sites keep their saved setting.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe Changesclean_nav_menu Safety Fix and Default Change
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
The Clean Navigation Menu optimization (
includes/Optimizations/General.php) caused two problems, both addressed here:nav_menu_css_classcallback calledarray_intersect( $classes, [...] )assuming$classesis always an array. Some page builders pass a string, which throws an uncaughtTypeErroron PHP 8.5+ and white-screens the entire frontend (HTTP 500).Changes
General.php— add anis_array()guard to thenav_menu_css_classcallback (returns the value unchanged when not an array); this matches the existing emoji guard atGeneral.php:48.General.php— removeadd_filter( 'nav_menu_item_id', '__return_null' )so menu item IDs are preserved.Optimizations.php— flip theclean_nav_menudefault fromtrue→false, making it opt-in. Existing sites keep their saved value (the settings save handler always writes every field; defaults only apply when no option row exists).Testing
php -lpasses on both files.nav_menu_css_classreturns unchanged (noTypeError).clean_nav_menutofalse; previously-saved enabled sites stay enabled.Summary by CodeRabbit
Bug Fixes
Chores