Skip to content

Administration: Add box reordering toggle to Screen Options. - #12627

Closed
j111q wants to merge 8 commits into
WordPress:trunkfrom
j111q:agent/meta-box-reordering-toggle
Closed

j111q wants to merge 8 commits into
WordPress:trunkfrom
j111q:agent/meta-box-reordering-toggle

Conversation

@j111q

@j111q j111q commented Jul 21, 2026 •

Copy link
Copy Markdown

Trac ticket: https://core.trac.wordpress.org/ticket/50699

This continues #12180, originally authored by @poligilad-auto. Poli’s original feature commit is preserved in this branch; I’m carrying the existing work and review feedback forward while Poli is away.

Summary

  • Adds a Screen Options setting for enabling or disabling box reordering.
  • Stores the setting as one per-user preference shared across screens on the current site and keeps reordering enabled by default.
  • Disables drag-and-drop sorting and hides the keyboard move controls and drop zones when reordering is disabled.
  • Places the “Allow boxes to be rearranged” checkbox under “Additional settings” on screens that support meta boxes.

Screenshot

Screenshot 2026-07-22 at 1 05 54 PM

Review follow-up

  • Uses the absence of the disabled body class to represent the enabled state.
  • Leaves hidden move controls to CSS instead of changing their accessibility attributes in JavaScript.
  • Preserves the existing Screen Options guidance and adds a separate sentence explaining the new setting.
  • Uses the user option API consistently when saving and reading the per-user, per-site preference.
  • Avoids duplicate sortable updates when the checkbox changes.
  • Preserves the legacy hidden editor-expand fieldset when a post screen has no meta boxes.
  • Replaces the unused rendering helper test with coverage through the real Screen Options rendering path.

Compatibility

  • Reordering remains enabled by default.
  • Existing meta box markup and keyboard controls remain unchanged while reordering is enabled.
  • The preference applies across screens on the current site for each user, matching the direction confirmed on the Trac ticket.

AI assistance

Codex was used to inspect the existing feedback, implement revisions, add tests, and draft this description. I manually verified the user-facing behavior, and the automated checks listed below were run. I do not independently have the technical expertise to validate every code change, so this draft is seeking human developer review before it is considered ready.

Testing

  • npm run test:php -- --filter Tests_Admin_IncludesScreen tests/phpunit/tests/admin/includesScreen.php
  • npm run test:php -- --group ajax --filter Tests_Ajax_wpAjaxMetaBoxReordering
  • npx grunt jshint:core --file=src/js/_enqueues/admin/postbox.js
  • npx grunt jshint:core --file=src/js/_enqueues/admin/common.js
  • PHPCS on all eight touched PHP and PHPUnit files.
  • npm run build:dev
  • git diff --check

Manually verified on the Dashboard that disabling the setting disables drag-and-drop, hides both keyboard move controls, and that re-enabling it restores both interaction methods.

Copilot AI review requested due to automatic review settings July 21, 2026 13:54
@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new Screen Options setting that lets users enable/disable meta box (postbox) reordering across wp-admin screens that support meta boxes. It wires the preference through wp-admin rendering, JS behaviors (drag-and-drop and keyboard move controls), and an authenticated Ajax endpoint, with PHPUnit coverage for both the Ajax persistence and Screen Options rendering.

Changes:

  • Add a “Enable box reordering” checkbox under “Additional settings” in Screen Options when a screen has meta boxes, and display supporting guidance text.
  • Persist the preference as a per-user setting via a new meta-box-reordering Ajax action and apply it via an admin body class.
  • Update admin JS/CSS to disable sortable behavior and hide keyboard move controls/drop zones when reordering is disabled, plus add tests for the new behavior.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/phpunit/tests/ajax/wpAjaxMetaBoxReordering.php Adds Ajax test coverage to verify the user option is saved correctly.
