Only load 'productCount' and 'experimentalBlocksEnabled' settings in admin (#48152)
* Only load 'productCount' setting in admin * Only load 'experimentalBlocksEnabled' setting in admin * Add changelog file * Update WcBlocksConfig types
This commit is contained in:
parent
5fbfe25f58
commit
f9281ae895
|
@ -11,11 +11,11 @@ export type WordCountType =
|
|||
|
||||
export interface WcBlocksConfig {
|
||||
pluginUrl: string;
|
||||
productCount: number;
|
||||
productCount?: number;
|
||||
defaultAvatar: string;
|
||||
restApiRoutes: Record< string, string[] >;
|
||||
wordCountType: WordCountType;
|
||||
experimentalBlocksEnabled: boolean;
|
||||
experimentalBlocksEnabled?: boolean;
|
||||
}
|
||||
|
||||
export const blocksConfig = getSetting( 'wcBlocksConfig', {
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: tweak
|
||||
|
||||
Only load 'productCount' and 'experimentalBlocksEnabled' settings in admin
|
|
@ -435,27 +435,35 @@ abstract class AbstractBlock {
|
|||
}
|
||||
|
||||
if ( ! $this->asset_data_registry->exists( 'wcBlocksConfig' ) ) {
|
||||
$wc_blocks_config = [
|
||||
'pluginUrl' => plugins_url( '/', dirname( __DIR__, 2 ) ),
|
||||
'restApiRoutes' => [
|
||||
'/wc/store/v1' => array_keys( $this->get_routes_from_namespace( 'wc/store/v1' ) ),
|
||||
],
|
||||
'defaultAvatar' => get_avatar_url( 0, [ 'force_default' => true ] ),
|
||||
|
||||
/*
|
||||
* translators: If your word count is based on single characters (e.g. East Asian characters),
|
||||
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
|
||||
* Do not translate into your own language.
|
||||
*/
|
||||
'wordCountType' => _x( 'words', 'Word count type. Do not translate!', 'woocommerce' ),
|
||||
];
|
||||
if ( is_admin() && ! WC()->is_rest_api_request() ) {
|
||||
$wc_blocks_config = array_merge(
|
||||
$wc_blocks_config,
|
||||
[
|
||||
// Note that while we don't have a consolidated way of doing feature-flagging
|
||||
// we are borrowing from the WC Admin Features implementation. Also note we cannot
|
||||
// use the wcAdminFeatures global because it's not always enqueued in the context of blocks.
|
||||
'experimentalBlocksEnabled' => Features::is_enabled( 'experimental-blocks' ),
|
||||
'productCount' => array_sum( (array) wp_count_posts( 'product' ) ),
|
||||
]
|
||||
);
|
||||
}
|
||||
$this->asset_data_registry->add(
|
||||
'wcBlocksConfig',
|
||||
[
|
||||
// Note that while we don't have a consolidated way of doing feature-flagging
|
||||
// we are borrowing from the WC Admin Features implementation. Also note we cannot
|
||||
// use the wcAdminFeatures global because it's not always enqueued in the context of blocks.
|
||||
'experimentalBlocksEnabled' => Features::is_enabled( 'experimental-blocks' ),
|
||||
'pluginUrl' => plugins_url( '/', dirname( __DIR__, 2 ) ),
|
||||
'productCount' => array_sum( (array) wp_count_posts( 'product' ) ),
|
||||
'restApiRoutes' => [
|
||||
'/wc/store/v1' => array_keys( $this->get_routes_from_namespace( 'wc/store/v1' ) ),
|
||||
],
|
||||
'defaultAvatar' => get_avatar_url( 0, [ 'force_default' => true ] ),
|
||||
|
||||
/*
|
||||
* translators: If your word count is based on single characters (e.g. East Asian characters),
|
||||
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
|
||||
* Do not translate into your own language.
|
||||
*/
|
||||
'wordCountType' => _x( 'words', 'Word count type. Do not translate!', 'woocommerce' ),
|
||||
]
|
||||
$wc_blocks_config
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue