Skip to content

Commit

Permalink
Plugin: Remove replace_editor filter, extend core editor
Browse files Browse the repository at this point in the history
  • Loading branch information
aduth committed Feb 28, 2019
1 parent f7b002d commit b65649e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 535 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ The Gutenberg project's deprecation policy is intended to support backward compa
- `window._wpLoadGutenbergEditor` has been removed. Use `window._wpLoadBlockEditor` instead. Note: This is a private API, not intended for public use. It may be removed in the future.
- The PHP function `gutenberg_get_script_polyfill` has been removed. Use [`wp_get_script_polyfill`](https://developer.wordpress.org/reference/functions/wp_get_script_polyfill/) instead.
- The PHP function `gutenberg_add_admin_body_class` has been removed. Use the `.block-editor-page` class selector in your stylesheets if you need to scope styles to the block editor screen.
- 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.

## 4.5.0
- `Dropdown.refresh()` has been deprecated as the contained `Popover` is now automatically refreshed.
Expand Down
104 changes: 14 additions & 90 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,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.2.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>
</div>
<?php
_deprecated_function( __FUNCTION__, '5.2.0' );
}

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

Expand Down Expand Up @@ -104,34 +83,15 @@ 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.2.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;
}
_deprecated_function( __FUNCTION__, '5.2.0', 'WP_Screen::is_block_editor' );

if ( get_current_screen()->base !== 'post' ) {
return false;
}

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

return true;
return get_current_screen()->is_block_editor();
}

/**
Expand Down Expand Up @@ -182,55 +142,19 @@ 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.2.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;
}
function gutenberg_init() {
_deprecated_function( __FUNCTION__, '5.2.0' );

// 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' );

/*
* 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();

return true;
return get_current_screen()->is_block_editor();
}
Loading

0 comments on commit b65649e

Please sign in to comment.