Skip to content
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

Meta Boxes Not Rendered for Block Patterns (wp_block) #67902

Open
3 of 6 tasks
abhi3315 opened this issue Dec 13, 2024 · 5 comments
Open
3 of 6 tasks

Meta Boxes Not Rendered for Block Patterns (wp_block) #67902

abhi3315 opened this issue Dec 13, 2024 · 5 comments
Labels
[Feature] Meta Boxes A draggable box shown on the post editing screen [Type] Bug An existing feature does not function as intended

Comments

@abhi3315
Copy link
Contributor

Description

With the recent WordPress update introducing the Split Content View, meta boxes and the block editor are now separated into distinct areas. However, this update has introduced a critical issue: meta boxes are not displayed for Block Patterns (wp_block).

Although all the registered meta boxes appear in the Preferences list, they are not rendered in the Split Content View (see screenshot below).

Image

This issue is particularly impactful for plugins like MultilingualPress, which rely on meta boxes to manage translations for custom post types (e.g., translating block patterns into different locales). The absence of meta boxes makes it impossible to translate block patterns effectively.

Step-by-step reproduction instructions

  1. Register a custom meta box using the sample code below:
/**
 * Register meta box(es).
 */
function wpdocs_register_meta_boxes() {
	add_meta_box( 'meta-box-id', __( 'My Meta Box', 'textdomain' ), 'wpdocs_my_display_callback' );
}
add_action( 'add_meta_boxes', 'wpdocs_register_meta_boxes' );

/**
 * Meta box display callback.
 *
 * @param WP_Post $post Current post object.
 */
function wpdocs_my_display_callback( $post ) {
	echo 'Hello World';
}
  1. Navigate to the Block Patterns (wp_block) section in the WordPress admin.
  2. Check for the custom meta box registered in Step 1.

Screenshots, screen recording, code snippet

No response

Environment info

  • WP Version: 6.7.1
  • Gutenberg Version: 18.6-19.3

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@abhi3315 abhi3315 added the [Type] Bug An existing feature does not function as intended label Dec 13, 2024
@Mamaduka Mamaduka added the [Feature] Meta Boxes A draggable box shown on the post editing screen label Dec 13, 2024
@Mamaduka
Copy link
Member

I believe this is intentional. The Synced Patterns don't support meta boxes.

@t-hamano, @stokesman, can you confirm this?

@t-hamano
Copy link
Contributor

I believe this is intentional. The Synced Patterns don't support meta boxes.

That's right. We can edit a pattern by selecting a synced pattern in the post editor and clicking "Edit original". However, the meta boxes displayed there are tied to the original post, which can be confusing.

However, if we're directly editing a pattern as a custom post, we may need to render the meta boxes.

Just to be safe, I'll move this issue to the 6.7.x project board.

@stokesman
Copy link
Contributor

This was changed in #64990 to fix #64914 (and it’s not dependent on the split view).

However, if we're directly editing a pattern as a custom post, we may need to render the meta boxes.

I think so. Further, even if it’s edited through "Edit original" if it’s possible to show only meta boxes tied to the focused post type that would seem nice to have.

@t-hamano
Copy link
Contributor

A quick fix to make the metabox visible when editing the pattern directly:

Details
diff --git a/packages/edit-post/src/components/layout/index.js b/packages/edit-post/src/components/layout/index.js
index b0a2b3f7d7..667fcb0de7 100644
--- a/packages/edit-post/src/components/layout/index.js
+++ b/packages/edit-post/src/components/layout/index.js
@@ -405,6 +405,9 @@ function Layout( {
                        const isRenderingPostOnly = getRenderingMode() === 'post-only';
                        const isNotDesignPostType =
                                ! DESIGN_POST_TYPES.includes( currentPostType );
+                       const isDirectlyEditingPattern =
+                               currentPostType === 'wp_block' &&
+                               ! onNavigateToPreviousEntityRecord;
 
                        return {
                                mode: getEditorMode(),
@@ -415,7 +418,9 @@ function Layout( {
                                        !! select( blockEditorStore ).getBlockSelectionStart(),
                                showIconLabels: get( 'core', 'showIconLabels' ),
                                isDistractionFree: get( 'core', 'distractionFree' ),
-                               showMetaBoxes: isNotDesignPostType && ! isZoomOut(),
+                               showMetaBoxes:
+                                       ( isNotDesignPostType && ! isZoomOut() ) ||
+                                       isDirectlyEditingPattern,
                                isWelcomeGuideVisible: isFeatureActive( 'welcomeGuide' ),
                                templateId:
                                        supportsTemplateMode &&
@@ -433,6 +438,7 @@ function Layout( {
                        currentPostId,
                        isEditingTemplate,
                        settings.supportsTemplateMode,
+                       onNavigateToPreviousEntityRecord,
                ]
        );
        useMetaBoxInitialization( hasActiveMetaboxes );

even if it’s edited through "Edit original" if it’s possible to show only meta boxes tied to the focused post type that would seem nice to have.

Perhaps we'll have to re-run initializeMetaBoxes()?

@stokesman
Copy link
Contributor

A quick fix to make the metabox visible when editing the pattern directly:

I quickly tested that and works for me.

Perhaps we'll have to re-run initializeMetaBoxes()?

It looks like it would take more than that because the meta boxes that are present are fixed when the editor loads. I guess navigating to directly edit the pattern is the simplest way but seems it should not be done automatically. A button to reload could be shown in the meta box area with some message like "A page reload is required to access any meta boxes for this pattern." However, I don’t think it can be known beforehand whether a pattern has any meta boxes so the button/message may not be applicable.

Otherwise, there would have to be an endpoint that could retrieve meta boxes for a given post type but I suppose that requires patching WP core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Meta Boxes A draggable box shown on the post editing screen [Type] Bug An existing feature does not function as intended
Projects
Development

No branches or pull requests

4 participants