AdvancedCustomFields / AdvancedCustomFields/acf
Gutenberg field groups cannot have their position changed after interacting with them
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
I had a strange issue where no matter how many times I changed the position setting on a field group, the meta box would only appear in the side - it would never move below the content.
After digging deeper I found the following in wp-admin/includex/template.php#1249:
// Grab the ones the user has manually sorted.
// Pull them out of their previous context/priority and into the one the user chose.
$sorted = get_user_option( "meta-box-order_$page" );
if ( ! $already_sorted && $sorted ) {
foreach ( $sorted as $box_context => $ids ) {
foreach ( explode( ',', $ids ) as $id ) {
if ( $id && 'dashboard_browser_nag' !== $id ) {
add_meta_box( $id, null, null, $screen, $box_context, 'sorted' );
}
}
}
}
$already_sorted = true;
This code basically means that if you have published a field group, and have dragged it to change priority at any point, it gets added to the user meta-box-order_$page meta, and this takes precedence over any rules set in ACF as the meta box has already been rendered and removed from the "left to render" list in $wp_meta_boxes.
In my situation, my group was ordered within the side location, so will always be rendered there.
Terrible fix
Duplicating the field group will cause it to be rendered in the correct place as it is a new meta box, not ordered in the user meta.
Better fix
In ACF_Form_Gutenberg::filter_block_editor_meta_boxes ACF performs add_filter( 'get_user_option_meta-box-order_' . $current_screen->id, array($this, 'modify_user_option_meta_box_order') ); but only in certain situations.
I would like to propose that when the position of a field group is changed, any existing "meta-box-order_$page" entries for the related meta box are removed; thus allowing the meta box to move into its new correct position.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ACF_Form_Gutenberg::filter_block_editor_meta_boxes and its modify_user_option_meta_box_order filter, then compare that behavior with the WordPress meta-box ordering code shown in the issue. The change is complete when changing a field group's position no longer leaves its related user meta-box ordering entry forcing the old location, allowing the group to render in its configured position.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php, wordpress
- Domain
- backend, content
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100