-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Administration: Add box reordering toggle to Screen Options. #12180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,6 +104,10 @@ | |
| postboxWithinSortablesIndex = postboxesWithinSortables.index( postbox ), | ||
| firstOrLastPositionMessage; | ||
|
|
||
| if ( ! postboxes.metaBoxReorderingEnabled ) { | ||
| return; | ||
| } | ||
|
|
||
| if ( 'dashboard_browser_nag' === postboxId ) { | ||
| return; | ||
| } | ||
|
|
@@ -344,6 +348,13 @@ | |
| postboxes.save_order( page ); | ||
| } | ||
| }); | ||
|
|
||
| $( '.meta-box-reordering-toggle' ).on( 'click.postboxes', function() { | ||
| var enabled = $( this ).prop( 'checked' ); | ||
|
|
||
| postboxes.setMetaBoxReordering( enabled ); | ||
| postboxes.save_meta_box_reordering_state( enabled ); | ||
| } ); | ||
| }, | ||
|
|
||
| /** | ||
|
|
@@ -419,6 +430,8 @@ | |
| } | ||
| }); | ||
|
|
||
| this.setMetaBoxReordering( this.isMetaBoxReorderingEnabled() ); | ||
|
|
||
| if ( isMobile ) { | ||
| $(document.body).on('orientationchange.postboxes', function(){ postboxes._pb_change(); }); | ||
| this._pb_change(); | ||
|
|
@@ -437,6 +450,68 @@ | |
| }); | ||
| }, | ||
|
|
||
| /** | ||
| * Checks whether meta box reordering is enabled. | ||
| * | ||
| * @since 7.1.0 | ||
| * | ||
| * @return {boolean} Whether meta box reordering is enabled. | ||
| */ | ||
| isMetaBoxReorderingEnabled: function() { | ||
| var $toggle = $( '#meta-box-reordering' ); | ||
|
|
||
| if ( $toggle.length ) { | ||
| return $toggle.prop( 'checked' ); | ||
| } | ||
|
|
||
| return ! $( document.body ).hasClass( 'meta-box-reordering-disabled' ); | ||
| }, | ||
|
|
||
| /** | ||
| * Enables or disables the meta box reordering UI. | ||
| * | ||
| * @since 7.1.0 | ||
| * | ||
| * @param {boolean} enabled Whether reordering should be enabled. | ||
| * @return {void} | ||
| */ | ||
| setMetaBoxReordering: function( enabled ) { | ||
| var $body = $( document.body ), | ||
| $orderButtons = $( '.postbox .handle-order-higher, .postbox .handle-order-lower' ); | ||
|
|
||
| this.metaBoxReorderingEnabled = !! enabled; | ||
|
|
||
| $body | ||
| .toggleClass( 'meta-box-reordering-enabled', this.metaBoxReorderingEnabled ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can simplify this by not adding |
||
| .toggleClass( 'meta-box-reordering-disabled', ! this.metaBoxReorderingEnabled ); | ||
|
|
||
| if ( this.metaBoxReorderingEnabled ) { | ||
| $orderButtons | ||
| .prop( 'disabled', false ) | ||
| .removeAttr( 'tabindex aria-hidden' ); | ||
| this.updateOrderButtonsProperties(); | ||
| } else { | ||
| $orderButtons | ||
| .prop( 'disabled', true ) | ||
| .attr( { | ||
| 'aria-hidden': 'true', | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not necessary to add any of these attributes to items hidden using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (that covers all of |
||
| tabindex: '-1' | ||
| } ); | ||
| } | ||
|
|
||
| if ( window.wpResponsive && window.wpResponsive.maybeDisableSortables ) { | ||
| window.wpResponsive.maybeDisableSortables(); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| $( '.meta-box-sortables' ) | ||
| .sortable( this.metaBoxReorderingEnabled ? 'enable' : 'disable' ) | ||
| .find( '.ui-sortable-handle' ) | ||
| .toggleClass( 'is-non-sortable', ! this.metaBoxReorderingEnabled ); | ||
|
Comment on lines
+508
to
+511
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this in a |
||
| } catch ( e ) {} | ||
| }, | ||
|
|
||
| /** | ||
| * Saves the state of the postboxes to the server. | ||
| * | ||
|
|
@@ -476,6 +551,30 @@ | |
| ); | ||
| }, | ||
|
|
||
| /** | ||
| * Saves the meta box reordering setting to the server. | ||
| * | ||
| * @since 7.1.0 | ||
| * | ||
| * @memberof postboxes | ||
| * | ||
| * @param {boolean} enabled Whether meta box reordering is enabled. | ||
| * @return {void} | ||
| */ | ||
| save_meta_box_reordering_state : function( enabled ) { | ||
| $.post( | ||
| ajaxurl, | ||
| { | ||
| action: 'meta-box-reordering', | ||
| enabled: enabled ? 1 : 0, | ||
| screenoptionnonce: $( '#screenoptionnonce' ).val() | ||
| }, | ||
| function() { | ||
| wp.a11y.speak( __( 'Screen Options updated.' ) ); | ||
| } | ||
| ); | ||
| }, | ||
|
|
||
| /** | ||
| * Saves the order of the postboxes to the server. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -214,6 +214,8 @@ | |
| $admin_body_class .= ' block-editor-page wp-embed-responsive'; | ||
| } | ||
|
|
||
| $admin_body_class .= wp_is_meta_box_reordering_enabled() ? ' meta-box-reordering-enabled' : ' meta-box-reordering-disabled'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can simplify this by not adding |
||
|
|
||
| $admin_body_class .= ' wp-theme-' . sanitize_html_class( get_template() ); | ||
| if ( is_child_theme() ) { | ||
| $admin_body_class .= ' wp-child-theme-' . sanitize_html_class( get_stylesheet() ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1856,6 +1856,25 @@ function wp_ajax_hidden_columns() { | |
| wp_die( 1 ); | ||
| } | ||
|
|
||
| /** | ||
| * Handles the meta box reordering setting via Ajax. | ||
| * | ||
| * @since 7.1.0 | ||
| */ | ||
| function wp_ajax_meta_box_reordering() { | ||
| check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' ); | ||
|
|
||
| $user = wp_get_current_user(); | ||
| if ( ! $user ) { | ||
| wp_die( -1 ); | ||
| } | ||
|
Comment on lines
+1868
to
+1870
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will never happen, I believe - Perhaps we meant to do either |
||
|
|
||
| $enabled = isset( $_POST['enabled'] ) && '1' === (string) $_POST['enabled']; | ||
| update_user_meta( $user->ID, 'meta_box_reordering', $enabled ? 'enabled' : 'disabled' ); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We seem to be using both the user option and user meta APIs a bit asymetrically here. This will work just because |
||
|
|
||
| wp_die( 1 ); | ||
| } | ||
|
|
||
| /** | ||
| * Handles updating whether to display the welcome panel via AJAX. | ||
| * | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1006,11 +1006,23 @@ public function show_screen_options() { | |
|
|
||
| $this->_screen_settings = ''; | ||
|
|
||
| $additional_settings = ''; | ||
|
|
||
| if ( $this->show_meta_box_reordering_options() ) { | ||
|
Comment on lines
+1009
to
+1011
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is false (when no meta boxes are registered), we'll renter an an "Additional settings" fieldset that contains only a |
||
| $additional_settings .= $this->get_meta_box_reordering_option(); | ||
| } | ||
|
|
||
| if ( 'post' === $this->base ) { | ||
| $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">'; | ||
| $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />'; | ||
| $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>'; | ||
| $this->_screen_settings = $expand; | ||
| $additional_settings .= '<label class="editor-expand hidden" for="editor-expand-toggle">'; | ||
| $additional_settings .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' /> '; | ||
| $additional_settings .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label>'; | ||
| } | ||
|
|
||
| if ( $additional_settings ) { | ||
| $this->_screen_settings = '<fieldset class="metabox-prefs additional-settings-prefs">'; | ||
| $this->_screen_settings .= '<legend>' . __( 'Additional settings' ) . '</legend>'; | ||
| $this->_screen_settings .= $additional_settings; | ||
| $this->_screen_settings .= '</fieldset>'; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -1023,7 +1035,7 @@ public function show_screen_options() { | |
| */ | ||
| $this->_screen_settings = apply_filters( 'screen_settings', $this->_screen_settings, $this ); | ||
|
|
||
| if ( $this->_screen_settings || $this->_options ) { | ||
| if ( $this->_screen_settings || $this->_options || $this->show_meta_box_reordering_options() ) { | ||
| $show_screen = true; | ||
| } | ||
|
|
||
|
|
@@ -1120,8 +1132,8 @@ public function render_meta_boxes_preferences() { | |
| <fieldset class="metabox-prefs"> | ||
| <legend><?php _e( 'Screen elements' ); ?></legend> | ||
| <p> | ||
| <?php _e( 'Some screen elements can be shown or hidden by using the checkboxes.' ); ?> | ||
| <?php _e( 'Expand or collapse the elements by clicking on their headings, and arrange them by dragging their headings or by clicking on the up and down arrows.' ); ?> | ||
| <?php _e( 'Use the checkboxes to show or hide screen elements.' ); ?> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not change strings that aren't necessary to change as part of this issue. |
||
| <?php _e( 'Expand or collapse screen elements by clicking their headings.' ); ?> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This text should still address the ability to move metaboxes, but add text covering how to turn the option on and off. |
||
| </p> | ||
| <div class="metabox-prefs-container"> | ||
| <?php | ||
|
|
@@ -1148,6 +1160,53 @@ public function render_meta_boxes_preferences() { | |
| <?php | ||
| } | ||
|
|
||
| /** | ||
| * Renders the option to enable or disable meta box reordering. | ||
| * | ||
| * @since 7.1.0 | ||
| */ | ||
| public function render_meta_box_reordering_options() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be dead/unused now. Along with the corresponding test. |
||
| if ( ! $this->show_meta_box_reordering_options() ) { | ||
| return; | ||
| } | ||
|
|
||
| ?> | ||
| <fieldset class="metabox-prefs additional-settings-prefs"> | ||
| <legend><?php _e( 'Additional settings' ); ?></legend> | ||
| <?php echo $this->get_meta_box_reordering_option(); ?> | ||
| </fieldset> | ||
| <?php | ||
| } | ||
|
|
||
| /** | ||
| * Gets the option to enable or disable meta box reordering. | ||
| * | ||
| * @since 7.1.0 | ||
| * | ||
| * @return string Meta box reordering option markup. | ||
| */ | ||
| private function get_meta_box_reordering_option() { | ||
| return '<label for="meta-box-reordering">' | ||
| . '<input class="meta-box-reordering-toggle" name="meta-box-reordering" type="checkbox" id="meta-box-reordering" value="enabled" ' . checked( wp_is_meta_box_reordering_enabled(), true, false ) . ' /> ' | ||
| . __( 'Enable box reordering' ) | ||
| . '</label>'; | ||
| } | ||
|
|
||
| /** | ||
| * Determines whether to show the meta box reordering option. | ||
| * | ||
| * @since 7.1.0 | ||
| * | ||
| * @global array $wp_meta_boxes Global meta box state. | ||
| * | ||
| * @return bool Whether to show the option. | ||
| */ | ||
| private function show_meta_box_reordering_options() { | ||
| global $wp_meta_boxes; | ||
|
|
||
| return ! empty( $wp_meta_boxes[ $this->id ] ); | ||
| } | ||
|
|
||
| /** | ||
| * Renders the list table columns preferences. | ||
| * | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new checkbox lives inside
#screen-options-wrap, so the existing$('#screen-options-wrap input').on('click', maybeDisableSortables)binding (in common.js) and the.meta-box-reordering-togglehandler both fire on the same click, andsetMetaBoxReordering()callsmaybeDisableSortables()a third time. Sounds like it may need tidying up a bit.