Skip to content
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

Merged
merged 11 commits into from
Jul 19, 2021

Conversation

sdixon194
Copy link
Contributor

The filter block_editor_settings is being deprecated in favor of block_editor_settings_all for WordPress 5.8.

Changes proposed in this Pull Request:

  • Adds support for block_editor_settings_all when running WordPress 5.8 or higher.

Jetpack product discussion

#19654

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

  • Smoke test using the block editor.
  • Enable the option allowing you to copy posts under Jetpack -> Writing -> Compose settings.
  • Make sure the copy post option still works.

@sdixon194 sdixon194 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Feature] Copy a Post [Feature] WordPress.com Block Editor [Focus] Compatibility Ensuring our products play well with third-parties labels Jun 28, 2021
@sdixon194 sdixon194 added this to the jetpack/9.9 milestone Jun 28, 2021
@sdixon194 sdixon194 requested a review from jeherve June 28, 2021 14:37
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello sdixon194! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D63394-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Jun 28, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Jun 28, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

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.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.


Jetpack plugin:

  • Next scheduled release: July 20, 2021.
  • Scheduled code freeze: July 15, 2021.

@github-actions github-actions bot added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jun 28, 2021
@sdixon194 sdixon194 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Jun 28, 2021
anomiex
anomiex previously approved these changes Jun 28, 2021
Copy link
Contributor

@anomiex anomiex left a 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.

jeherve
jeherve previously requested changes Jul 6, 2021
Copy link
Member

@jeherve jeherve left a 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 );
Copy link
Member

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:

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.

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jul 6, 2021
@sdixon194 sdixon194 added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Jul 9, 2021
@sdixon194 sdixon194 merged commit 4a5c6ed into master Jul 19, 2021
@sdixon194 sdixon194 deleted the update/block-editor-settings-deprecation branch July 19, 2021 16:00
sdixon194 added a commit that referenced this pull request Jul 19, 2021
@sdixon194
Copy link
Contributor Author

Cherry picked to release branch in 1bb54d2

@sdixon194 sdixon194 removed [Status] Needs Cherry-Pick [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jul 19, 2021
@github-actions
Copy link
Contributor

Great news! One last step: head over to your WordPress.com diff, D63394-code, and commit it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@sdixon194
Copy link
Contributor Author

sdixon194 commented Jul 19, 2021

Deployed to wpcom in r228850-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Copy a Post [Feature] WordPress.com Block Editor [Focus] Compatibility Ensuring our products play well with third-parties [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants