Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Check if WordPress version is higher than 6.2.2 to make Products block compatible with Gutenberg 16+ #10360

Merged
merged 3 commits into from
Jul 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/BlockTypes/ProductQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ protected function initialize() {
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );

if ( version_compare( $GLOBALS['wp_version'], '6.2.2', '>' ) ) {
Copy link
Contributor

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)

Copy link
Contributor Author

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)

Good idea! I extracted the logic to separate function, do you mind taking a look one more time?

Copy link
Contributor

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure that this check is correct? Should be

Suggested change
if ( version_compare( $GLOBALS['wp_version'], '6.2.2', '>' ) ) {
if ( version_compare( $GLOBALS['wp_version'], '6.3.0', '>=' ) ) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

version_compare consider versions with suffix as lower, for example, 6.3.0 is higher than 6.3.0-RC2. That means the fix won't be applied to the RC version.

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 wp_version_compare which I belive was written for exactly this case or I'll think of something custom.

Copy link
Contributor

Choose a reason for hiding this comment

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

version_compare consider versions with suffix as lower, for example, 6.3.0 is higher than 6.3.0-RC2. That means the fix won't be applied to the RC version.

TIL

version_compare consider versions with suffix as lower, for example, 6.3.0 is higher than 6.3.0-RC2. That means the fix won't be applied to the RC version.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

$this->asset_data_registry->add(
'post_template_has_support_for_grid_view',
true
);
return;
}

$gutenberg_version = '';

if ( is_plugin_active( 'gutenberg/gutenberg.php' ) ) {
Expand Down