diff --git a/projects/plugins/jetpack/changelog/update-block-editor-settings-deprecation b/projects/plugins/jetpack/changelog/update-block-editor-settings-deprecation new file mode 100644 index 0000000000000..a67c143ac9271 --- /dev/null +++ b/projects/plugins/jetpack/changelog/update-block-editor-settings-deprecation @@ -0,0 +1,4 @@ +Significance: minor +Type: compat + +Compatibility: Adds support for block_editor_settings_all when running WordPress 5.8 or higher diff --git a/projects/plugins/jetpack/modules/copy-post.php b/projects/plugins/jetpack/modules/copy-post.php index 47b9e991d2dce..dc92af45a1970 100644 --- a/projects/plugins/jetpack/modules/copy-post.php +++ b/projects/plugins/jetpack/modules/copy-post.php @@ -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; @@ -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. diff --git a/projects/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php b/projects/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php index b6e514b48f2a2..7d2548eb7e4c6 100644 --- a/projects/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php +++ b/projects/plugins/jetpack/modules/wpcom-block-editor/class-jetpack-wpcom-block-editor.php @@ -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 ) ) { @@ -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(); } diff --git a/projects/plugins/jetpack/modules/wpcom-block-editor/functions.editor-type.php b/projects/plugins/jetpack/modules/wpcom-block-editor/functions.editor-type.php index ea053954e31d9..4da4c9b9efbee 100644 --- a/projects/plugins/jetpack/modules/wpcom-block-editor/functions.editor-type.php +++ b/projects/plugins/jetpack/modules/wpcom-block-editor/functions.editor-type.php @@ -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' ); }