#61799 closed defect (bug) (fixed)
Calling wp_update_nav_menu_item() with an invalid taxonomy causes a fatal error
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.7 | Priority: | normal |
| Severity: | normal | Version: | 5.5 |
| Component: | Import | Keywords: | has-patch |
| Focuses: | Cc: |
Description
For background, please see https://github.com/WordPress/wordpress-importer/issues/164
When attempting to import a WXR which contains a Nav menu item that references a taxonomy that doesn't exist on the site, wp_update_nav_menu_item() will hit a fatal error.
PHP Fatal error: Uncaught Error: Object of class WP_Error could not be converted to string in /wordpress/wp-includes/formatting.php:2
Stack trace:
#0 /wordpress/wp-includes/nav-menu.php(2): wp_specialchars_decode(Object(WP_Error))
#1 /wordpress/wp-content/plugins/wordpress-importer/class-wp-import.php(996): wp_update_nav_menu_item(3, 0, Array)
#2 /wordpress/wp-content/plugins/wordpress-importer/class-wp-import.php(653): WP_Import->process_menu_item(Array)
#3 /wordpress/wp-content/plugins/wordpress-importer/class-wp-import.php(89): WP_Import->process_posts()
#4 /wordpress/wp-content/plugins/wordpress-importer/class-wp-import.php(65): WP_Import->import('/wordpress/wp-c...')
#5 /wordpress/wp-admin/admin.php(2): WP_Import->dispatch()
#6 {main}
thrown in /wordpress/wp-includes/formatting.php on line 2
It appears that invalid post type archives are handled, just not missing taxonomies.
Relevant lines:
https://core.trac.wordpress.org/browser/tags/6.6/src/wp-includes/nav-menu.php?marks=496,509#L484
$original_title will be a WP_Error for a non-existent taxonomy in $args['menu-item-object'].
Change History (7)
#2
follow-up:
↓ 4
@
19 months ago
The changes you suggest works but the get_term_field return $term here https://github.com/WordPress/wordpress-develop/blob/6.6/src/wp-includes/taxonomy.php#L1221-L1236, If it return error then it should return null instead of $term
what do you think?
This ticket was mentioned in PR #7121 on WordPress/wordpress-develop by @narenin.
19 months ago
#3
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/61799
#4
in reply to:
↑ 2
@
19 months ago
Replying to mukesh27:
If it return error then it should return null instead of
$term
It is 'weird' that it returns an empty string in other cases of error, but not this one.
But given it's documented as returning an empty string, and has done so since [5726] it's not worth changing IMHO.
#5
@
19 months ago
- Milestone changed from Awaiting Review to 6.7
- Owner set to SergeyBiryukov
- Status changed from new to reviewing
@SergeyBiryukov commented on PR #7121:
19 months ago
#7
Thanks for the PR! Merged in r58854.
Untested, but it might be enough to simply avoid the fatal on update and leave the menu code to resolve the issue elsewhere:
nav-menu.php
) {