Skip to content

Commit 2ad0566

Browse files
committed
Fix adding custom fields for newly-inserted items
1 parent 087e696 commit 2ad0566

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

customize-nav-menu-item-custom-fields.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ var CustomizeNavMenuItemCustomFields = (function( $ ) {
66

77
var component = {
88
api: null,
9+
hasSaved: false,
910
data: {
1011
metaKeys: [],
1112
l10n: {
@@ -39,7 +40,12 @@ var CustomizeNavMenuItemCustomFields = (function( $ ) {
3940
api.control.each( component.prepareCustomFields );
4041
api.control.bind( 'add', component.prepareCustomFields );
4142

42-
// @todo Delete postmeta when nav menu is removed?
43+
// @todo Delete postmeta (or clear _dirty flag) when nav menu is removed?
44+
45+
// @todo The hasSaved property is needed because of a core bug where expanded set but instead a class is being toggled directly: https://github.com/xwp/wordpress-develop/blob/a803a33c04dfd083b5b012ba1e8c79752209ac3c/src/wp-admin/js/customize-nav-menus.js#L2909
46+
api.bind( 'saved', function() {
47+
component.hasSaved = true;
48+
} );
4349

4450
// Export the component to be available at wp.customize.Menus.ItemCustomFields.
4551
component.api.Menus.ItemCustomFields = component;
@@ -115,6 +121,8 @@ var CustomizeNavMenuItemCustomFields = (function( $ ) {
115121
component.requestItemsPostmetaSettingsTimeoutId = setTimeout( function() {
116122
var ensurePostsPromise = component.api.Posts.ensurePosts( component.pendingRequestPostmetaSettingsItemIds );
117123
component.pendingRequestPostmetaSettingsItemIds = [];
124+
component.requestItemsPostmetaSettingsDeferred = null;
125+
component.requestItemsPostmetaSettingsTimeoutId = null;
118126
ensurePostsPromise.done( function( gatheredFetchedPostsData ) {
119127
var postmetaSettings = {};
120128

@@ -242,7 +250,7 @@ var CustomizeNavMenuItemCustomFields = (function( $ ) {
242250

243251
// Defer initializing custom fields until the control is embedded and expanded. This improves DOM performance.
244252
control.deferred.embedded.done( function() {
245-
if ( control.expanded.get() ) {
253+
if ( component.hasSaved || control.expanded.get() ) {
246254
component.initializeCustomFields( control );
247255
} else {
248256
control.expanded.bind( onceExpanded );

0 commit comments

Comments
 (0)