-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Improve error handling when converting classic to block menus #52482
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These updates make sense to me 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks for spotting these.
Will need a complementary backport PR to WP Core for WP 6.3.
@dlh01 Are you in a position to take that on?
@@ -31,7 +31,7 @@ public static function convert( $menu ) { | |||
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) ); | |||
|
|||
if ( empty( $menu_items ) ) { | |||
return array(); | |||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this return a WP_error object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also got me thinking. Any changes here will possible effect the fallback handling code so we'd need to check there.
I'd hope if the tests aren't failing it's all ok but it's entirely possible there isn't 100% coverage 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I don't think this should be an error. That's because we have converted the menu but it was just empty. That doesn't make it invalid. The conversion was a success.
We're just exiting early to avoid running the "to_blocks" code.
Later on we throw an error if the conversion to blocks fails because that's a true "error".
@getdave Sure, I think I can do that. Is there anything more to it than filing a core PR with the same changes? |
That would be great. Thank you. Yes you raise a Core PR with the same changes in the equivalent files. And you need a Trac ticket. |
Done in https://core.trac.wordpress.org/ticket/58823 and WordPress/wordpress-develop#4858. Thanks! |
Looks like the failing PHP tests are related:
|
What?
See #52481. Addresses some errors that can occur when
Gutenberg_Navigation_Fallback::create_classic_menu_fallback()
callsGutenberg_Classic_To_Block_Menu_Converter::convert()
.Why?
To avoid unexpected behavior or errors resulting from incorrect type handling.
How?
Improving type-checking and returning types consistent with the documentation