Skip to content

Commit

Permalink
[not verified] WordPress 5.8 Compatibility: Add support for `block_ed…
Browse files Browse the repository at this point in the history
…itor_settings_all` (#20201)
  • Loading branch information
sdixon194 committed Jul 19, 2021
1 parent e3dcd2b commit 1bb54d2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: compat

Compatibility: Adds support for block_editor_settings_all when running WordPress 5.8 or higher
12 changes: 10 additions & 2 deletions projects/plugins/jetpack/modules/copy-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function __construct() {
* @return void
*/
public function update_post_data( $target_post_id, $post, $update ) {
global $wp_version;
// This `$update` check avoids infinite loops of trying to update our updated post.
if ( $update ) {
return;
Expand All @@ -69,8 +70,15 @@ public function update_post_data( $target_post_id, $post, $update ) {
add_filter( 'default_content', array( $this, 'filter_content' ), 10, 2 );
add_filter( 'default_excerpt', array( $this, 'filter_excerpt' ), 10, 2 );

// Required to avoid the block editor from adding default blocks according to post format.
add_filter( 'block_editor_settings', array( $this, 'remove_post_format_template' ) );
/*
* Required to avoid the block editor from adding default blocks according to post format.
* @todo: simplify once WordPress 5.8 is the minimum required version.
*/
if ( version_compare( $wp_version, '5.8', '>=' ) ) {
add_filter( 'block_editor_settings_all', array( $this, 'remove_post_format_template' ) );
} else {
add_filter( 'block_editor_settings', array( $this, 'remove_post_format_template' ) );
}

/**
* Fires after all updates have been performed, and default content filters have been added.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private function __construct() {
* Add in all hooks.
*/
public function init_actions() {
global $wp_version;
// Bail early if Jetpack's block editor extensions are disabled on the site.
/* This filter is documented in class.jetpack-gutenberg.php */
if ( ! apply_filters( 'jetpack_gutenberg', true ) ) {
Expand All @@ -64,11 +65,16 @@ public function init_actions() {

require_once __DIR__ . '/functions.editor-type.php';
add_action( 'edit_form_top', 'Jetpack\EditorType\remember_classic_editor' );
add_filter( 'block_editor_settings', 'Jetpack\EditorType\remember_block_editor', 10, 2 );
add_action( 'login_init', array( $this, 'allow_block_editor_login' ), 1 );
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ), 9 );
add_action( 'enqueue_block_assets', array( $this, 'enqueue_block_assets' ) );
add_filter( 'mce_external_plugins', array( $this, 'add_tinymce_plugins' ) );
// @todo simplify once 5.8 is the minimum supported version.
if ( version_compare( $wp_version, '5.8', '>=' ) ) {
add_filter( 'block_editor_settings_all', 'Jetpack\EditorType\remember_block_editor', 10, 2 );
} else {
add_filter( 'block_editor_settings', 'Jetpack\EditorType\remember_block_editor', 10, 2 );
}

$this->enable_cross_site_auth_cookies();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,26 @@ function remember_classic_editor( $post ) {
/**
* Remember when the block editor was used to edit a post.
*
* @param object $editor_settings This is hooked into a filter and this is the settings that are passed in.
* @param object $post The post being editted.
* @return object The unmodified $editor_settings parameter.
* @todo: simplify once WordPress 5.8 is the minimum required version.
*
* @param array $editor_settings This is hooked into a filter and this is the settings that are passed in.
* @param WP_Post|WP_Block_Editor_Context $post In WP 5.7- the post being editted. In WP 5.8+, the block editor context.
*
* @return array The unmodified $editor_settings parameter.
*/
function remember_block_editor( $editor_settings, $post ) {
$post_type = get_post_type( $post );
if (
! empty( $post->post ) &&
is_a( $post, 'WP_Block_Editor_Context' )
) {
$post = $post->post;
}

if ( empty( $post ) ) {
return $editor_settings;
}

$post_type = get_post_type( $post );
if ( $post_type && can_edit_post_type( $post_type ) ) {
remember_editor( $post->ID, 'block-editor' );
}
Expand Down

0 comments on commit 1bb54d2

Please sign in to comment.