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

Commit fc200a6

Browse files
authored
Add inline console warning if shared settings hook is consumed (#4143)
* Add inline console warning if shared settings hook is consumed * remove localisation on console string
1 parent 1cef921 commit fc200a6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/Assets/AssetDataRegistry.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,22 @@ protected function initialize_core_data() {
197197
* ->get( Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry::class )
198198
* ->add( $key, $value )
199199
*/
200-
$message = __(
201-
'The filter should not be used for assets registration. Please read woocommerce-gutenberg-products-block/docs/contributors/block-assets.md for more information on how to proceed.',
202-
'woo-gutenberg-products-block'
203-
);
200+
$settings = apply_filters( 'woocommerce_shared_settings', $this->data );
204201

205-
$settings = apply_filters_deprecated( 'woocommerce_shared_settings', [ $this->data ], '5.0.0', '', $message );
202+
// Surface a deprecation warning in the error console.
203+
if ( has_filter( 'woocommerce_shared_settings' ) ) {
204+
$error_handle = 'deprecated-shared-settings-error';
205+
$error_message = '`woocommerce_shared_settings` filter in Blocks is deprecated. See https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/trunk/docs/contributors/block-assets.md';
206+
// phpcs:ignore WordPress.WP.EnqueuedResourceParameters.NotInFooter,WordPress.WP.EnqueuedResourceParameters.MissingVersion
207+
wp_register_script( $error_handle, '' );
208+
wp_enqueue_script( $error_handle );
209+
wp_add_inline_script(
210+
$error_handle,
211+
sprintf( 'console.warn( "%s" );', $error_message )
212+
);
213+
}
206214

207-
// note this WILL wipe any data already registered to these keys because
208-
// they are protected.
215+
// note this WILL wipe any data already registered to these keys because they are protected.
209216
$this->data = array_replace_recursive( $settings, $this->get_core_data() );
210217
}
211218

0 commit comments

Comments
 (0)