Closed johnbillion closed 6 years ago
The underlying cause is that the gutenberg_collect_meta_box_data()
function (which fires the dbx_post_advanced
hook, among several others) fires on the admin_head
action, which is too late.
Do you have a workaround, such as hooking into gutenberg_can_edit_post_type
?
See also https://github.com/WordPress/gutenberg/issues/1316
I don't have a workaround yet but I'm looking into it.
I believe that the following is a workaround for this particular issue, but it's not been extensively tested. If anyone else has the same issue, feedback would be welcome.
add_action( 'admin_enqueue_scripts', function() {
do_action( 'dbx_post_advanced', $GLOBALS['post'] );
remove_all_actions( 'dbx_post_advanced' );
}, -999 );
The underlying cause is that the gutenberg_collect_meta_box_data() function (which fires the dbx_post_advanced hook, among several others) fires on the admin_head action, which is too late.
If it doesn't fire on admin_head
it is too early for other meta box plugins, like ACF. For whatever reason a significant amount of ACF registrations happen on admin_head
. I can look into this at some point, and fix it up for CMB. Don't have any bandwidth currently.
From https://github.com/WordPress/gutenberg/issues/7000#issuecomment-398067899
NB: According to this comment, it looks like metaboxes are added "as soon as possible". I don't know why it cannot be done as soon as in the classic editor but worry that changing the order of two of the most widely used actions (See hooks usage statistics) could introduce other various backward compatibility issues in the ecosystem.
I think we may need to revert back to the existing order and have ACF include some form of compatibility shim.
@jsternberg Hi! Hope you don't mind the ping. Are you aware if this issue affects CMB2?
Hi, I think you might have pinged the wrong person. I do not know what the acronym CMB2 stands for so I'm unlikely to know if this issue affects it.
Sorry! @jtsternberg is who I was after :-)
👋Looks like I'm too late as #10660 has resolved it. Sorry I missed the ping.
Issue Overview
The way in which Gutenberg loads meta boxes causes it to trigger core actions in the incorrect order on the post editing screen. One problem that this causes is to break meta boxes which are registered with the CMB library because the
admin_enqueue_scripts
action fires before the fields are registered, causing JavaScript files to not get enqueued.Steps to Reproduce (for bugs)
dbx_post_advanced
action fires before theadmin_enqueue_scripts
hook.Expected Behavior
The
dbx_post_advanced
hook fires before theadmin_enqueue_scripts
hook.Current Behavior
The
admin_enqueue_scripts
hook fires before thedbx_post_advanced
hook./cc @mikeselander @mattheu