From 5aa74cd2d5af50c3259c9cf33d1ba6f7ff568032 Mon Sep 17 00:00:00 2001 From: Luigi Date: Wed, 3 May 2023 11:47:04 +0200 Subject: [PATCH 01/12] use 'enqueue_block_assets' is available --- src/Assets/AssetDataRegistry.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index a72a81c960d..760be8ce6e4 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,7 +66,8 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - add_action( 'init', array( $this, 'register_data_script' ) ); + // @todo: Remove this check when WordPress 6.3 is the minimum supported version. + add_action( has_action( 'enqueue_block_assets' ) ? 'enqueue_block_assets' : 'init', array( $this, 'register_data_script' ) ); add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); } From ff1c51ca25084c8be8fb3e0fe0cf20a2e2e4de8f Mon Sep 17 00:00:00 2001 From: Luigi Date: Thu, 4 May 2023 11:38:58 +0200 Subject: [PATCH 02/12] enqueue in a different way --- src/Assets/AssetDataRegistry.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index 760be8ce6e4..6ed9ee70e27 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,8 +66,8 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - // @todo: Remove this check when WordPress 6.3 is the minimum supported version. - add_action( has_action( 'enqueue_block_assets' ) ? 'enqueue_block_assets' : 'init', array( $this, 'register_data_script' ) ); + add_action( 'wp_enqueue_scripts', array( $this, 'register_data_script' ) ); + add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) ); add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); } From 090f58b468a675532432329c51dd67c66252851a Mon Sep 17 00:00:00 2001 From: tjcafferkey Date: Thu, 4 May 2023 10:59:02 +0100 Subject: [PATCH 03/12] Run init if not wp_admin() to register AssetDataRegistry scripts --- src/Assets/AssetDataRegistry.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index 6ed9ee70e27..c0471453415 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,8 +66,13 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - add_action( 'wp_enqueue_scripts', array( $this, 'register_data_script' ) ); - add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) ); + // is_login() was introduced in 6.1 so lets check it exists before executing. + if ( ! is_admin() && function_exists( 'is_login' ) && ! is_login() ) { + add_action( 'init', array( $this, 'register_data_script' ) ); + } else { + add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) ); + } + add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); } From 801ca134371fd22a17c5e129fe2249d005f95f2b Mon Sep 17 00:00:00 2001 From: Luigi Date: Thu, 4 May 2023 12:35:51 +0200 Subject: [PATCH 04/12] try now --- src/Assets/AssetDataRegistry.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index c0471453415..0014211cb34 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,11 +66,12 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - // is_login() was introduced in 6.1 so lets check it exists before executing. - if ( ! is_admin() && function_exists( 'is_login' ) && ! is_login() ) { - add_action( 'init', array( $this, 'register_data_script' ) ); - } else { + // phpcs:ignore WordPress.Security.NonceVerification + if ( isset( $_GET['page'] ) && 'gutenberg-edit-site' === $_GET['page'] ) { add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) ); + } else { + add_action( 'init', array( $this, 'register_data_script' ) ); + } add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); From 0577d0cb02438e8bbefc71752703a26d79756767 Mon Sep 17 00:00:00 2001 From: Patricia Hillebrandt Date: Thu, 4 May 2023 12:43:49 +0200 Subject: [PATCH 05/12] update enqueue block assets --- src/Assets/AssetDataRegistry.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index 0014211cb34..0248817ca25 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,14 +66,7 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - // phpcs:ignore WordPress.Security.NonceVerification - if ( isset( $_GET['page'] ) && 'gutenberg-edit-site' === $_GET['page'] ) { - add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) ); - } else { - add_action( 'init', array( $this, 'register_data_script' ) ); - - } - + add_action( 'enqueue_block_assets', array( $this, 'register_data_script' ), 1 ); add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); } From e366216e9cc8952d8f3446efebd7c4a3bc078806 Mon Sep 17 00:00:00 2001 From: tjcafferkey Date: Thu, 4 May 2023 12:00:08 +0100 Subject: [PATCH 06/12] Run init action on non-site editor pages --- src/Assets/AssetDataRegistry.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index c0471453415..e19f8f7a92f 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,17 +66,30 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - // is_login() was introduced in 6.1 so lets check it exists before executing. - if ( ! is_admin() && function_exists( 'is_login' ) && ! is_login() ) { - add_action( 'init', array( $this, 'register_data_script' ) ); - } else { + if ( $this->is_site_editor() ) { add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) ); + } else { + add_action( 'init', array( $this, 'register_data_script' ) ); } add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); } + /** + * Checks if the current URL is the Site Editor. + * + * @return boolean + */ + protected function is_site_editor() { + // phpcs:ignore WordPress.Security.NonceVerification + if ( isset( $_GET['page'] ) && 'gutenberg-edit-site' === $_GET['page'] ) { + return true; + } + + return false; + } + /** * Exposes core data via the wcSettings global. This data is shared throughout the client. * From ee15cdb69b230efb5c9bc3ddec0c3b0a35f90cc6 Mon Sep 17 00:00:00 2001 From: Luigi Date: Thu, 4 May 2023 13:15:28 +0200 Subject: [PATCH 07/12] try now --- src/Assets/AssetDataRegistry.php | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index d7d2d315ee6..7e3ccb4cbe4 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,29 +66,12 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - if ( $this->is_site_editor() ) { - add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) ); - } else { - add_action( 'init', array( $this, 'register_data_script' ) ); - } + add_action( 'enqueue_block_assets', array( $this, 'register_data_script' ) ); + add_action( 'admin_enqueue_scripts', array( $this, 'register_data_script' ) ); add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); } - /** - * Checks if the current URL is the Site Editor. - * - * @return boolean - */ - protected function is_site_editor() { - // phpcs:ignore WordPress.Security.NonceVerification - if ( isset( $_GET['page'] ) && 'gutenberg-edit-site' === $_GET['page'] ) { - return true; - } - - return false; - } - /** * Exposes core data via the wcSettings global. This data is shared throughout the client. * From 784fa46bd2b134ec2e4e64c2c28f3e910fed5e62 Mon Sep 17 00:00:00 2001 From: Patricia Hillebrandt Date: Thu, 4 May 2023 13:29:53 +0200 Subject: [PATCH 08/12] Enqueue wc-settings early --- src/Assets/AssetDataRegistry.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index 7e3ccb4cbe4..3c4f0d95c7c 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,8 +66,7 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - add_action( 'enqueue_block_assets', array( $this, 'register_data_script' ) ); - add_action( 'admin_enqueue_scripts', array( $this, 'register_data_script' ) ); + add_action( 'enqueue_block_assets', array( $this, 'register_data_script' ), 1 ); add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); } @@ -348,6 +347,10 @@ public function register_page_id( $page_id ) { * @return void */ public function register_data_script() { + if ( ! wp_script_is( 'wc-settings', 'enqueued' ) ) { + wp_enqueue_script( 'wc-settings' ); + } + $this->api->register_script( $this->handle, 'build/wc-settings.js', From c84d3880d1afb719fbcfe66828bd408dde1f7946 Mon Sep 17 00:00:00 2001 From: tjcafferkey Date: Thu, 4 May 2023 12:33:25 +0100 Subject: [PATCH 09/12] Run init action on non-site editor pages --- src/Assets/AssetDataRegistry.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index 3c4f0d95c7c..6e20d51613a 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -66,11 +66,29 @@ public function __construct( Api $asset_api ) { * Hook into WP asset registration for enqueueing asset data. */ protected function init() { - add_action( 'enqueue_block_assets', array( $this, 'register_data_script' ), 1 ); + if ( $this->is_site_editor() ) { + add_action( 'enqueue_block_editor_assets', array( $this, 'register_data_script' ) ); + } else { + add_action( 'init', array( $this, 'register_data_script' ) ); + } add_action( 'wp_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); add_action( 'admin_print_footer_scripts', array( $this, 'enqueue_asset_data' ), 2 ); } + /** + * Checks if the current URL is the Site Editor. + * + * @return boolean + */ + protected function is_site_editor() { + $url_path = isset( $_SERVER['REQUEST_URI'] ) ?? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ); + if ( str_contains( $url_path, 'site-editor.php' ) !== false ) { + return true; + } + + return false; + } + /** * Exposes core data via the wcSettings global. This data is shared throughout the client. * From 850ab6eac36e76fa9b3bfe180b049e00a08c49a7 Mon Sep 17 00:00:00 2001 From: tjcafferkey Date: Thu, 4 May 2023 12:38:00 +0100 Subject: [PATCH 10/12] Refactor --- src/Assets/AssetDataRegistry.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index 6e20d51613a..cbb8b0cf7f0 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -81,12 +81,8 @@ protected function init() { * @return boolean */ protected function is_site_editor() { - $url_path = isset( $_SERVER['REQUEST_URI'] ) ?? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ); - if ( str_contains( $url_path, 'site-editor.php' ) !== false ) { - return true; - } - - return false; + $url_path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; + return str_contains( $url_path, 'site-editor.php' ); } /** From aaa2929d1409a0842b3740684f606198ee6cedc9 Mon Sep 17 00:00:00 2001 From: Patricia Hillebrandt Date: Thu, 4 May 2023 13:59:47 +0200 Subject: [PATCH 11/12] Ditch enqueue of 'wp-settings' --- patterns/product-listing-pattern.php | 132 +++++++++++++++++++++++++++ src/Assets/AssetDataRegistry.php | 4 - 2 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 patterns/product-listing-pattern.php diff --git a/patterns/product-listing-pattern.php b/patterns/product-listing-pattern.php new file mode 100644 index 00000000000..5673dc11f71 --- /dev/null +++ b/patterns/product-listing-pattern.php @@ -0,0 +1,132 @@ + + +
+ +
+ +
+ +
+ +
+
+
+ +
+ + + +
+ +
+ +

Unisex Leather Winter Jacket

+ + + +

With high-quality materials and expert craftsmanship, our products are built to last and exceed your expectations.

+ + + +
+ +
+ Shop now +
+ +
+ +
+ +
+ +
+ + + +
+ +
+ +
+ +
+ +
+ +
Quality Materials
+ + + +

We use only the highest-quality materials in our products, ensuring that they look great and last for years to come.

+ +
+ + + +
+ +
Expert Craftsmanship
+ + + +

Our products are made with expert craftsmanship and attention to detail, ensuring that every stitch and seam is perfect.

+ +
+ +
+ + + +
+ +
+ +
Unique Design
+ + + +

From bold prints and colors to intricate details and textures, our products are a perfect combination of style and function.

+ +
+ + + +
+ +
Customer Satisfaction
+ + + +

Our top priority is customer satisfaction, and we stand behind our products 100%.

+ +
+ +
+ +
+ +
+ + + +
+ +
+ +
+
+
+ +
+ +
+ +
+ diff --git a/src/Assets/AssetDataRegistry.php b/src/Assets/AssetDataRegistry.php index cbb8b0cf7f0..46494c2e174 100644 --- a/src/Assets/AssetDataRegistry.php +++ b/src/Assets/AssetDataRegistry.php @@ -361,10 +361,6 @@ public function register_page_id( $page_id ) { * @return void */ public function register_data_script() { - if ( ! wp_script_is( 'wc-settings', 'enqueued' ) ) { - wp_enqueue_script( 'wc-settings' ); - } - $this->api->register_script( $this->handle, 'build/wc-settings.js', From 7db5540a98ec12366873209a591a06deb02e41e4 Mon Sep 17 00:00:00 2001 From: Patricia Hillebrandt Date: Thu, 4 May 2023 14:01:36 +0200 Subject: [PATCH 12/12] Ditch the pattern --- patterns/product-listing-pattern.php | 132 --------------------------- 1 file changed, 132 deletions(-) delete mode 100644 patterns/product-listing-pattern.php diff --git a/patterns/product-listing-pattern.php b/patterns/product-listing-pattern.php deleted file mode 100644 index 5673dc11f71..00000000000 --- a/patterns/product-listing-pattern.php +++ /dev/null @@ -1,132 +0,0 @@ - - -
- -
- -
- -
- -
-
-
- -
- - - -
- -
- -

Unisex Leather Winter Jacket

- - - -

With high-quality materials and expert craftsmanship, our products are built to last and exceed your expectations.

- - - -
- -
- Shop now -
- -
- -
- -
- -
- - - -
- -
- -
- -
- -
- -
Quality Materials
- - - -

We use only the highest-quality materials in our products, ensuring that they look great and last for years to come.

- -
- - - -
- -
Expert Craftsmanship
- - - -

Our products are made with expert craftsmanship and attention to detail, ensuring that every stitch and seam is perfect.

- -
- -
- - - -
- -
- -
Unique Design
- - - -

From bold prints and colors to intricate details and textures, our products are a perfect combination of style and function.

- -
- - - -
- -
Customer Satisfaction
- - - -

Our top priority is customer satisfaction, and we stand behind our products 100%.

- -
- -
- -
- -
- - - -
- -
- -
-
-
- -
- -
- -
-