tests/phpunit/tests/admin/includesScreen.php Adds tests for default enabled behavior and Screen Options rendering logic.
tests/phpunit/includes/testcase-ajax.php Whitelists the new Ajax action for the Ajax test harness.
src/wp-admin/includes/screen.php Introduces wp_is_meta_box_reordering_enabled() helper for reading the preference.
src/wp-admin/includes/class-wp-screen.php Renders the new Screen Options toggle and related guidance; adjusts “Additional settings” markup handling.
src/wp-admin/includes/ajax-actions.php Adds wp_ajax_meta_box_reordering() endpoint to store the preference.
src/wp-admin/css/dashboard.css Hides dashboard empty drop containers when reordering is disabled.
src/wp-admin/css/common.css Adds styling for additional settings fieldset and hides move controls when reordering is disabled.
src/wp-admin/admin-header.php Applies meta-box-reordering-disabled body class based on the preference.
src/wp-admin/admin-ajax.php Registers meta-box-reordering as a core POST Ajax action.
src/js/_enqueues/admin/postbox.js Adds UI logic to enable/disable reordering, persist state, and gate keyboard move behavior.
src/js/_enqueues/admin/common.js Prevents responsive sortable toggling from being triggered by the new checkbox; disables sortables when reordering is disabled.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/wp-admin/includes/ajax-actions.php
Comment thread src/js/_enqueues/admin/postbox.js
Copilot AI review requested due to automatic review settings July 22, 2026 05:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.

Comment thread src/wp-admin/includes/ajax-actions.php
Comment thread tests/phpunit/tests/admin/includesScreen.php
@j111q
j111q marked this pull request as ready for review July 22, 2026 05:25
@github-actions

github-actions Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props poligilad, jillq, joedolson, afercia.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@joedolson joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A handful of minor questions/suggestions.

Comment thread src/js/_enqueues/admin/postbox.js Outdated
Comment thread src/wp-admin/css/common.css
Comment thread src/wp-admin/css/common.css Outdated
Comment thread src/wp-admin/includes/class-wp-screen.php
Comment thread src/wp-admin/includes/class-wp-screen.php Outdated
Comment thread src/wp-admin/includes/class-wp-screen.php Outdated
@joedolson

Copy link
Copy Markdown
Contributor

I've pushed fixes to address my review questions.

@afercia afercia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some comments.
I'll also comment on the ticket about the scope of this change.

