Changeset 64301
- Timestamp:
- 10/11/2026 09:24:39 PM (5 weeks ago)
- Location:
- trunk
- Files:
-
- 1 added
- 11 edited
-
src/js/_enqueues/admin/common.js (modified) (2 diffs)
-
src/js/_enqueues/admin/postbox.js (modified) (5 diffs)
-
src/wp-admin/admin-ajax.php (modified) (1 diff)
-
src/wp-admin/admin-header.php (modified) (1 diff)
-
src/wp-admin/css/common.css (modified) (2 diffs)
-
src/wp-admin/css/dashboard.css (modified) (1 diff)
-
src/wp-admin/includes/ajax-actions.php (modified) (1 diff)
-
src/wp-admin/includes/class-wp-screen.php (modified) (3 diffs)
-
src/wp-admin/includes/screen.php (modified) (1 diff)
-
tests/phpunit/includes/testcase-ajax.php (modified) (1 diff)
-
tests/phpunit/tests/admin/includesScreen.php (modified) (1 diff)
-
tests/phpunit/tests/ajax/wpAjaxMetaBoxReordering.php (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/js/_enqueues/admin/common.js
r64282 r64301 1859 1859 1860 1860 // When the screen columns are changed, potentially disable sortables. 1861 $( '#screen-options-wrap input ' ).on( 'click', this.maybeDisableSortables );1861 $( '#screen-options-wrap input:not(.meta-box-reordering-toggle)' ).on( 'click', this.maybeDisableSortables ); 1862 1862 }, 1863 1863 … … 1873 1873 1874 1874 if ( 1875 $body.hasClass( 'meta-box-reordering-disabled' ) || 1875 1876 ( width <= 782 ) || 1876 1877 ( 1 >= $sortables.find( '.ui-sortable-handle:visible' ).length && jQuery( '.columns-prefs-1 input' ).prop( 'checked' ) ) -
trunk/src/js/_enqueues/admin/postbox.js
r63600 r64301 105 105 firstOrLastPositionMessage; 106 106 107 if ( ! postboxes.metaBoxReorderingEnabled ) { 108 return; 109 } 110 107 111 if ( 'dashboard_browser_nag' === postboxId ) { 108 112 return; … … 345 349 } 346 350 }); 351 352 $( '.meta-box-reordering-toggle' ).on( 'click.postboxes', function() { 353 var enabled = $( this ).prop( 'checked' ); 354 355 postboxes.setMetaBoxReordering( enabled ); 356 postboxes.save_meta_box_reordering_state( enabled ); 357 } ); 347 358 }, 348 359 … … 420 431 }); 421 432 433 this.setMetaBoxReordering( this.isMetaBoxReorderingEnabled() ); 434 422 435 if ( isMobile ) { 423 436 $(document.body).on('orientationchange.postboxes', function(){ postboxes._pb_change(); }); … … 436 449 $el.attr( 'aria-expanded', ! $el.closest( '.postbox' ).hasClass( 'closed' ) ); 437 450 }); 451 }, 452 453 /** 454 * Checks whether meta box reordering is enabled. 455 * 456 * @since 7.2.0 457 * 458 * @return {boolean} Whether meta box reordering is enabled. 459 */ 460 isMetaBoxReorderingEnabled: function() { 461 var $toggle = $( '#meta-box-reordering' ); 462 463 if ( $toggle.length ) { 464 return $toggle.prop( 'checked' ); 465 } 466 467 return ! $( document.body ).hasClass( 'meta-box-reordering-disabled' ); 468 }, 469 470 /** 471 * Enables or disables the meta box reordering UI. 472 * 473 * @since 7.2.0 474 * 475 * @param {boolean} enabled Whether reordering should be enabled. 476 * @return {void} 477 */ 478 setMetaBoxReordering: function( enabled ) { 479 var $sortables = $( '.meta-box-sortables' ); 480 481 this.metaBoxReorderingEnabled = enabled; 482 483 $( document.body ).toggleClass( 'meta-box-reordering-disabled', ! this.metaBoxReorderingEnabled ); 484 485 if ( window.wpResponsive && window.wpResponsive.maybeDisableSortables ) { 486 window.wpResponsive.maybeDisableSortables(); 487 return; 488 } 489 490 if ( $sortables.hasClass( 'ui-sortable' ) ) { 491 $sortables 492 .sortable( this.metaBoxReorderingEnabled ? 'enable' : 'disable' ) 493 .find( '.ui-sortable-handle' ) 494 .toggleClass( 'is-non-sortable', ! this.metaBoxReorderingEnabled ); 495 } 438 496 }, 439 497 … … 473 531 function() { 474 532 wp.a11y.speak( __( 'Screen Options updated.' ) ); 533 } 534 ); 535 }, 536 537 /** 538 * Saves the meta box reordering setting to the server. 539 * 540 * @since 7.2.0 541 * 542 * @param {boolean} enabled Whether meta box reordering is enabled. 543 * @return {void} 544 */ 545 save_meta_box_reordering_state: function( enabled ) { 546 $.post( 547 ajaxurl, 548 { 549 action: 'meta-box-reordering', 550 enabled: enabled ? 1 : 0, 551 screenoptionnonce: $( '#screenoptionnonce' ).val() 552 }, 553 function() { 554 wp.a11y.speak( 555 enabled ? 556 __( 'Rearranging screen elements enabled.' ) : 557 __( 'Rearranging screen elements disabled.' ) 558 ); 475 559 } 476 560 ); -
trunk/src/wp-admin/admin-ajax.php
r58672 r64301 80 80 'closed-postboxes', 81 81 'hidden-columns', 82 'meta-box-reordering', 82 83 'update-welcome-panel', 83 84 'menu-get-metabox', -
trunk/src/wp-admin/admin-header.php
r64120 r64301 246 246 } 247 247 248 if ( ! wp_is_meta_box_reordering_enabled() ) { 249 $admin_body_class .= ' meta-box-reordering-disabled'; 250 } 251 248 252 $admin_body_class .= ' wp-theme-' . sanitize_html_class( get_template() ); 249 253 if ( is_child_theme() ) { -
trunk/src/wp-admin/css/common.css
r64229 r64301 1991 1991 } 1992 1992 1993 .additional-settings-prefs { 1994 margin-top: 14px; 1995 } 1996 1993 1997 /* This ID appears to be unused in Core. */ 1994 1998 #number-of-columns { … … 2285 2289 color: #646970; 2286 2290 width: 1.62rem; 2291 } 2292 2293 .js.meta-box-reordering-disabled .postbox .handle-order-higher, 2294 .js.meta-box-reordering-disabled .postbox .handle-order-lower { 2295 display: none; 2287 2296 } 2288 2297 -
trunk/src/wp-admin/css/dashboard.css
r63969 r64301 1380 1380 } 1381 1381 1382 .js.meta-box-reordering-disabled #dashboard-widgets .postbox-container .empty-container { 1383 display: none; 1384 } 1385 1382 1386 @media screen and (max-width: 870px) { 1383 1387 /* @deprecated 5.9.0 -- Lists removed from welcome panel. */ -
trunk/src/wp-admin/includes/ajax-actions.php
r63959 r64301 1876 1876 1877 1877 /** 1878 * Handles the meta box reordering setting via Ajax. 1879 * 1880 * @since 7.2.0 1881 */ 1882 function wp_ajax_meta_box_reordering() { 1883 check_ajax_referer( 'screen-options-nonce', 'screenoptionnonce' ); 1884 1885 $enabled = isset( $_POST['enabled'] ) && '1' === (string) $_POST['enabled']; 1886 update_user_option( get_current_user_id(), 'meta_box_reordering', $enabled ? 'enabled' : 'disabled' ); 1887 1888 wp_die( 1 ); 1889 } 1890 1891 /** 1878 1892 * Handles updating whether to display the welcome panel via AJAX. 1879 1893 * -
trunk/src/wp-admin/includes/class-wp-screen.php
r63648 r64301 1007 1007 $this->_screen_settings = ''; 1008 1008 1009 $additional_settings = ''; 1010 $has_meta_boxes = $this->has_meta_boxes(); 1011 1012 if ( $has_meta_boxes ) { 1013 $additional_settings .= $this->get_meta_box_reordering_option(); 1014 } 1015 1009 1016 if ( 'post' === $this->base ) { 1010 $expand = '<fieldset class="editor-expand hidden"><legend>' . __( 'Additional settings' ) . '</legend><label for="editor-expand-toggle">'; 1011 $expand .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />'; 1012 $expand .= __( 'Enable full-height editor and distraction-free functionality.' ) . '</label></fieldset>'; 1013 $this->_screen_settings = $expand; 1017 $additional_settings .= '<span class="editor-expand hidden">'; 1018 $additional_settings .= '<input type="checkbox" id="editor-expand-toggle"' . checked( get_user_setting( 'editor_expand', 'on' ), 'on', false ) . ' />'; 1019 $additional_settings .= '<label for="editor-expand-toggle">' . __( 'Enable full-height editor and distraction-free functionality.' ) . '</label>'; 1020 $additional_settings .= '</span>'; 1021 } 1022 1023 if ( $additional_settings ) { 1024 $fieldset_class = 'metabox-prefs additional-settings-prefs'; 1025 1026 // The editor expand setting is revealed by JavaScript, so keep the fieldset hidden when it is the only setting. 1027 if ( ! $has_meta_boxes ) { 1028 $fieldset_class .= ' editor-expand hidden'; 1029 } 1030 1031 $this->_screen_settings = '<fieldset class="' . $fieldset_class . '">'; 1032 $this->_screen_settings .= '<legend>' . __( 'Additional settings' ) . '</legend>'; 1033 $this->_screen_settings .= $additional_settings; 1034 $this->_screen_settings .= '</fieldset>'; 1014 1035 } 1015 1036 … … 1123 1144 <?php _e( 'Some screen elements can be shown or hidden by using the checkboxes.' ); ?> 1124 1145 <?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.' ); ?> 1146 <?php if ( $this->has_meta_boxes() ) : ?> 1147 <?php _e( 'Use the setting below to control whether screen elements can be rearranged.' ); ?> 1148 <?php endif; ?> 1125 1149 </p> 1126 1150 <div class="metabox-prefs-container"> … … 1147 1171 </fieldset> 1148 1172 <?php 1173 } 1174 1175 /** 1176 * Gets the option to enable or disable meta box reordering. 1177 * 1178 * @since 7.2.0 1179 * 1180 * @return string Meta box reordering option markup. 1181 */ 1182 private function get_meta_box_reordering_option() { 1183 return '<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 ) . ' />' 1184 . '<label for="meta-box-reordering">' . __( 'Allow screen elements to be rearranged' ) . '</label>'; 1185 } 1186 1187 /** 1188 * Checks whether the screen has meta boxes. 1189 * 1190 * @since 7.2.0 1191 * 1192 * @global array $wp_meta_boxes Global meta box state. 1193 * 1194 * @return bool Whether the screen has meta boxes. 1195 */ 1196 private function has_meta_boxes() { 1197 global $wp_meta_boxes; 1198 1199 return ! empty( $wp_meta_boxes[ $this->id ] ); 1149 1200 } 1150 1201 -
trunk/src/wp-admin/includes/screen.php
r61484 r64301 196 196 197 197 /** 198 * Determines whether meta box reordering is enabled. 199 * 200 * @since 7.2.0 201 * 202 * @return bool Whether meta box reordering is enabled. 203 */ 204 function wp_is_meta_box_reordering_enabled() { 205 $setting = get_user_option( 'meta_box_reordering' ); 206 207 return false === $setting ? true : 'disabled' !== $setting; 208 } 209 210 /** 198 211 * Register and configure an admin screen option 199 212 * -
trunk/tests/phpunit/includes/testcase-ajax.php
r63593 r64301 67 67 'closed-postboxes', 68 68 'hidden-columns', 69 'meta-box-reordering', 69 70 'update-welcome-panel', 70 71 'menu-get-metabox', -
trunk/tests/phpunit/tests/admin/includesScreen.php
r61484 r64301 261 261 } 262 262 263 public function test_meta_box_reordering_enabled_defaults_to_true() { 264 wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); 265 266 $this->assertTrue( wp_is_meta_box_reordering_enabled() ); 267 } 268 269 public function test_meta_box_reordering_enabled_respects_user_option() { 270 $user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); 271 wp_set_current_user( $user_id ); 272 update_user_option( $user_id, 'meta_box_reordering', 'disabled' ); 273 274 $this->assertFalse( wp_is_meta_box_reordering_enabled() ); 275 } 276 277 public function test_meta_box_reordering_option_is_rendered_for_screens_with_meta_boxes() { 278 global $wp_meta_boxes; 279 280 $old_wp_meta_boxes = $wp_meta_boxes; 281 set_current_screen( 'index.php' ); 282 $screen = get_current_screen(); 283 284 add_meta_box( 'testbox1', 'Test Metabox', '__return_false', $screen ); 285 286 try { 287 $screen->show_screen_options(); 288 289 ob_start(); 290 $screen->render_screen_options(); 291 $output = ob_get_clean(); 292 } finally { 293 $wp_meta_boxes = $old_wp_meta_boxes; 294 } 295 296 $this->assertStringContainsString( 'id="meta-box-reordering"', $output ); 297 $this->assertStringContainsString( 'Additional settings', $output ); 298 $this->assertStringContainsString( '<label for="meta-box-reordering">Allow screen elements to be rearranged</label>', $output ); 299 $this->assertStringContainsString( 'Some screen elements can be shown or hidden by using the checkboxes.', $output ); 300 $this->assertStringContainsString( '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.', $output ); 301 $this->assertStringContainsString( 'Use the setting below to control whether screen elements can be rearranged.', $output ); 302 } 303 304 public function test_meta_box_reordering_and_editor_expand_options_share_additional_settings_fieldset() { 305 global $wp_meta_boxes; 306 307 $old_wp_meta_boxes = $wp_meta_boxes; 308 309 // WP_Screen caches its settings per screen, so use a different post screen than the other tests. 310 set_current_screen( 'page' ); 311 $screen = get_current_screen(); 312 313 add_meta_box( 'testbox1', 'Test Metabox', '__return_false', $screen ); 314 315 try { 316 $screen->show_screen_options(); 317 318 ob_start(); 319 $screen->render_screen_options(); 320 $output = ob_get_clean(); 321 } finally { 322 $wp_meta_boxes = $old_wp_meta_boxes; 323 } 324 325 $this->assertSame( 1, substr_count( $output, '<legend>Additional settings</legend>' ) ); 326 $this->assertStringContainsString( '<fieldset class="metabox-prefs additional-settings-prefs">', $output ); 327 $this->assertStringContainsString( '<label for="meta-box-reordering">Allow screen elements to be rearranged</label>', $output ); 328 $this->assertStringContainsString( '<label for="editor-expand-toggle">Enable full-height editor and distraction-free functionality.</label>', $output ); 329 } 330 331 public function test_meta_box_reordering_option_is_not_rendered_for_screens_without_meta_boxes() { 332 global $wp_meta_boxes; 333 334 $old_wp_meta_boxes = $wp_meta_boxes; 335 set_current_screen( 'edit.php' ); 336 $screen = get_current_screen(); 337 338 unset( $wp_meta_boxes[ $screen->id ] ); 339 340 try { 341 $screen->show_screen_options(); 342 343 ob_start(); 344 $screen->render_screen_options(); 345 $output = ob_get_clean(); 346 } finally { 347 $wp_meta_boxes = $old_wp_meta_boxes; 348 } 349 350 $this->assertStringNotContainsString( 'id="meta-box-reordering"', $output ); 351 $this->assertStringNotContainsString( 'Additional settings', $output ); 352 } 353 354 public function test_additional_settings_fieldset_is_hidden_when_editor_expand_is_the_only_option() { 355 global $wp_meta_boxes; 356 357 $old_wp_meta_boxes = $wp_meta_boxes; 358 set_current_screen( 'post.php' ); 359 $screen = get_current_screen(); 360 361 unset( $wp_meta_boxes[ $screen->id ] ); 362 363 try { 364 $screen->show_screen_options(); 365 366 ob_start(); 367 $screen->render_screen_options(); 368 $output = ob_get_clean(); 369 } finally { 370 $wp_meta_boxes = $old_wp_meta_boxes; 371 } 372 373 $this->assertStringNotContainsString( 'id="meta-box-reordering"', $output ); 374 $this->assertStringContainsString( '<fieldset class="metabox-prefs additional-settings-prefs editor-expand hidden">', $output ); 375 $this->assertStringContainsString( 'Enable full-height editor and distraction-free functionality.', $output ); 376 } 377 263 378 public function test_post_type_with_edit_prefix() { 264 379 register_post_type( 'edit-some-thing' );
Note:
See TracChangeset
for help on using the changeset viewer.