WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#40596 closed defect (bug) (duplicate)

Import nav_menu_item fails on PHP 7

Reported by: RavanH Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.7.4
Component: Import Keywords:
Focuses: Cc:

Description

When I do a WordPress Export and then an Import it on another WordPress install, all menus are imported as expected but they are empty. It appears menu items are skipped for some reason.

Looking through the export xml file, I find all items of post-type nav_menu_item are there, so the problem must lie with the import.

Change History (9)

#1 @RavanH
4 years ago

  • Keywords needs-testing added

#2 @RavanH
4 years ago

WP_DEBUG log shows these notices

[28-Apr-2017 14:45:56 UTC] PHP Notice:  Undefined variable: _menu_item_type in /home/grainsdihq/www/wp-content/plugins/wordpress-importer/wordpress-importer.php on line 886
[28-Apr-2017 14:45:56 UTC] PHP Notice:  Undefined variable: _menu_item_type in /home/grainsdihq/www/wp-content/plugins/wordpress-importer/wordpress-importer.php on line 888
[28-Apr-2017 14:45:56 UTC] PHP Notice:  Undefined variable: _menu_item_type in /home/grainsdihq/www/wp-content/plugins/wordpress-importer/wordpress-importer.php on line 890

but no errors are reported. This is on PHP7, will test on PHP5.6 now...

#3 @RavanH
4 years ago

On PHP 5.6 it turns out there is no problem with importing menu items. Issue seems PHP 7 (7.0 and 7.1) related only.

Last edited 4 years ago by RavanH (previous) (diff)

#4 @RavanH
4 years ago

  • Summary changed from Export/import creates empty menus to Import nav_menu_item fails on PHP 7

#5 @mixoet
4 years ago

Meta variables are undefined, because syntax of variable variables changed in PHP7. So if you change line 884 in wordpress-importer.php

<?php
$$meta['key'] = $meta['value'];

to

<?php
${$meta['key']} = $meta['value'];

should do the trick. Unable to test it myself.

#6 @RavanH
4 years ago

Tested and confirmed. Thanks @mixoet :)

#7 @RavanH
4 years ago

  • Keywords has-patch added; needs-testing removed

#8 @netweb
4 years ago

  • Keywords needs-patch added; has-patch removed

For has-patch we need a patch uploaded to this ticket :)

Details on creating and uploading patches can be found in our handbook here.

#9 @dd32
4 years ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #36281.

Note: See TracTickets for help on using tickets.