Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #276 from xwp/bugfix/disable-non-published-pages-i…
Browse files Browse the repository at this point in the history
…n-dropdown-pages-controls

Disable non-published pages from the dropdown-pages controls
  • Loading branch information
westonruter authored Sep 18, 2016
2 parents 14fb231 + 710bf25 commit f7433ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 6 additions & 3 deletions js/customize-post-section.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@

// Update the dropdown-pages controls.
api.control.each( function( control ) {
var pageOption, select, isTrashed, optionText;
var pageOption, select, isTrashed, isPublished, optionText;

// Skip anything but the dropdown-pages control, including the Customize Object Selector control..
if ( 'dropdown-pages' !== control.params.type ) {
Expand All @@ -944,14 +944,17 @@

// Remove a trashed post from being selected.
isTrashed = 'trash' === newPostData.post_status;
if ( isTrashed && parseInt( control.setting.get(), 10 ) === section.params.post_id ) {
isPublished = 'publish' === newPostData.post_status;
if ( ! isPublished && parseInt( control.setting.get(), 10 ) === section.params.post_id ) {
control.setting.set( 0 );
}

// Sync the page option into the select options.
optionText = newPostData.post_title || api.Posts.data.l10n.noTitle;
if ( isTrashed ) {
optionText = api.Posts.data.l10n.dropdownPagesOptionTrashed.replace( '%s', optionText );
} else if ( ! isPublished ) {
optionText = api.Posts.data.l10n.dropdownPagesOptionUnpublished.replace( '%s', optionText );
}
select = control.container.find( 'select' );
pageOption = select.find( 'option[value="' + String( section.params.post_id ) + '"]' );
Expand All @@ -966,7 +969,7 @@
}

// Note that the option may or may not also be hidden. The visibility is tied a collision-prevention state.
pageOption.prop( 'disabled', isTrashed );
pageOption.prop( 'disabled', ! isPublished );
});
},

Expand Down
2 changes: 2 additions & 0 deletions php/class-wp-customize-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ public function enqueue_scripts() {
'invalidDateError' => __( 'Whoops, the provided date is invalid.', 'customize-posts' ),
/* translators: %s is the trashed page name */
'dropdownPagesOptionTrashed' => __( '%s (Trashed)', 'customize-posts' ),
/* translators: %s is the trashed page name */
'dropdownPagesOptionUnpublished' => __( '%s (Unpublished)', 'customize-posts' ),
'editPostFailure' => __( 'Failed to open for editing.', 'customize-posts' ),
'createPostFailure' => __( 'Failed to create for editing.', 'customize-posts' ),
'installCustomizeObjectSelector' => sprintf(
Expand Down

0 comments on commit f7433ff

Please sign in to comment.