-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WordPress 5.8 Compatibility: Add support for block_editor_settings_all
#20201
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available. Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
…-settings-deprecation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks sensible to me. Haven't tested though.
…-settings-deprecation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a small remark below.
I also think it would be nice to add a comment so we can easily find that backwards compatibility check later and remove it once WP 5.8 is the minimum supported version.
Maybe something like this?
diff --git a/projects/plugins/jetpack/modules/copy-post.php b/projects/plugins/jetpack/modules/copy-post.php
index 069adef24c..dc92af45a1 100644
--- a/projects/plugins/jetpack/modules/copy-post.php
+++ b/projects/plugins/jetpack/modules/copy-post.php
@@ -70,7 +70,10 @@ class Jetpack_Copy_Post {
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.
+ /*
+ * 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 {
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 db35050d99..7d89bb0052 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
@@ -69,6 +69,8 @@ class Jetpack_WPCOM_Block_Editor {
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 WordPress 5.8 is the minimum required version.
if ( version_compare( $wp_version, '5.8', '>=' ) ) {
add_filter( 'block_editor_settings_all', 'Jetpack\EditorType\remember_block_editor', 10, 2 );
} else {
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 ea053954e3..40d76be7a4 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,11 +24,21 @@ 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 ) {
+ if (
+ is_a( $post, 'WP_Block_Editor_Context' )
+ && ! empty( $post->post )
+ ) {
+ $post = $post->post;
+ }
+
$post_type = get_post_type( $post );
if ( $post_type && can_edit_post_type( $post_type ) ) {
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' ) ); | ||
if ( version_compare( $wp_version, '5.8', '>=' ) ) { | ||
add_filter( 'block_editor_settings_all', 'Jetpack\EditorType\remember_block_editor', 10, 2 ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's going to work as well in WordPress 5.8.
In WordPress 5.7, the block_editor_settings
filter's second parameter was an instance of WP_Post
. We use it here:
jetpack/projects/plugins/jetpack/modules/wpcom-block-editor/functions.editor-type.php
Line 32 in 26db3e4
$post_type = get_post_type( $post ); |
In WordPress 5.8, the block_editor_settings_all
filter's second parameter is different: it is now an instance of WP_Block_Editor_Context
.
…-settings-deprecation
…-settings-deprecation
…-settings-deprecation
…-settings-deprecation
…itor_settings_all` (#20201)
Cherry picked to release branch in 1bb54d2 |
Great news! One last step: head over to your WordPress.com diff, D63394-code, and commit it. Thank you! |
Deployed to wpcom in r228850-wpcom |
The filter
block_editor_settings
is being deprecated in favor ofblock_editor_settings_all
for WordPress 5.8.Changes proposed in this Pull Request:
Jetpack product discussion
#19654
Does this pull request change what data or activity we track or use?
No.
Testing instructions: