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

Block version gating #14703

Merged
merged 14 commits into from
Feb 24, 2020
Merged

Block version gating #14703

merged 14 commits into from
Feb 24, 2020

Conversation

glendaviesnz
Copy link
Contributor

@glendaviesnz glendaviesnz commented Feb 16, 2020

Adds a version gating option block registration.

Changes proposed in this Pull Request:

  • Some of the new blocks being created require specific versions of gutenberg. This PR introduces the ability to include min WP and gutenberg plugin versions in jetpack_register_block $args

  • It also runs set_extension_unavailable if block is version gated in order to allow a version upgrade nudge to be added a later point.

Is this a new feature or does it add/remove features to an existing part of Jetpack?

  • New feature.

Testing instructions:

  • Check out this branch and build blocks
  • Update extensions/blocks/markdown/markdown.php block registration to the following:
jetpack_register_block( 'jetpack/markdown', array( 'version_requirements' => array( 'gutenberg' => '8', 'wp' => '7')) );
  • Load the build in your local jetpack dev setup and check that window.Jetpack_Editor_Initial_State.available_blocks; shows
markdown:
available: false
unavailable_reason: "incorrect_gutenberg_version"
details:
required_feature: "jetpack/markdown"
required_version: {gutenberg: "8", wp: "7"}
current_version: {wp: "5.3", gutenberg: "7.5.0"}
  • Play around with modifying the gutenberg and wp versions, and the versions you are running and check block shows available or not.

N.B. Your local dev may set GUTENBERG_DEVELOPMENT_MODE in which case the block will always show available, in which case you can comment out the following in class.jetpack-gutenberg.php to test:

if ( defined( 'GUTENBERG_DEVELOPMENT_MODE' ) && GUTENBERG_DEVELOPMENT_MODE ) {
	return true;
}

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello glendaviesnz! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D38972-code before merging this PR. Thank you!

@jetpackbot
Copy link

jetpackbot commented Feb 16, 2020

Warnings
⚠️

pre-commit hook was skipped for one or more commits

⚠️ "Proposed changelog entry" is missing for this PR. Please include any meaningful changes

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

Generated by 🚫 dangerJS against e07aa21

