Make WordPress Core

Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#52189 closed enhancement (fixed)

Enable wp_update_nav_menu_item to use passed values for setting post_date

Reported by: jmdodd's profile jmdodd Owned by: pento's profile pento
Milestone: 5.7 Priority: normal
Severity: normal Version: 5.7
Component: Menus Keywords: has-patch has-unit-tests commit has-dev-note
Focuses: Cc:


When a nav menu item is imported, it is given the post_date "now" rather than the value in the export file. There is currently no simple mechanism for setting the post_date for a nav menu item in wp_update_nav_menu_item, even though this value is useful for post_exists checks.

This change will allow the WordPress importer to pass the export file post_date value through wp_update_nav_menu_item, improving performance of post_exists for nav menu items.

This requires the new function resolve_post_date proposed in #52187.

Attachments (2)

52189.diff (1.7 KB) - added by jmdodd 3 years ago.
52189.1.diff (6.6 KB) - added by jmdodd 3 years ago.
Updated patch (now using wp_resolve_post_date) with unit tests for menu date values.

Download all attachments as: .zip

Change History (12)

3 years ago

#1 @SergeyBiryukov
3 years ago

  • Milestone changed from Awaiting Review to 5.7

#2 @mukesh27
3 years ago

Hi @jmdodd, Where I check the resolve_post_date function? I can't found this function in WordPress.

#3 @mukesh27
3 years ago

Got the new function on the #52187 ticket.

3 years ago

Updated patch (now using wp_resolve_post_date) with unit tests for menu date values.

#4 @jmdodd
3 years ago

  • Keywords has-unit-tests added

52189.1.diff avoids insert failures and defaults to using "now", as previously wp_update_nav_menu_item would not fail because of a bad date. I've added unit tests to assert this behavior.

#5 @audrasjb
3 years ago

  • Keywords commit needs-dev-note added
  • Owner set to audrasjb
  • Status changed from new to accepted

I tested the patch and it looks good and relevant to me.
Indeed, it can be useful in some cases to get the post date, especially in custom nav menu walkers.

I'm marking this for commit.

Also adding needs-dev-note workflow keyword to make sure we don't forget to mention it in the Miscellaneous changes dev note :)

#6 @pento
3 years ago

  • Owner changed from audrasjb to pento

#7 @pento
3 years ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 50013:

Menus: Make use of wp_resolve_post_date() when updating menu items.

This allows a menu item post_date to be set to particular value, rather than only allowing it to be set to "now". In particular, the WordPress Importer can use this to perform faster, more accurate duplicate checks.

Props jmdodd.
Fixes #52189.

#8 @TimothyBlynJacobs
3 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

It looks like the tests are introducing a phpcs error due to the usage of date instead of gmdate.

#9 @pento
3 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 50014:

Menus: Fix linting errors introduced in [50013].

Props TimothyBlynJacobs.
Fixes #52189.

Note: See TracTickets for help on using tickets.