Skip to content

Commit

Permalink
Plugin: Remove replace_editor filter, extend core editor (#13569)
Browse files Browse the repository at this point in the history
* Plugin: Remove replace_editor filter, extend core editor

* Plugin: Avoid dynamic dependencies for wp-block-library style

This is handled by core in common blocks style enqueues behavior https://github.com/WordPress/wordpress-develop/blob/e421f26/src/wp-includes/script-loader.php#L2626-L2630

* Testing: Leverage saveDraft for meta boxes save
  • Loading branch information
aduth authored Mar 13, 2019
1 parent cd456f6 commit 67656bc
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 702 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

The Gutenberg project's deprecation policy is intended to support backward compatibility for releases, when possible. The current deprecations are listed below and are grouped by _the version at which they will be removed completely_. If your plugin depends on these behaviors, you must update to the recommended alternative before the noted version.

## 5.5.0

- The PHP function `gutenberg_init` has been removed.
- The PHP function `is_gutenberg_page` has been removed. Use [`WP_Screen::is_block_editor`](https://developer.wordpress.org/reference/classes/wp_screen/is_block_editor/) instead.
- The PHP function `the_gutenberg_project` has been removed.
- The PHP function `gutenberg_default_post_format_template` has been removed.
- The PHP function `gutenberg_get_available_image_sizes` has been removed.
- The PHP function `gutenberg_get_autosave_newer_than_post_save` has been removed.
- The PHP function `gutenberg_default_post_format_template` has been removed.
- The PHP function `gutenberg_editor_scripts_and_styles` has been removed.

## 5.4.0

- The PHP function `gutenberg_load_plugin_textdomain` has been removed.
Expand Down
132 changes: 16 additions & 116 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,11 @@
* The main entry point for the Gutenberg editor. Renders the editor on the
* wp-admin page for the plugin.
*
* The gutenberg and gutenberg__editor classNames are left for backward compatibility.
*
* @since 0.1.0
* @deprecated 5.3.0
*/
function the_gutenberg_project() {
global $post_type_object;
?>
<noscript>
<div class="error" style="position:absolute;top:32px;z-index:40"><p>
<?php
printf(
/* translators: %s: https://wordpress.org/plugins/classic-editor/ */
__( 'The block editor requires JavaScript. Please try the <a href="%s">Classic Editor plugin</a>.', 'gutenberg' ),
__( 'https://wordpress.org/plugins/classic-editor/', 'gutenberg' )
);
?>
</p></div>
</noscript>
<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" class="hidden">
<?php the_block_editor_meta_boxes(); ?>
</div>
<?php
/**
* Start: Include for phase 2
*/
/** This action is documented in wp-admin/admin-footer.php */
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
do_action( 'admin_print_footer_scripts-widgets.php' );

/** This action is documented in wp-admin/admin-footer.php */
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
do_action( 'admin_footer-widgets.php' );
/**
* End: Include for phase 2
*/
?>
</div>
<?php
_deprecated_function( __FUNCTION__, '5.3.0' );
}

/**
Expand All @@ -80,7 +44,7 @@ function gutenberg_menu() {
'Gutenberg',
'edit_posts',
'gutenberg',
'the_gutenberg_project',
'',
'dashicons-edit'
);

Expand Down Expand Up @@ -120,34 +84,16 @@ function gutenberg_menu() {
/**
* Checks whether we're currently loading a Gutenberg page
*
* @return boolean Whether Gutenberg is being loaded.
*
* @since 3.1.0
* @deprecated 5.3.0 WP_Screen::is_block_editor
*
* @return boolean Whether Gutenberg is being loaded.
*/
function is_gutenberg_page() {
global $post;

if ( ! is_admin() ) {
return false;
}

/*
* There have been reports of specialized loading scenarios where `get_current_screen`
* does not exist. In these cases, it is safe to say we are not loading Gutenberg.
*/
if ( ! function_exists( 'get_current_screen' ) ) {
return false;
}

if ( get_current_screen()->base !== 'post' ) {
return false;
}
_deprecated_function( __FUNCTION__, '5.3.0', 'WP_Screen::is_block_editor' );

if ( ! use_block_editor_for_post( $post ) ) {
return false;
}

return true;
require_once ABSPATH . 'wp-admin/includes/screen.php';
return get_current_screen()->is_block_editor();
}

/**
Expand Down Expand Up @@ -198,66 +144,20 @@ function gutenberg_pre_init() {
}

require_once dirname( __FILE__ ) . '/lib/load.php';

add_filter( 'replace_editor', 'gutenberg_init', 10, 2 );
}

/**
* Initialize Gutenberg.
*
* Load API functions, register scripts and actions, etc.
*
* @param bool $return Whether to replace the editor. Used in the `replace_editor` filter.
* @param object $post The post to edit or an auto-draft.
* @return bool Whether Gutenberg was initialized.
* @deprecated 5.3.0
*
* @return bool Whether Gutenberg was initialized.
*/
function gutenberg_init( $return, $post ) {
if ( true === $return && current_filter() === 'replace_editor' ) {
return $return;
}

if ( ! is_gutenberg_page() ) {
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 );

add_action( 'admin_enqueue_scripts', 'gutenberg_editor_scripts_and_styles' );
add_filter( 'screen_options_show_screen', '__return_false' );

/*
* Remove the emoji script as it is incompatible with both React and any
* contenteditable fields.
*/
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );

/**
* Start: Include for phase 2
*/
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
do_action( 'admin_print_styles-widgets.php' );
// phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
do_action( 'admin_print_scripts-widgets.php' );
/**
* End: Include for phase 2
*/

/*
* Ensure meta box functions are available to third-party code;
* includes/meta-boxes is typically loaded from edit-form-advanced.php.
*/
require_once ABSPATH . 'wp-admin/includes/meta-boxes.php';
register_and_do_post_meta_boxes( $post );

require_once ABSPATH . 'wp-admin/admin-header.php';
the_gutenberg_project();
function gutenberg_init() {
_deprecated_function( __FUNCTION__, '5.3.0' );

return true;
require_once ABSPATH . 'wp-admin/includes/screen.php';
return get_current_screen()->is_block_editor();
}
Loading

0 comments on commit 67656bc

Please sign in to comment.