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

Plugin: Deprecate metabox supports, fall back to core #13449

Merged
merged 2 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ The Gutenberg project's deprecation policy is intended to support backward compa
- The PHP function `gutenberg_check_if_classic_needs_warning_about_blocks` has been removed.
- The PHP function `gutenberg_warn_classic_about_blocks` has been removed.
- The PHP function `gutenberg_show_privacy_policy_help_text` has been removed.
- The PHP function `gutenberg_common_scripts_and_styles` has been removed. Use [`wp_common_block_scripts_and_styles`](https://developer.wordpress.org/reference/functions/wp_common_block_scripts_and_styles/) instead.
- The PHP function `gutenberg_enqueue_registered_block_scripts_and_styles` has been removed. Use [`wp_enqueue_registered_block_scripts_and_styles`](https://developer.wordpress.org/reference/functions/wp_enqueue_registered_block_scripts_and_styles/) instead.
- The PHP function `gutenberg_meta_box_save` has been removed.
- The PHP function `gutenberg_meta_box_save_redirect` has been removed.
- The PHP function `gutenberg_filter_meta_boxes` has been removed.
- The PHP function `gutenberg_intercept_meta_box_render` has been removed.
- The PHP function `gutenberg_override_meta_box_callback` has been removed.
- The PHP function `gutenberg_show_meta_box_warning` has been removed.
- The PHP function `the_gutenberg_metaboxes` has been removed. Use [`the_block_editor_meta_boxes`](https://developer.wordpress.org/reference/functions/the_block_editor_meta_boxes/) instead.
- The PHP function `gutenberg_meta_box_post_form_hidden_fields` has been removed. Use [`the_block_editor_meta_box_post_form_hidden_fields`](https://developer.wordpress.org/reference/functions/the_block_editor_meta_box_post_form_hidden_fields/) instead.
- The PHP function `gutenberg_toggle_custom_fields` has been removed.
- The PHP function `gutenberg_collect_meta_box_data` has been removed. Use [`register_and_do_post_meta_boxes`](https://developer.wordpress.org/reference/functions/register_and_do_post_meta_boxes/) instead.

## 4.5.0
- `Dropdown.refresh()` has been deprecated as the contained `Popover` is now automatically refreshed.
Expand Down
15 changes: 12 additions & 3 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ function the_gutenberg_project() {
<div class="block-editor gutenberg">
<h1 class="screen-reader-text"><?php echo esc_html( $post_type_object->labels->edit_item ); ?></h1>
<div id="editor" class="block-editor__container gutenberg__editor"></div>
<div id="metaboxes" style="display: none;">
<?php the_gutenberg_metaboxes(); ?>
<div id="metaboxes" class="hidden">
<?php the_block_editor_meta_boxes(); ?>
</div>
</div>
<?php
Expand Down Expand Up @@ -211,6 +211,15 @@ function gutenberg_init( $return, $post ) {
return false;
}

// Instruct WordPress that this is the block editor. Without this, a call
// to `is_block_editor()` would yield `false` while editing a post with
// Gutenberg.
//
// [TODO]: This is temporary so long as Gutenberg is implemented to use
// `replace_editor`, rather than allow `edit-form-blocks.php` from core to
// take effect, where this would otherwise be assigned.
get_current_screen()->is_block_editor( true );
Copy link
Contributor

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 :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

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.


add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' );
add_filter( 'screen_options_show_screen', '__return_false' );
add_filter( 'admin_body_class', 'gutenberg_add_admin_body_class' );
Expand All @@ -237,7 +246,7 @@ function gutenberg_init( $return, $post ) {
* includes/meta-boxes is typically loaded from edit-form-advanced.php.
*/
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
gutenberg_collect_meta_box_data();
register_and_do_post_meta_boxes( $post );

require_once ABSPATH . 'wp-admin/admin-header.php';
the_gutenberg_project();
Expand Down
68 changes: 11 additions & 57 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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' ),
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we could remove bootstraping Gutenberg entirely in the plugin (and just upgrade the scripts)

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.

https://github.com/WordPress/wordpress-develop/blob/8b4330bb6ea196005b5f0f84070b64c139f39b37/src/wp-admin/edit-form-blocks.php#L115-L126

),
$meta_box_url
);
Expand Down Expand Up @@ -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 ) );
} );
Expand Down
Loading