WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 5 weeks ago

#52818 new defect (bug)

Ordering metaboxes broken in WP 5.7

Reported by: terraling Owned by:
Milestone: 5.8.1 Priority: normal
Severity: normal Version: 5.7
Component: Editor Keywords: needs-patch
Focuses: Cc:

Description

Post edit screens with metaboxes allow for drag and drop re-ordering.

This worked up to WordPress 5.6.2, but stopped working in WP 5.7, though it continues to work if you use the Classic Editor to edit posts rather than the block editor.

When re-ordering the metaboxes, an ajax update with the action 'meta-box-order' occurs, and this reports a succesful response both in the working and non-working cases, so it appears as if updating the metabox order works.

But, when the page is reloaded, the metaboxes are displayed in an unchanged order.

For testing you can use the following code to register two dummy metaboxes:

<?php
/**
 * Add two dummy metaboxes to post edit screens
 */
function xyz_init_meta_boxes(){
        add_meta_box(
                'metabox_id_1',
                __( 'Metabox One', 'textdomain' ),
                'xyz_metabox_callback',
                'post',
                'normal',
                'low',
                array( 'foo' => 'One' )
        );

        add_meta_box(
                'metabox_id_2',
                __( 'Metabox Two', 'textdomain' ),
                'xyz_metabox_callback',
                'post',
                'normal',
                'low',
                array( 'foo' => 'Two' )
        );

}
add_action( 'load-post.php', 'xyz_init_meta_boxes' );
add_action( 'load-post-new.php', 'xyz_init_meta_boxes' );

function xyz_metabox_callback( $post, $metabox ) {

        $foo = $metabox['args']['foo'];
        echo "<p>Content of metabox $foo</p>";
}

To reproduce, with WP 5.7 edit a post using the block editor.
Re-order the two metaboxes and update the post.
Reload the page.

Change History (11)

#1 @desrosj
5 months ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to 5.7.1

Hi @terraling,

Welcome to Trac!

I've done some testing and I am able to reproduce the issue you are describing (thanks for the proof of concept code)!

Based on my testing, it seems that the post type is not being included in the request, so $page is empty within wp_ajax_meta_box_order(), causing the meta key to be incorrect (relevant source code). The resulting keys are meta-box-order_ instead of meta-box-order_post, meta-box-order_page, etc.

When the page refreshes, it is unable to find the user's preferred ordering for that post type. I tested with pages, and it seems to happen regardless of post type.

I'm moving this to 5.7.1 to investigate further, but this may require an issue and fix over on the Gutenberg GitHub repository.

#2 @desrosj
5 months ago

Related: #50699.

#3 @peterwilsoncc
4 months ago

Indeed, it looks like this will need an upstream fix in the Gutenberg repo as it was introduced in [50048] according to git bisect which is a package update for Gutenberg/the block editor.

I've logged an issue on GitHub for the editor team but will wait until I hear back before making status changes to this ticket. https://github.com/WordPress/gutenberg/issues/30071

#4 @vladytimy
4 months ago

The page parameter is not included in the AJAX request to the admin-ajax action closed-postboxes either, resulting in not saving the closed status of metaboxes.

Not sure if this needs a separate ticket / issue, since I guess it has the same cause (missing page parameter). I'll open a separate ticket / issue if it's better to keep track of.

Issue brought up on this forum topic by @viliusl. I can replicate the issue on 5.7, not on 5.6.2

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


4 months ago

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


4 months ago

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


4 months ago

#8 @audrasjb
4 months ago

  • Milestone changed from 5.7.1 to 5.7.2

Moving to Milestone 5.7.2 as WordPress 5.7.1 Release Candidate 1 is planned for today.

#9 @dd32
3 months ago

  • Milestone changed from 5.7.2 to 5.7.3

WordPress 5.7.2 has been released, moving open tickets to 5.7.3

#10 @desrosj
5 weeks ago

With 5.8 RC1 due out next week and no 5.7.3 currently planned, I'm going to punt this to the milestone for the next minor release: 5.8.1.

#11 @desrosj
5 weeks ago

  • Milestone changed from 5.7.3 to 5.8.1
Note: See TracTickets for help on using tickets.