-
Notifications
You must be signed in to change notification settings - Fork 219
Check if WordPress version is higher than 6.2.2 to make Products block compatible with Gutenberg 16+ #10360
Check if WordPress version is higher than 6.2.2 to make Products block compatible with Gutenberg 16+ #10360
Changes from 2 commits
4381994
fee90dc
cc4dbdd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -82,18 +82,19 @@ protected function initialize() { | |||||
} | ||||||
|
||||||
/** | ||||||
* Extra data passed through from server to client for block. | ||||||
* | ||||||
* @param array $attributes Any attributes that currently are available from the block. | ||||||
* Note, this will be empty in the editor context when the block is | ||||||
* not in the post content on editor load. | ||||||
*/ | ||||||
protected function enqueue_data( array $attributes = [] ) { | ||||||
parent::enqueue_data( $attributes ); | ||||||
|
||||||
$gutenberg_version = ''; | ||||||
* Post Template support for grid view was introduced in Gutenberg 16 / WordPress 6.3 | ||||||
* Fixed in: | ||||||
* - https://github.com/woocommerce/woocommerce-blocks/pull/9916 | ||||||
* - https://github.com/woocommerce/woocommerce-blocks/pull/10360 | ||||||
*/ | ||||||
private function check_if_post_template_has_support_for_grid_view() { | ||||||
if ( version_compare( $GLOBALS['wp_version'], '6.2.2', '>' ) ) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure that this check is correct? Should be
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
But you're right, I cannot compare to 6.2.2, because there may be another 6.2.x release and there will be incorrect behaviour. I'll try to use this custom function There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
TIL
Thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, code updated! And I updated testing steps to cover cases with higher and lower than WP 6.3 + Gutenberg 16 enabled and disabled. |
||||||
return true; | ||||||
} | ||||||
|
||||||
if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) { | ||||||
$gutenberg_version = ''; | ||||||
|
||||||
if ( defined( 'GUTENBERG_VERSION' ) ) { | ||||||
$gutenberg_version = GUTENBERG_VERSION; | ||||||
} | ||||||
|
@@ -105,11 +106,27 @@ protected function enqueue_data( array $attributes = [] ) { | |||||
); | ||||||
$gutenberg_version = $gutenberg_data['Version']; | ||||||
} | ||||||
return version_compare( $gutenberg_version, '16.0', '>=' ); | ||||||
} | ||||||
|
||||||
return false; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Extra data passed through from server to client for block. | ||||||
* | ||||||
* @param array $attributes Any attributes that currently are available from the block. | ||||||
* Note, this will be empty in the editor context when the block is | ||||||
* not in the post content on editor load. | ||||||
*/ | ||||||
protected function enqueue_data( array $attributes = [] ) { | ||||||
parent::enqueue_data( $attributes ); | ||||||
|
||||||
$post_template_has_support_for_grid_view = $this->check_if_post_template_has_support_for_grid_view(); | ||||||
|
||||||
$this->asset_data_registry->add( | ||||||
'post_template_has_support_for_grid_view', | ||||||
version_compare( $gutenberg_version, '16.0', '>=' ) | ||||||
$post_template_has_support_for_grid_view | ||||||
); | ||||||
} | ||||||
|
||||||
|
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.
NIT: Should we put both logic in a dedicated function and add a comment? (it would be great just the link to this PR)
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 idea! I extracted the logic to separate function, do you mind taking a look one more time?
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 noticed that we should fix the check for the WP version :D