Automattic\WooCommerce\Internal\Admin
WCAdminAssets::modify_script_dependencies
Modify script dependencies based on various conditions to only load the necessary scripts.
Method of the class: WCAdminAssets{}
No Hooks.
Returns
Array. Modified dependencies.
Usage
// private - for code of main (parent) class only $result = $this->modify_script_dependencies( $dependencies, $script );
- $dependencies(array) (required)
- Array of script dependencies.
- $script(string) (required)
- Script name.
WCAdminAssets::modify_script_dependencies() WCAdminAssets::modify script dependencies code WC 10.8.1
private function modify_script_dependencies( $dependencies, $script ) {
switch ( $script ) {
case WC_ADMIN_APP:
// Remove wp-editor dependency if we're not on a customize store page since we don't use wp-editor in other pages.
$is_customize_store_page = (
PageController::is_admin_page() &&
isset( $_GET['path'] ) && // phpcs:ignore WordPress.Security.NonceVerification.Recommended
str_starts_with( wc_clean( wp_unslash( $_GET['path'] ) ), '/customize-store' ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
);
if ( ! $is_customize_store_page ) {
$dependencies = array_diff( $dependencies, array( 'wp-editor' ) );
}
// Remove product editor dependency from WC_ADMIN_APP when feature is disabled.
if ( ! FeaturesUtil::feature_is_enabled( 'product_block_editor' ) ) {
$dependencies = array_diff( $dependencies, array( 'wc-product-editor' ) );
}
break;
case 'wc-product-editor':
// Remove wp-editor dependency if the product editor feature is disabled as we don't need it.
$is_product_data_view_page = \Automattic\WooCommerce\Admin\Features\ProductDataViews\Init::is_product_data_view_page();
if ( ! ( FeaturesUtil::feature_is_enabled( 'product_block_editor' ) || $is_product_data_view_page ) ) {
$dependencies = array_diff( $dependencies, array( 'wp-editor' ) );
}
break;
}
return $dependencies;
}