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 Jan 31, 2019
1 parent 62f6163 commit 4185fc6
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 816 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,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
118 changes: 14 additions & 104 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,42 +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.0.0
*/
function the_gutenberg_project() {
global $post_type_object;
?>
<noscript>
<div class="error" style="position:absolute;top:32px;z-index:40"><p>
<?php
// Using Gutenberg as Plugin.
if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
$current_url = esc_url( add_query_arg( 'classic-editor', true, $_SERVER['REQUEST_URI'] ) );
printf(
// Translators: link is to current page specify classic editor.
__( 'The Block Editor requires JavaScript. You can use the <a href="%s">Classic Editor</a>.', 'gutenberg' ),
$current_url
);
} else { // Using Gutenberg in Core.
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.0.0' );
}

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

Expand Down Expand Up @@ -105,38 +74,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.0.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;
}

if ( isset( $_GET['classic-editor'] ) ) {
return false;
}
_deprecated_function( __FUNCTION__, '5.0.0', 'WP_Screen::is_block_editor' );

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

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

/**
Expand Down Expand Up @@ -187,57 +133,21 @@ 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.0.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.0.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();
}

/**
Expand Down
Loading

0 comments on commit 4185fc6

Please sign in to comment.