Merge pull request woocommerce/woocommerce-beta-tester#90 from woocommerce/fix/89

Load assets only inside Woo Beta Tester pages
This commit is contained in:
Ron Rennick 2021-02-08 15:37:07 -04:00 committed by GitHub
commit 9ba2b9b141
1 changed files with 11 additions and 6 deletions

View File

@ -23,17 +23,19 @@ class WC_Beta_Tester_Admin_Assets {
* Enqueue scripts. * Enqueue scripts.
*/ */
public function admin_scripts() { public function admin_scripts() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; $screen = get_current_screen();
$screen_id = $screen ? $screen->id : '';
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
$version = WC_VERSION;
// Need admin styles for the modal. // Need admin styles for the modal.
wp_register_style( 'wc-beta-tester-admin', WC_Beta_Tester::instance()->plugin_url() . '/assets/css/admin.css', array( 'woocommerce_admin_styles' ) ); wp_register_style( 'wc-beta-tester-admin', WC_Beta_Tester::instance()->plugin_url() . '/assets/css/admin.css', array( 'woocommerce_admin_styles' ) );
wp_enqueue_style( 'wc-beta-tester-admin' );
// Register scripts.
wp_register_script( 'wc-beta-tester-version-info', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-information' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION ); wp_register_script( 'wc-beta-tester-version-info', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-information' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION );
wp_register_script( 'wc-beta-tester-version-picker', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-picker' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION ); wp_register_script( 'wc-beta-tester-version-picker', WC_Beta_Tester::instance()->plugin_url() . '/assets/js/version-picker' . $suffix . '.js', array( 'wc-backbone-modal' ), WC_BETA_TESTER_VERSION );
$version = WC_VERSION;
wp_localize_script( wp_localize_script(
'wc-beta-tester-version-info', 'wc-beta-tester-version-info',
'wc_beta_tester_version_info_params', 'wc_beta_tester_version_info_params',
@ -52,8 +54,11 @@ class WC_Beta_Tester_Admin_Assets {
) )
); );
wp_enqueue_script( 'wc-beta-tester-version-info' ); if ( in_array( $screen_id, array( 'woocommerce_page_wc-beta-tester', 'woocommerce_page_wc-beta-tester-version-picker' ) ) ) {
wp_enqueue_script( 'wc-beta-tester-version-picker' ); wp_enqueue_style( 'wc-beta-tester-admin' );
wp_enqueue_script( 'wc-beta-tester-version-info' );
wp_enqueue_script( 'wc-beta-tester-version-picker' );
}
} }
} }