Skip to content

Importing a WXR with a menu item that references a taxonomy that doesn't exist, causes a fatal #164

Closed as not planned
@dd32

Description

@dd32

This bug is in WordPress core, but I think it can only be triggered through an import, so I'm filing the initial details here. This might be resolved via Core, or maybe it should be handled in the Importer.

Reported in the forums:
https://wordpress.org/support/topic/uncaught-error-object-of-class-wp_error-could-not-be-converted-to-string-7/

Duplicated in Playground

  • Create a Menu, add a taxonomy item
  • Export the site
  • Edit the export to change the taxonomy of the nav_menu_item to a taxonomy that doesn't exist
  • Import and hit fatal error.

This could also be triggered by using a plugin that adds a taxonomy, add that taxonomy to a menu, and then export/import into a new site without that plugin.

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

Example WXR that triggers this mywordpresswebsite.WordPress.2024-08-01.xml.zip which can be uploaded at this playground instance and you'll then see the error in the browser console.

The Core lines that triggers it:
https://github.com/WordPress/wordpress-develop/blob/50af37a9083f003f8e98d089091d2cc428797cc5/src/wp-includes/nav-menu.php#L496

if ( 'taxonomy' === $args['menu-item-type'] ) {
	$original_title  = get_term_field( 'name', $args['menu-item-object-id'], $args['menu-item-object'], 'raw' );
}
....
if ( wp_unslash( $args['menu-item-title'] ) === wp_specialchars_decode( $original_title ) ) {

$original_title is a WP_Error as it's an unknown taxonomy in $args['menu-item-object'].

Core could avoid this as it does elsewhere in that code, or the Importer could not import unknown taxonomy items.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions