diff --git a/js/customize-post-section.js b/js/customize-post-section.js index 0ace896..31adfde 100644 --- a/js/customize-post-section.js +++ b/js/customize-post-section.js @@ -275,6 +275,9 @@ if ( postTypeObj.supports['page-attributes'] || postTypeObj.supports.parent ) { section.addParentControl(); } + if ( postTypeObj.supports['page-attributes'] || postTypeObj.supports.ordering ) { + section.addOrderControl(); + } if ( postTypeObj.supports.editor ) { section.addContentControl(); } @@ -400,7 +403,7 @@ control = new api.controlConstructor.dynamic( section.id + '[post_name]', { params: { section: section.id, - priority: 15, + priority: 20, label: postTypeObj.labels.slug_field ? postTypeObj.labels.slug_field : api.Posts.data.l10n.fieldSlugLabel, active: true, settings: { @@ -450,7 +453,7 @@ control = new api.controlConstructor.post_status( section.id + '[post_status]', { params: { section: section.id, - priority: 20, + priority: 30, label: postTypeObj.labels.status_field ? postTypeObj.labels.status_field : api.Posts.data.l10n.fieldStatusLabel, settings: { 'default': setting.id @@ -474,75 +477,6 @@ return control; }, - /** - * Add parent control. - * - * @returns {wp.customize.Control} Added control. - */ - addParentControl: function() { - var section = this, control, setting = api( section.id ), controlId, params, postTypeObj; - postTypeObj = api.Posts.data.postTypes[ section.params.post_type ]; - - controlId = section.id + '[post_parent]'; - params = { - section: section.id, - priority: 20, - label: postTypeObj.labels.parent_item_colon ? postTypeObj.labels.parent_item_colon.replace( /:$/, '' ) : api.Posts.data.l10n.fieldParentLabel, - active: true, - settings: { - 'default': setting.id - }, - field_type: 'select', - setting_property: 'post_parent' - }; - - if ( api.controlConstructor.object_selector ) { - control = new api.controlConstructor.object_selector( controlId, { - params: _.extend( params, { - post_query_vars: { - post_type: section.params.post_type, - post_status: 'publish', - post__not_in: [ section.params.post_id ], - show_initial_dropdown: true, - dropdown_args: { - exclude_tree: section.params.post_id, - sort_column: 'menu_order, post_title' - }, - apply_dropdown_args_filters_post_id: section.params.post_id // Applies page_attributes_dropdown_pages_args filters. - }, - show_add_buttons: false, - select2_options: { - multiple: false, - allowClear: true, - placeholder: postTypeObj.labels.search_items - } - } ) - } ); - } else { - control = new api.controlConstructor.dynamic( controlId, { - params: _.extend( params, { - field_type: 'hidden', - description: api.Posts.data.l10n.installCustomizeObjectSelector - } ) - } ); - } - - // Override preview trying to de-activate control not present in preview context. - control.active.validate = function() { - return true; - }; - - // Register. - section.postFieldControls.page_parent = control; - api.control.add( control.id, control ); - - if ( control.notifications ) { - control.notifications.add = section.addPostFieldControlNotification; - control.notifications.setting_property = control.params.setting_property; - } - return control; - }, - /** * Add post date control. * @@ -555,7 +489,7 @@ control = new api.controlConstructor.post_date( section.id + '[post_date]', { params: { section: section.id, - priority: 21, + priority: 40, label: postTypeObj.labels.date_field ? postTypeObj.labels.date_field : api.Posts.data.l10n.fieldDateLabel, description: api.Posts.data.l10n.fieldDateDescription, settings: { @@ -592,6 +526,7 @@ control = new api.controlConstructor.post_editor( section.id + '[post_content]', { params: { section: section.id, + priority: 50, label: postTypeObj.labels.content_field ? postTypeObj.labels.content_field : api.Posts.data.l10n.fieldContentLabel, setting_property: 'post_content', settings: { @@ -627,7 +562,7 @@ control = new api.controlConstructor.dynamic( section.id + '[post_excerpt]', { params: { section: section.id, - priority: 30, + priority: 60, label: postTypeObj.labels.excerpt_field ? postTypeObj.labels.excerpt_field : api.Posts.data.l10n.fieldExcerptLabel, active: true, settings: { @@ -654,6 +589,113 @@ return control; }, + /** + * Add parent control. + * + * @returns {wp.customize.Control} Added control. + */ + addParentControl: function addParentControl() { + var section = this, control, setting = api( section.id ), controlId, params, postTypeObj; + postTypeObj = api.Posts.data.postTypes[ section.params.post_type ]; + + controlId = section.id + '[post_parent]'; + params = { + section: section.id, + priority: 70, + label: postTypeObj.labels.parent_item_colon ? postTypeObj.labels.parent_item_colon.replace( /:$/, '' ) : api.Posts.data.l10n.fieldParentLabel, + active: true, + settings: { + 'default': setting.id + }, + field_type: 'select', + setting_property: 'post_parent' + }; + + if ( api.controlConstructor.object_selector ) { + control = new api.controlConstructor.object_selector( controlId, { + params: _.extend( params, { + post_query_vars: { + post_type: section.params.post_type, + post_status: 'publish', + post__not_in: [ section.params.post_id ], + show_initial_dropdown: true, + dropdown_args: { + exclude_tree: section.params.post_id, + sort_column: 'menu_order, post_title' + }, + apply_dropdown_args_filters_post_id: section.params.post_id // Applies page_attributes_dropdown_pages_args filters. + }, + show_add_buttons: false, + select2_options: { + multiple: false, + allowClear: true, + placeholder: postTypeObj.labels.search_items + } + } ) + } ); + } else { + control = new api.controlConstructor.dynamic( controlId, { + params: _.extend( params, { + field_type: 'hidden', + description: api.Posts.data.l10n.installCustomizeObjectSelector + } ) + } ); + } + + // Override preview trying to de-activate control not present in preview context. + control.active.validate = function() { + return true; + }; + + // Register. + section.postFieldControls.page_parent = control; + api.control.add( control.id, control ); + + if ( control.notifications ) { + control.notifications.add = section.addPostFieldControlNotification; + control.notifications.setting_property = control.params.setting_property; + } + return control; + }, + + /** + * Add order control. + * + * @returns {wp.customize.Control} Added control. + */ + addOrderControl: function addOrderControl() { + var section = this, control, setting = api( section.id ), postTypeObj; + postTypeObj = api.Posts.data.postTypes[ section.params.post_type ]; + control = new api.controlConstructor.dynamic( section.id + '[menu_order]', { + params: { + section: section.id, + priority: 80, + label: postTypeObj.labels.order_field ? postTypeObj.labels.order_field : api.Posts.data.l10n.fieldOrderLabel, + active: true, + settings: { + 'default': setting.id + }, + field_type: 'number', + setting_property: 'menu_order' + } + } ); + + // Override preview trying to de-activate control not present in preview context. See WP Trac #37270. + control.active.validate = function() { + return true; + }; + + // Register. + section.postFieldControls.menu_order = control; + api.control.add( control.id, control ); + + if ( control.notifications ) { + control.notifications.add = section.addPostFieldControlNotification; + control.notifications.setting_property = control.params.setting_property; + } + return control; + }, + /** * Add discussion fields (comments and ping status fields) control. * @@ -665,7 +707,7 @@ control = new api.controlConstructor.post_discussion_fields( section.id + '[discussion_fields]', { params: { section: section.id, - priority: 60, + priority: 90, label: postTypeObj.labels.discussion_field ? postTypeObj.labels.discussion_field : api.Posts.data.l10n.fieldDiscusionLabel, active: true, settings: { @@ -702,7 +744,7 @@ control = new api.controlConstructor.dynamic( section.id + '[post_author]', { params: { section: section.id, - priority: 70, + priority: 100, label: postTypeObj.labels.author_field ? postTypeObj.labels.author_field : api.Posts.data.l10n.fieldAuthorLabel, active: true, settings: { diff --git a/php/class-wp-customize-posts-preview.php b/php/class-wp-customize-posts-preview.php index 7534fdd..1d73f2f 100644 --- a/php/class-wp-customize-posts-preview.php +++ b/php/class-wp-customize-posts-preview.php @@ -1071,6 +1071,9 @@ public function get_post_field_partial_schema( $field_id = '' ) { 'post_parent' => array( 'fallback_refresh' => true, ), + 'menu_order' => array( + 'fallback_refresh' => true, + ), 'post_date' => array( 'selector' => 'time.entry-date', 'fallback_refresh' => false, diff --git a/php/class-wp-customize-posts.php b/php/class-wp-customize-posts.php index c23ce9c..06b85a5 100644 --- a/php/class-wp-customize-posts.php +++ b/php/class-wp-customize-posts.php @@ -728,6 +728,7 @@ public function enqueue_scripts() { 'fieldDiscussionLabel' => __( 'Discussion', 'customize-posts' ), 'fieldAuthorLabel' => __( 'Author', 'customize-posts' ), 'fieldParentLabel' => __( 'Parent', 'customize-posts' ), + 'fieldOrderLabel' => __( 'Order', 'customize-posts' ), 'noTitle' => __( '(no title)', 'customize-posts' ), 'theirChange' => __( 'Their change: %s', 'customize-posts' ), 'openEditor' => __( 'Open Editor', 'customize-posts' ), // @todo Move this into editor control?