diff --git a/docs/testing/releases/721.md b/docs/testing/releases/721.md
new file mode 100644
index 00000000000..5481d3e7be7
--- /dev/null
+++ b/docs/testing/releases/721.md
@@ -0,0 +1,13 @@
+## Testing notes and ZIP for release 7.2.1
+
+Zip file for testing: [woocommerce-gutenberg-products-block.zip](https://github.com/woocommerce/woocommerce-gutenberg-products-block/files/8333094/woocommerce-gutenberg-products-block.zip)
+
+## Feature plugin and package inclusion in WooCommerce
+
+### Hide deprecation notices before headers are sent. [#6074](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/6074)
+
+1. Enable WooCommerce Payments or WooCommerce Subscriptions. It hasn't been updated with compatibility yet (I put in a PR a week ago).
+2. Enable WP_DEBUG mode
+3. Go to WP Admin. No notices are visible.
+4. Check the error log. See the notices there.
+5. Edit the code in this PR and remove the 7.4 from the function calls. Repeat steps 2-4 and confirm logs are used.
\ No newline at end of file
diff --git a/docs/testing/releases/README.md b/docs/testing/releases/README.md
index 35ed173f96d..98ea891544d 100644
--- a/docs/testing/releases/README.md
+++ b/docs/testing/releases/README.md
@@ -63,6 +63,7 @@ Every release includes specific testing instructions for new features and bug fi
- [7.0.0](./700.md)
- [7.1.0](./710.md)
- [7.2.0](./720.md)
+ - [7.2.1](./721.md)
diff --git a/package.json b/package.json
index 3b5c991d8d0..68a86423c85 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "@woocommerce/block-library",
"title": "WooCommerce Blocks",
"author": "Automattic",
- "version": "7.2.0",
+ "version": "7.2.1",
"description": "WooCommerce blocks for the Gutenberg editor.",
"homepage": "https://github.com/woocommerce/woocommerce-gutenberg-products-block/",
"keywords": [
diff --git a/readme.txt b/readme.txt
index 66c0ec6ed85..b4330c71f54 100644
--- a/readme.txt
+++ b/readme.txt
@@ -4,7 +4,7 @@ Tags: gutenberg, woocommerce, woo commerce, products, blocks, woocommerce blocks
Requires at least: 5.9
Tested up to: 5.9
Requires PHP: 7.0
-Stable tag: 7.2.0
+Stable tag: 7.2.1
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -85,6 +85,11 @@ Release and roadmap notes available on the [WooCommerce Developers Blog](https:/
== Changelog ==
+= 7.2.1 - 2022-03-23 =
+
+#### Bug fixes
+
+- Don't trigger class deprecations if headers are already sent [#6074](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/6074)
= 7.2.0 - 2022-03-14 =
#### Bug Fixes
diff --git a/src/Domain/Bootstrap.php b/src/Domain/Bootstrap.php
index 48d6baa4850..4effed5ec1d 100644
--- a/src/Domain/Bootstrap.php
+++ b/src/Domain/Bootstrap.php
@@ -264,33 +264,86 @@ function () {
$this->container->register(
'Automattic\WooCommerce\Blocks\StoreApi\Formatters',
function( Container $container ) {
- _deprecated_function( 'Automattic\WooCommerce\Blocks\StoreApi\Formatters', '7.2.0', 'Automattic\WooCommerce\StoreApi\Formatters' );
+ $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\Formatters', '7.2.0', 'Automattic\WooCommerce\StoreApi\Formatters', '7.4.0' );
return $container->get( StoreApi::class )::container()->get( \Automattic\WooCommerce\StoreApi\Formatters::class );
}
);
$this->container->register(
'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi',
function( Container $container ) {
- _deprecated_function( 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi', '7.2.0', 'Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema' );
+ $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\Domain\Services\ExtendRestApi', '7.2.0', 'Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema', '7.4.0' );
return $container->get( StoreApi::class )::container()->get( \Automattic\WooCommerce\StoreApi\Schemas\ExtendSchema::class );
}
);
$this->container->register(
'Automattic\WooCommerce\Blocks\StoreApi\SchemaController',
function( Container $container ) {
- _deprecated_function( 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController', '7.2.0', 'Automattic\WooCommerce\StoreApi\SchemaController' );
+ $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\SchemaController', '7.2.0', 'Automattic\WooCommerce\StoreApi\SchemaController', '7.4.0' );
return $container->get( StoreApi::class )::container()->get( SchemaController::class );
}
);
$this->container->register(
'Automattic\WooCommerce\Blocks\StoreApi\RoutesController',
function( Container $container ) {
- _deprecated_function( 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController', '7.2.0', 'Automattic\WooCommerce\StoreApi\RoutesController' );
+ $this->deprecated_dependency( 'Automattic\WooCommerce\Blocks\StoreApi\RoutesController', '7.2.0', 'Automattic\WooCommerce\StoreApi\RoutesController', '7.4.0' );
return $container->get( StoreApi::class )::container()->get( RoutesController::class );
}
);
}
+ /**
+ * Throws a deprecation notice for a dependency without breaking requests.
+ *
+ * @param string $function Class or function being deprecated.
+ * @param string $version Version in which it was deprecated.
+ * @param string $replacement Replacement class or function, if applicable.
+ * @param string $trigger_error_version Optional version to start surfacing this as a PHP error rather than a log. Defaults to $version.
+ */
+ protected function deprecated_dependency( $function, $version, $replacement = '', $trigger_error_version = '' ) {
+ if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) {
+ return;
+ }
+
+ $trigger_error_version = $trigger_error_version ? $trigger_error_version : $version;
+ $error_message = $replacement ? sprintf(
+ '%1$s is deprecated since version %2$s! Use %3$s instead.',
+ $function,
+ $version,
+ $replacement
+ ) : sprintf(
+ '%1$s is deprecated since version %2$s with no alternative available.',
+ $function,
+ $version
+ );
+
+ do_action( 'deprecated_function_run', $function, $replacement, $version );
+
+ $log_error = false;
+
+ // If headers have not been sent yet, log to avoid breaking the request.
+ if ( ! headers_sent() ) {
+ $log_error = true;
+ }
+
+ // If the $trigger_error_version was not yet reached, only log the error.
+ if ( version_compare( $this->package->get_version(), $trigger_error_version, '<' ) ) {
+ $log_error = true;
+ }
+
+ // Apply same filter as WP core.
+ if ( ! apply_filters( 'deprecated_function_trigger_error', true ) ) {
+ $log_error = true;
+ }
+
+ if ( $log_error ) {
+ // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
+ error_log( $error_message );
+ } else {
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
+ trigger_error( $error_message, E_USER_DEPRECATED );
+ }
+ }
+
/**
* Register payment method integrations with the container.
*/
diff --git a/src/Package.php b/src/Package.php
index abf6eb6efdd..4756d7ce061 100644
--- a/src/Package.php
+++ b/src/Package.php
@@ -106,7 +106,7 @@ public static function container( $reset = false ) {
NewPackage::class,
function ( $container ) {
// leave for automated version bumping.
- $version = '7.2.0';
+ $version = '7.2.1';
return new NewPackage(
$version,
dirname( __DIR__ ),
diff --git a/woocommerce-gutenberg-products-block.php b/woocommerce-gutenberg-products-block.php
index 94588c5e992..ebfe6562914 100644
--- a/woocommerce-gutenberg-products-block.php
+++ b/woocommerce-gutenberg-products-block.php
@@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Blocks
* Plugin URI: https://github.com/woocommerce/woocommerce-gutenberg-products-block
* Description: WooCommerce blocks for the Gutenberg editor.
- * Version: 7.2.0
+ * Version: 7.2.1
* Author: Automattic
* Author URI: https://woocommerce.com
* Text Domain: woo-gutenberg-products-block