public static function is_block_version_gated( $core_wp_version, $plugin_version ) {
global $wp_version;

if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this check true on Atomic sites? (Those can sometimes run older versions of Gutenberg.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question, will try and find out

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently this will only return true for simple sites.

@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

2 similar comments
@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

@glendaviesnz glendaviesnz changed the title Initial commit of block version gating [WIP] Block version gating Feb 17, 2020
public static function is_block_version_gated( $core_wp_version, $plugin_version ) {
global $wp_version;

if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why WPCOM will always return false? It seems like there are reasonable situations where it may not have the necessary version of Core or Gutenberg (for example, I believe some VIPs are running older versions of Gutenberg).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that wpcom simple sites currently have the latest gutenberg release - but if there are VIP sites running older versions which have IS_WPCOM set then I will take a look and see how we can identify which gutenberg version is active for any site which has IS_WPCOM true.

@jeherve jeherve added [Status] In Progress [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack labels Feb 17, 2020
Copy link
Contributor

@pablinos pablinos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good so far. Should we add the nudge to this PR or create a separate one?

'incorrect_gutenberg_version',
array(
'required_feature' => $slug,
'required_version' => $args['version_requirements']['plugin'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we need all the version requirements for the nudge? And would it be beneficial to know the versions detected?

class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

1 similar comment
@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

@glendaviesnz
Copy link
Contributor Author

@pablinos I made some changes based on your feedback, let me know what you think about the latest iteration.

@glendaviesnz
Copy link
Contributor Author

Should we add the nudge to this PR or create a separate one?

I was figuring we would keep it simple and do the nudge as a separate PR.

@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

@pablinos
Copy link
Contributor

@pablinos I made some changes based on your feedback, let me know what you think about the latest iteration.

It's looking good at first glance. I think on reflection it would be good to keep this PR as just the logic to check versions and we can add the nudge in a separate one.

@pablinos
Copy link
Contributor

I was figuring we would keep it simple and do the nudge as a separate PR.

Sorry only just saw this reply. I agree!

@glendaviesnz glendaviesnz changed the title [WIP] Block version gating Block version gating Feb 18, 2020
@glendaviesnz glendaviesnz marked this pull request as ready for review February 18, 2020 19:29
@glendaviesnz glendaviesnz requested a review from a team February 18, 2020 19:29
@scruffian
Copy link
Member

This looks good to me, just a few thoughts:

  1. We should update the documentation of jetpack_register_block to add this option and explain how to use it.

  2. From the name (is_editor_version_available) and the code itself, I don't think it's 100% clear whether this is just a check for the Gutenberg version that is running, or a generic check for any plugin. Maybe we should change the plugin array key to gutenberg and the function to is_gutenberg_version_available. I can see a case in the future of extending this to check for any plugin, but lets not add that at this stage :)

class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
}

if ( defined( 'GUTENBERG_VERSION' ) ) {
$version_available = GUTENBERG_VERSION >= $version_requirements['plugin'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should check if plugin and wp are set before to call them here and below, to avoid any errors if someone registers a block but only specifies one or the other?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - but wasn't sure on bailing if we just return false or true - open to suggestions on best approach here.

class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
@jeherve jeherve added this to the 8.3 milestone Feb 19, 2020
@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
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.

This seems to work nicely in my tests with the Markdown block:

image

It may be useful to add some testing instructions to your PR so others can test.

For example, I am not sure what one should use as value for the wp requirement when registering a block, though. For example right now I can develop a block that uses features introduced in Gutenberg 7.5.0. I don't necessarily know when that version of Gutenberg will make it to WordPress Core though, do I? In this case what should one use? A random high WordPress version number that we're not likely to reach anytime soon?

class.jetpack-gutenberg.php Outdated Show resolved Hide resolved
@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] In Progress labels Feb 21, 2020
…quired version of gutenberg will go out it
@glendaviesnz
Copy link
Contributor Author

I am not sure what one should use as value for the wp requirement when registering a block, though. For example right now I can develop a block that uses features introduced in Gutenberg 7.5.0. I don't necessarily know when that version of Gutenberg will make it to WordPress Core though, do I

Ah, nice catch, hadn't thought about it from that angle. Making up a random future core release number seems a bit hacky to me though - I have pushed an alternative approach that makes the wp version optional if it is know, and updated the comments to explain this - let me know what you think of this approach - the main downside I can see is that teams will need to be disciplined about circling back and adding wp version to the version requirements array once it is known if the version gate is still required at that point.

@matticbot
Copy link
Contributor

glendaviesnz, Your synced wpcom patch D38972-code has been updated.

@glendaviesnz
Copy link
Contributor Author

It may be useful to add some testing instructions to your PR so others can test.

Done.

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it 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 Feb 24, 2020
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.

This works well for me right now. 👍

@glendaviesnz glendaviesnz merged commit 0ea25dc into master Feb 24, 2020
@glendaviesnz glendaviesnz deleted the add/block-plan-version-gating branch February 24, 2020 09:35
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Feb 24, 2020
@scruffian
Copy link
Member

r203276-wpcom

jeherve added a commit that referenced this pull request Feb 25, 2020
jeherve added a commit that referenced this pull request Feb 25, 2020
* 8.3 release: changelog

* Changelog: add #14516

* Changelog: add #14574

* Bring in changes from 8.2.1 and 8.2.2

* Update stable version

* Bring in 8.2.3 changes

* Changelog: add #14714

* Changelog: add #14639

* Changelog: add #14678

* Changelog: add #14673

* Changelog: add #14687

* Changelog: add #14704

* Changelog: add #14702

* Changelog: add #14541

* Changelog: add #14657

* Changelog: add #14622

* Changelog: add #14582

* Changelog: add #14638

* Changelog: add #14633

* Changelog: add #14571

* Changelog: add #14592

* Changelog: add #14539

* Changelog: add #14514

* Changelog: add #14643

* Changelog: add #14494

* Changelog: add #13739

* Changelog: add #14707

* Changelog: add #14736

* Changelog: add #14706

* Changelog: add #14730

* Changelog: add #14685

* Changelog: add #14727

* Changelog: add #14711

* Changelog: add #14742

* Changelog: add #14746

* Changelog: add #14725

* Changelog: add #13999

* Changelog: add #14740

* Changelog: add #14759

* Changelog: add #14703

* Changelog: add #14753

* Changelog: add #14754

* Changelog: add #14645

* Cahngelog: add #14599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants