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

Metaboxes added on the admin_head hook are not added to the post edit page #3165

Closed
kmgalanakis opened this issue Oct 26, 2017 · 9 comments
Closed
Labels
[Feature] Meta Boxes A draggable box shown on the post editing screen [Status] Needs More Info Follow-up required in order to be actionable.

Comments

@kmgalanakis
Copy link

kmgalanakis commented Oct 26, 2017

When registering a metabox to be added in the admin_head hook, the metabox doesn't appear on the Post edit page as it does for the Page edit page.

For the case of the Page edit page, the gutenberg_meta_box_partial_page_admin_header method is called which does again the admin_head action. I think we need something similar for the Post edit page too.

The strange thing is that when creating a new post, the metaboxes are there. After debugging this a bit, I saw that when creating a new post, the global $post post type is revision, the revision of the currently edited post, while when creating a post the post type from the global $post is post. Based on this behavior, for the Post edit page, the metabox is registered for the revision post type, while for the New Post page, the metabox is registered for the post post type.

Test code:

add_action( 'admin_head', 'my_meta_box' );

function my_meta_box() {
	global $post;
	add_meta_box( 
		'my_meta_box', 
		__( 'My metabox', 'my-context' ), 
		'my_meta_box_callback', 
		$post->post_type, 'side' 
	);
}

function my_meta_box_callback() {
    echo '<p>Lorem ipsum dolor sit amet.</p>';
}
@kevinwhoffman
Copy link
Contributor

This likely explains why ACF meta boxes with a High position do not show up in Gutenberg.

image

@BE-Webdesign
Copy link
Contributor

This is definitely fixable. I had code that solved it but I believe I chopped it out on a rebase. Thank you for the report!

@BE-Webdesign BE-Webdesign added the [Feature] Meta Boxes A draggable box shown on the post editing screen label Nov 2, 2017
@kevinwhoffman
Copy link
Contributor

@BE-Webdesign Would this by chance require adding a third iframe?

@BE-Webdesign
Copy link
Contributor

Would this by chance require adding a third iframe?

For your use case yes, but for the topic of this issue, no.

If I understand the issue topic correctly, meta boxes are not being registered correctly as plugins who register on admin_head, since they are relying the global $post variable which is currently being set to revision. All that needs to be done is to fake the globals, so that these plugins correctly register and then we switch the globals back to what they were.

@kevinwhoffman
Copy link
Contributor

Based on my performance tests in #3304 (comment), it would be ill-advised to add yet another iframe if that means enqueuing a fourth set of plugin assets on the page. I understand that may "fix" the original issue, but I don't think it benefits us to knowingly commit solutions that don't belong in the final product based on the performance concerns and additional limitations of iframes.

@aduth
Copy link
Member

aduth commented Mar 1, 2018

Is this issue still relevant?

@aduth aduth added the [Status] Needs More Info Follow-up required in order to be actionable. label Mar 1, 2018
@BE-Webdesign
Copy link
Contributor

This is still relevant in some cases. I am carving out time to work on Meta Boxes this weekend.

@kmgalanakis
Copy link
Author

@aduth this issue is not reproducible for me anymore. The test metabox I gave on the issue description is properly displayed everywhere.

@BE-Webdesign what are those cases you are referring to? Clearly out of curiosity.

@mtias
Copy link
Member

mtias commented Mar 6, 2018

Closing, but feel free to reopen.

@mtias mtias closed this as completed Mar 6, 2018
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 [Status] Needs More Info Follow-up required in order to be actionable.
Projects
None yet
Development

No branches or pull requests

5 participants