-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Plugin: Deprecate metabox supports, fall back to core #13449
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -721,72 +721,26 @@ function gutenberg_prepare_blocks_for_js() { | |
* are loaded last. | ||
* | ||
* @since 0.4.0 | ||
* @deprecated 5.0.0 wp_common_block_scripts_and_styles | ||
*/ | ||
function gutenberg_common_scripts_and_styles() { | ||
if ( ! is_gutenberg_page() && is_admin() ) { | ||
return; | ||
} | ||
|
||
// Enqueue basic styles built out of Gutenberg through `npm build`. | ||
wp_enqueue_style( 'wp-block-library' ); | ||
|
||
/* | ||
* Enqueue block styles built through plugins. This lives in a separate | ||
* action for a couple of reasons: (1) we want to load these assets | ||
* (usually stylesheets) in *both* frontend and editor contexts, and (2) | ||
* one day we may need to be smarter about whether assets are included | ||
* based on whether blocks are actually present on the page. | ||
*/ | ||
_deprecated_function( __FUNCTION__, '5.0.0', 'wp_common_block_scripts_and_styles' ); | ||
|
||
/** | ||
* Fires after enqueuing block assets for both editor and front-end. | ||
* | ||
* Call `add_action` on any hook before 'wp_enqueue_scripts'. | ||
* | ||
* In the function call you supply, simply use `wp_enqueue_script` and | ||
* `wp_enqueue_style` to add your functionality to the Gutenberg editor. | ||
* | ||
* @since 0.4.0 | ||
*/ | ||
do_action( 'enqueue_block_assets' ); | ||
wp_common_block_scripts_and_styles(); | ||
} | ||
add_action( 'wp_enqueue_scripts', 'gutenberg_common_scripts_and_styles' ); | ||
add_action( 'admin_enqueue_scripts', 'gutenberg_common_scripts_and_styles' ); | ||
|
||
/** | ||
* Enqueues registered block scripts and styles, depending on current rendered | ||
* context (only enqueuing editor scripts while in context of the editor). | ||
* | ||
* @since 2.0.0 | ||
* @deprecated 5.0.0 wp_enqueue_registered_block_scripts_and_styles | ||
*/ | ||
function gutenberg_enqueue_registered_block_scripts_and_styles() { | ||
$is_editor = ( 'enqueue_block_editor_assets' === current_action() ); | ||
_deprecated_function( __FUNCTION__, '5.0.0', 'wp_enqueue_registered_block_scripts_and_styles' ); | ||
|
||
$block_registry = WP_Block_Type_Registry::get_instance(); | ||
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { | ||
// Front-end styles. | ||
if ( ! empty( $block_type->style ) ) { | ||
wp_enqueue_style( $block_type->style ); | ||
} | ||
|
||
// Front-end script. | ||
if ( ! empty( $block_type->script ) ) { | ||
wp_enqueue_script( $block_type->script ); | ||
} | ||
|
||
// Editor styles. | ||
if ( $is_editor && ! empty( $block_type->editor_style ) ) { | ||
wp_enqueue_style( $block_type->editor_style ); | ||
} | ||
|
||
// Editor script. | ||
if ( $is_editor && ! empty( $block_type->editor_script ) ) { | ||
wp_enqueue_script( $block_type->editor_script ); | ||
} | ||
} | ||
wp_enqueue_registered_block_scripts_and_styles(); | ||
} | ||
add_action( 'enqueue_block_assets', 'gutenberg_enqueue_registered_block_scripts_and_styles' ); | ||
add_action( 'enqueue_block_editor_assets', 'gutenberg_enqueue_registered_block_scripts_and_styles' ); | ||
|
||
/** | ||
* Assigns a default editor template with a default block by post format, if | ||
|
@@ -1074,10 +1028,10 @@ function gutenberg_editor_scripts_and_styles( $hook ) { | |
$meta_box_url = admin_url( 'post.php' ); | ||
$meta_box_url = add_query_arg( | ||
array( | ||
'post' => $post->ID, | ||
'action' => 'edit', | ||
'classic-editor' => true, | ||
'meta_box' => true, | ||
'post' => $post->ID, | ||
'action' => 'edit', | ||
'meta-box-loader' => true, | ||
'_wpnonce' => wp_create_nonce( 'meta-box-loader' ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this to match the URL used in Core? Do you think we could remove bootstraping Gutenberg entirely in the plugin (and just upgrade the scripts) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes, in fact, what I've done here is simply to align the bootstrapping to exactly what core does, in order to facilitate it being dropped altogether. |
||
), | ||
$meta_box_url | ||
); | ||
|
@@ -1277,7 +1231,7 @@ function gutenberg_editor_scripts_and_styles( $hook ) { | |
|
||
$init_script = <<<JS | ||
( function() { | ||
window._wpLoadGutenbergEditor = new Promise( function( resolve ) { | ||
window._wpLoadGutenbergEditor = window._wpLoadBlockEditor = new Promise( function( resolve ) { | ||
wp.domReady( function() { | ||
resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, %s, %s ) ); | ||
} ); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw a comment on the description, but still having hard time understanding this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It mimics similar to what's done here:
https://github.com/WordPress/wordpress-develop/blob/8b4330bb6ea196005b5f0f84070b64c139f39b37/src/wp-admin/edit-form-blocks.php#L26-L28
It's important because there are conditions in core's handling of meta boxes which key off this value:
Without this, the the value of
is_block_editor
is false on the Gutenberg screen, which is clearly problematic irrespective of the specific meta box integration. For example, it forces plugin authors to do funny things to check whether the current screen is the block editor, regardless of whether that's the one in core or the one in the Gutenberg plugin.https://github.com/aduth/g-debugger/blob/522d88a56f7e389f741edc48220a9750d78b80fd/g-debugger.php#L13-L32
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a clarifying comment in the rebased 4f62c93.