Comment thread src/js/_enqueues/admin/postbox.js Outdated
/**
* Checks whether meta box reordering is enabled.
*
* @since 7.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated to 7.2.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 947e54a.

Comment thread src/js/_enqueues/admin/postbox.js Outdated
/**
* Enables or disables the meta box reordering UI.
*
* @since 7.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated to 7.2.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 947e54a.

Comment thread src/js/_enqueues/admin/postbox.js Outdated
setMetaBoxReordering: function( enabled ) {
var $sortables = $( '.meta-box-sortables' );

this.metaBoxReorderingEnabled = !! enabled;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why coercing to boolean with !!? it is already a booleanand the callers always pass a boolean

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 947e54a.

Comment thread src/js/_enqueues/admin/postbox.js Outdated
/**
* Saves the meta box reordering setting to the server.
*
* @since 7.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update to 7.2.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 947e54a.

Comment thread src/js/_enqueues/admin/postbox.js Outdated
*
* @since 7.1.0
*
* @memberof postboxes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a little redundant

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 947e54a.

/**
* Gets the option to enable or disable meta box reordering.
*
* @since 7.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update to 7.2.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 947e54a.

* @return string Meta box reordering option markup.
*/
private function get_meta_box_reordering_option() {
return '<label for="meta-box-reordering">'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above: this should be refactored to not wrap the input.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored in 947e54a, same as above.

/**
* Determines whether to show the meta box reordering option.
*
* @since 7.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update to 7.2.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 947e54a.

}

/**
* Determines whether to show the meta box reordering option.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the description and name of this method a little confusing. This is not what the code does. it checks whether there are meta boxes for this screen. It does not 'Show' or 'Determine whether to show'.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Renamed to has_meta_boxes() with the description "Checks whether the screen has meta boxes." in 947e54a.

Comment thread src/wp-admin/includes/screen.php Outdated
/**
* Determines whether meta box reordering is enabled.
*
* @since 7.1.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update to 7.2.0

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 947e54a.

@afercia

afercia commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Posting a video recording here, s it exceeds the upload max size for Trac. Comment on the Trac ticket.

Screen.Recording.2026-10-07.at.10.35.06.mov

<?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 if ( $this->show_meta_box_reordering_options() ) : ?>
<?php _e( 'Use the setting below to control whether boxes can be rearranged.' ); ?>

@afercia afercia Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminology: the term 'boxes' is obscure for users. I think we should use 'screen elements' as in the introduction paragraph. When rephrased, the tests should be updated.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, updated to "Use the setting below to control whether screen elements can be rearranged." in 947e54a. Tests updated too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"screen elements" feels like a meaningless set of terms to me, but I do agree that it's at least consistent.

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 ) . ' /> '
. __( 'Allow boxes to be rearranged' )

@afercia afercia Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Terminology: the term 'boxes' is obscure for users. I think we should use 'screen elements' as in the introduction paragraph. When rephrased, the tests should be updated.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, the label is now "Allow screen elements to be rearranged" in 947e54a. Tests updated too.

@afercia

afercia commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Note that some styles added in this commit fb107a4
have been removed in this merge commit: 988dffb not sure that was intentional. In case, I'd restore only the top margin for .additional-settings-prefs, the other ones seem unnecessary to me.

Also, the PR needs to be rebased first as there is a merge conflict related to those styles.

- Update `@since` tags to 7.2.0.
- Always build a single "Additional settings" fieldset, and drop the redundant Screen Options visibility check.
- Use separate `label` and `input` elements instead of wrapping labels.
- Use "screen elements" instead of "boxes" in user-facing text.
- Announce whether rearranging was enabled or disabled.
- Rename `show_meta_box_reordering_options()` to `has_meta_boxes()`.
- Restore the "Additional settings" top margin dropped in a merge, and remove the unneeded paragraph and legend styles.
- Add tests for the shared fieldset and for screens without meta boxes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@poligilad-auto

Copy link
Copy Markdown

@joedolson @afercia, I've addressed your feedback in 947e54a. Could you take another look?

@joedolson

Copy link
Copy Markdown
Contributor

Thanks for the updates, @poligilad-auto!

With these changes, I think this is workable.

@joedolson
joedolson self-requested a review October 10, 2026 02:32

@joedolson joedolson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

wporg-sync pushed a commit that referenced this pull request Oct 11, 2026
In most cases, changing the order and position of dashboard or post meta boxes is an occasional need. When it's not needed, the extra two controls for every meta box create a high number of extra tab stops and a busy design. The drag and drop can result in accidental moves and difficulty scrolling on mobile devices due to accidental touch effects.

Add a screen option that allows users to disable moving meta boxes, disabling mover buttons and drag and drop behavior. The setting is defaulted to enable moving meta boxes, so there is no change in the default experience for users.

Developed in #12627.

Props azaozz, pbiron, afercia, johnbillion, hellofromtonya, helen, knutsp, johnjamesjacoby, garrett-eclipse, margaretschneider, johnstonphilip, hedgefield, sanketparmar, poligilad, sabernhardt, tyxla, jillq, sarahricker, ryokuhi, poena, abrain, SergeyBiryukov, joedolson.
Fixes #50699, #51419.

git-svn-id: https://develop.svn.wordpress.org/trunk@64301 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 64301
GitHub commit: 6718bd3

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Oct 11, 2026
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 11, 2026
In most cases, changing the order and position of dashboard or post meta boxes is an occasional need. When it's not needed, the extra two controls for every meta box create a high number of extra tab stops and a busy design. The drag and drop can result in accidental moves and difficulty scrolling on mobile devices due to accidental touch effects.

Add a screen option that allows users to disable moving meta boxes, disabling mover buttons and drag and drop behavior. The setting is defaulted to enable moving meta boxes, so there is no change in the default experience for users.

Developed in WordPress/wordpress-develop#12627.

Props azaozz, pbiron, afercia, johnbillion, hellofromtonya, helen, knutsp, johnjamesjacoby, garrett-eclipse, margaretschneider, johnstonphilip, hedgefield, sanketparmar, poligilad, sabernhardt, tyxla, jillq, sarahricker, ryokuhi, poena, abrain, SergeyBiryukov, joedolson.
Fixes #50699, #51419.
Built from https://develop.svn.wordpress.org/trunk@64301


git-svn-id: http://core.svn.wordpress.org/trunk@63451 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants