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

Commit

Permalink
Release: 11.5.2 (#11705)
Browse files Browse the repository at this point in the history
* Empty commit for release pull request

* Add readme and testing notes

* Bump versions to 11.5.1

* Fix Single Product Classic Template block not showing on the front-end (#11455)

In WordPress 6.4, it appears that the global `have_posts` is `false` in
the context of the full site editing single product template. This
breaks the Classic Template block.

In this commit, we are creating a custom query using the available id
instead of relying on the global query.

This might be a temporary workaround as we are waiting to see
if that's an issue that core is willing to fix, as it might affect
backwards-compatibility for other vendors.

(cherry picked from commit d9e8809)

* Update testing notes with new zip file

* Add protection against wrong params in get_block_template_fallback() (#11690)

* Add protection towards wrong params in get_block_template_fallback()

* Improve protection

* Update WC Blocks 11.5.1 changelog and testing steps with new fix

* bump version

* [CYS] Fix decoding issue and pattern (#11681)

* Fix pattern description

* Decode the actual file content, not the filepath

* Use wp_post table instead wp_option to store patterns data generated by AI (#11659)

* Use wp_post table instead wp_option to store patterns data generated by AI

* avoid crash when there isn't any patterns_ai_data post type

* restore check

* remove unnecessary constant

* catch error

* pass boolean to return WP_Error

* Rename Centered Header Menu with Search pattern (#11637)

* Rename Centered Header Menu with Search pattern

Since the search bar has been removed from this pattern, this PR renames
the pattern title and slug to reflect that change.

* Rename file to reflect search removal.

Remove `search` from the filename, as this no longer reflects the
pattern.

* Add missing condition to avoid a php warning when 'plugins' is not set (#11652)

* Fix pattern route performance (#11535)

* fix pattern route performance

* update namespace

* improve middleware

* improve ProductSchema

* improve error handling

* update identifier

* fix middleware

* update description

* use schema to return the response

* Break down the generate_content method and create the new fetch_dummy_products_to_update method for handling the fetch of dummy products to be updated.

* Ensure the Product endpoint relies on the fetch_dummy_products_to_update method for fetching dummy products to avoid code repetition and add safety checks and handle errors in case certain properties are not available.

* Add error handling for the Products endpoint.

* Remove memory limit increase and update docblocks.

* re-add set_time_limit

---------

Co-authored-by: Patricia Hillebrandt <[email protected]>

* Empty commit for release pull request

* add testing instructions

* add zip link

---------

Co-authored-by: github-actions <[email protected]>
Co-authored-by: Lucio Giannotta <[email protected]>
Co-authored-by: Albert Juhé Lluveras <[email protected]>
Co-authored-by: Luigi <[email protected]>
Co-authored-by: Alba Rincón <[email protected]>
Co-authored-by: Daniel W. Robert <[email protected]>
Co-authored-by: Patricia Hillebrandt <[email protected]>
  • Loading branch information
8 people authored Nov 8, 2023
1 parent 721e6a7 commit 1e1afd2
Show file tree
Hide file tree
Showing 27 changed files with 857 additions and 155 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://woocommerce.com/",
"type": "wordpress-plugin",
"version": "11.5.1",
"version": "11.5.2",
"keywords": [
"gutenberg",
"woocommerce",
Expand Down
19 changes: 19 additions & 0 deletions docs/internal-developers/testing/releases/1152.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Testing notes and ZIP for release 11.5.2

Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-blocks/files/13300708/woocommerce-gutenberg-products-block.zip)

## WooCommerce Core

### Bug Fixes

#### Rename the Centered Header Menu with Search to Centered Header Menu. [11637](https://github.com/woocommerce/woocommerce-blocks/pull/11637)

1. Create a new page or post.
2. Confirm that the `Centered Header Menu` pattern appears under the WooCommerce category dropdown and is NOT named `Centered Header Menu with Search`.
3. Insert in and confirm everything appears as expected.

#### Fix decoding issue and pattern. [11681](https://github.com/woocommerce/woocommerce-blocks/pull/11681)

1. Ensure you are on fresh install (it should not have the `patterns_ai_data` post created).
2. Insert the `Featured Products: Fresh & Tasty` pattern and make sure it has all the default text content, nothing is empty.
3. Insert a few other WooCommerce Blocks patterns and check all of them have all the text content as well.
2 changes: 2 additions & 0 deletions docs/internal-developers/testing/releases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,5 @@ Every release includes specific testing instructions for new features and bug fi
- [11.4.3](./1143.md)
- [11.5.0](./1150.md)
- [11.5.1](./1151.md)
- [11.5.2](./1152.md)

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@woocommerce/block-library",
"title": "WooCommerce Blocks",
"author": "Automattic",
"version": "11.5.1",
"version": "11.5.2",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion patterns/featured-products-fresh-and-tasty.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
$first_description = $content['descriptions'][0]['default'] ?? '';
$second_description = $content['descriptions'][1]['default'] ?? '';
$third_description = $content['descriptions'][2]['default'] ?? '';
$fourth_description = $content['descriptions'][3]['default'] ?? '';
?>

<!-- wp:heading {"level":3,"align":"wide"} -->
Expand Down Expand Up @@ -129,7 +130,7 @@
<!-- wp:column {"width":"67%","style":{"typography":{"fontWeight":"600"}},"layout":{"type":"constrained","justifyContent":"left"}} -->
<div class="wp-block-column" style="font-weight:600;flex-basis:67%">
<!-- wp:paragraph {"fontSize":"small"} -->
<p class="has-small-font-size"><?php echo esc_html( $content['descriptions'][0]['default'] ); ?></p>
<p class="has-small-font-size"><?php echo esc_html( $fourth_description ); ?></p>
<!-- /wp:paragraph -->
</div>
<!-- /wp:column -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Title: Centered Header Menu with Search
* Slug: woocommerce-blocks/header-centered-menu-with-search
* Title: Centered Header Menu
* Slug: woocommerce-blocks/header-centered-menu
* Categories: WooCommerce
* Block Types: core/template-part/header
*/
Expand Down
9 changes: 8 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks
Requires at least: 6.3
Tested up to: 6.3
Requires PHP: 7.4
Stable tag: 11.5.1
Stable tag: 11.5.2
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -81,6 +81,13 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/

== Changelog ==

= 11.5.2 - 2023-11-08 =

#### Bug Fixes

- Rename the Centered Header Menu with Search to Centered Header Menu. [11637](https://github.com/woocommerce/woocommerce-blocks/pull/11637)
- Fix decoding issue and pattern. [11681](https://github.com/woocommerce/woocommerce-blocks/pull/11681)

= 11.5.1 - 2023-11-08 =

#### Bug Fixes
Expand Down
23 changes: 20 additions & 3 deletions src/BlockPatterns.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
* @internal
*/
class BlockPatterns {
const SLUG_REGEX = '/^[A-z0-9\/_-]+$/';
const COMMA_SEPARATED_REGEX = '/[\s,]+/';
const SLUG_REGEX = '/^[A-z0-9\/_-]+$/';
const COMMA_SEPARATED_REGEX = '/[\s,]+/';
const PATTERNS_AI_DATA_POST_TYPE = 'patterns_ai_data';

/**
* Path to the patterns directory.
Expand Down Expand Up @@ -92,6 +93,22 @@ public function register_block_patterns() {
return;
}

register_post_type(
self::PATTERNS_AI_DATA_POST_TYPE,
array(
'labels' => array(
'name' => __( 'Patterns AI Data', 'woo-gutenberg-products-block' ),
'singular_name' => __( 'Patterns AI Data', 'woo-gutenberg-products-block' ),
),
'public' => false,
'hierarchical' => false,
'rewrite' => false,
'query_var' => false,
'delete_with_user' => false,
'can_export' => true,
)
);

$default_headers = array(
'title' => 'Title',
'slug' => 'Slug',
Expand Down Expand Up @@ -250,7 +267,7 @@ public function schedule_on_option_update( $option, $value ) {
* @param array $options Array of bulk item update data.
*/
public function schedule_on_plugin_update( $upgrader_object, $options ) {
if ( 'update' === $options['action'] && 'plugin' === $options['type'] ) {
if ( 'update' === $options['action'] && 'plugin' === $options['type'] && isset( $options['plugins'] ) ) {
foreach ( $options['plugins'] as $plugin ) {
if ( str_contains( $plugin, 'woocommerce-gutenberg-products-block.php' ) || str_contains( $plugin, 'woocommerce.php' ) ) {
$business_description = get_option( 'woo_ai_describe_store_description' );
Expand Down
2 changes: 1 addition & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function container( $reset = false ) {
NewPackage::class,
function ( $container ) {
// leave for automated version bumping.
$version = '11.5.1';
$version = '11.5.2';
return new NewPackage(
$version,
dirname( __DIR__ ),
Expand Down
13 changes: 5 additions & 8 deletions src/Patterns/PatternUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
*/
class PatternUpdater {

/**
* The patterns content option name.
*/
const WC_BLOCKS_PATTERNS_CONTENT = 'wc_blocks_patterns_content';

/**
* Creates the patterns content for the given vertical.
*
Expand Down Expand Up @@ -42,13 +37,15 @@ public function generate_content( $ai_connection, $token, $images, $business_des
return new WP_Error( 'failed_to_set_pattern_content', __( 'Failed to set the pattern content.', 'woo-gutenberg-products-block' ) );
}

if ( get_option( self::WC_BLOCKS_PATTERNS_CONTENT ) === $patterns_with_images_and_content ) {
$patterns_ai_data_post = PatternsHelper::get_patterns_ai_data_post();

if ( isset( $patterns_ai_data_post->post_content ) && json_decode( $patterns_ai_data_post->post_content ) === $patterns_with_images_and_content ) {
return true;
}

$updated_content = update_option( self::WC_BLOCKS_PATTERNS_CONTENT, $patterns_with_images_and_content );
$updated_content = PatternsHelper::upsert_patterns_ai_data_post( $patterns_with_images_and_content );

if ( ! $updated_content ) {
if ( is_wp_error( $updated_content ) ) {
return new WP_Error( 'failed_to_update_patterns_content', __( 'Failed to update patterns content.', 'woo-gutenberg-products-block' ) );
}

Expand Down
50 changes: 47 additions & 3 deletions src/Patterns/PatternsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,48 @@ public static function get_image_url( array $images, int $index, string $default

return $image;
}
/**
* Returns the post that has the generated data by the AI for the patterns.
*
* @return WP_Post|null
*/
public static function get_patterns_ai_data_post() {
$arg = array(
'post_type' => 'patterns_ai_data',
'posts_per_page' => 1,
'no_found_rows' => true,
'cache_results' => true,
);

$query = new \WP_Query( $arg );

$posts = $query->get_posts();
return isset( $posts[0] ) ? $posts[0] : null;
}

/**
* Upsert the patterns AI data.
*
* @param array $patterns_dictionary The patterns dictionary.
*
* @return WP_Error|null
*/
public static function upsert_patterns_ai_data_post( $patterns_dictionary ) {
$patterns_ai_data_post = self::get_patterns_ai_data_post();

if ( isset( $patterns_ai_data_post ) ) {
$patterns_ai_data_post->post_content = wp_json_encode( $patterns_dictionary );
return wp_update_post( $patterns_ai_data_post, true );
} else {
$patterns_ai_data_post = array(
'post_title' => 'Patterns AI Data',
'post_content' => wp_json_encode( $patterns_dictionary ),
'post_status' => 'publish',
'post_type' => 'patterns_ai_data',
);
return wp_insert_post( $patterns_ai_data_post, true );
}
}

/**
* Get the Patterns Dictionary.
Expand All @@ -83,9 +125,11 @@ public static function get_image_url( array $images, int $index, string $default
* @return mixed|WP_Error|null
*/
private static function get_patterns_dictionary( $pattern_slug = null ) {
$patterns_dictionary = get_option( PatternUpdater::WC_BLOCKS_PATTERNS_CONTENT );

if ( ! empty( $patterns_dictionary ) ) {
$patterns_ai_data_post = self::get_patterns_ai_data_post();

if ( isset( $patterns_ai_data_post ) ) {
$patterns_dictionary = json_decode( $patterns_ai_data_post->post_content, true );
if ( empty( $pattern_slug ) ) {
return $patterns_dictionary;
}
Expand All @@ -103,7 +147,7 @@ private static function get_patterns_dictionary( $pattern_slug = null ) {
return new WP_Error( 'missing_patterns_dictionary', __( 'The patterns dictionary is missing.', 'woo-gutenberg-products-block' ) );
}

$patterns_dictionary = wp_json_file_decode( $patterns_dictionary_file, array( 'associative' => true ) );
$patterns_dictionary = json_decode( $patterns_dictionary_file, true );

if ( ! empty( $pattern_slug ) ) {
foreach ( $patterns_dictionary as $pattern_dictionary ) {
Expand Down
Loading

0 comments on commit 1e1afd2

Please sign in to comment.