-
Notifications
You must be signed in to change notification settings - Fork 808
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
Block version gating #14703
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
This is an automated check which relies on |
class.jetpack-gutenberg.php
Outdated
public static function is_block_version_gated( $core_wp_version, $plugin_version ) { | ||
global $wp_version; | ||
|
||
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
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.
Does this check true
on Atomic sites? (Those can sometimes run older versions of Gutenberg.)
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.
good question, will try and find out
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.
Apparently this will only return true for simple sites.
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
2 similar comments
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
class.jetpack-gutenberg.php
Outdated
public static function is_block_version_gated( $core_wp_version, $plugin_version ) { | ||
global $wp_version; | ||
|
||
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
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.
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).
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 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.
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.
Looking good so far. Should we add the nudge to this PR or create a separate one?
class.jetpack-gutenberg.php
Outdated
'incorrect_gutenberg_version', | ||
array( | ||
'required_feature' => $slug, | ||
'required_version' => $args['version_requirements']['plugin'], |
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.
Would we need all the version requirements for the nudge? And would it be beneficial to know the versions detected?
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
1 similar comment
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
@pablinos I made some changes based on your feedback, let me know what you think about the latest iteration. |
I was figuring we would keep it simple and do the nudge as a separate PR. |
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
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. |
Sorry only just saw this reply. I agree! |
This looks good to me, just a few thoughts:
|
class.jetpack-gutenberg.php
Outdated
} | ||
|
||
if ( defined( 'GUTENBERG_VERSION' ) ) { | ||
$version_available = GUTENBERG_VERSION >= $version_requirements['plugin']; |
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 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?
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.
Done - but wasn't sure on bailing if we just return false or true - open to suggestions on best approach here.
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
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.
This seems to work nicely in my tests with the Markdown block:
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?
…quired version of gutenberg will go out it
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. |
glendaviesnz, Your synced wpcom patch D38972-code has been updated. |
Done. |
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.
This works well for me right now. 👍
r203276-wpcom |
* 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
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?
Testing instructions:
extensions/blocks/markdown/markdown.php
block registration to the following:window.Jetpack_Editor_Initial_State.available_blocks;
showsN.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 inclass.jetpack-gutenberg.php
to test: