Enqueue beta features scripts on enqueue_scripts action instead of filter (https://github.com/woocommerce/woocommerce-admin/pull/6358)

* Change filter callback to enqueue_scripts action to safely enqueue scripts

* Add changelog

* Only load beta modal JS on advanced features settings tab
This commit is contained in:
louwie17 2021-02-18 16:38:58 -04:00 committed by GitHub
parent 3483f1930e
commit 58503834f7
2 changed files with 14 additions and 9 deletions

View File

@ -79,6 +79,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Dev: Remove Google fonts and material icons. #6343
- Add: Remove CES actions for adding and editing a product and editing an order #6355
- Dev: Add unit tests to Navigation's Container component. #6344
- Fix: Enqueue scripts called incorrectly in php unit tests #6358
== 2.0.0 02/05/2021 ==

View File

@ -36,7 +36,7 @@ class Features {
add_action( 'init', array( __CLASS__, 'load_features' ), 4 );
add_filter( 'woocommerce_get_sections_advanced', array( __CLASS__, 'add_features_section' ) );
add_filter( 'woocommerce_get_settings_advanced', array( __CLASS__, 'add_features_settings' ), 10, 2 );
add_filter( 'woocommerce_get_settings_advanced', array( __CLASS__, 'maybe_load_beta_features_modal' ), 10, 2 );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'maybe_load_beta_features_modal' ) );
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_scripts' ), 15 );
add_filter( 'admin_body_class', array( __CLASS__, 'add_admin_body_classes' ) );
add_filter( 'update_option_woocommerce_allow_tracking', array( __CLASS__, 'maybe_disable_features' ), 10, 2 );
@ -60,10 +60,10 @@ class Features {
$features = [];
$navigation_class = self::get_feature_class( 'navigation' );
$settings_class = self::get_feature_class( 'settings' );
$settings_class = self::get_feature_class( 'settings' );
if ( $navigation_class ) {
$features['navigation'] = $navigation_class::TOGGLE_OPTION_NAME;
$features['settings'] = $settings_class::TOGGLE_OPTION_NAME;
$features['settings'] = $settings_class::TOGGLE_OPTION_NAME;
}
return $features;
@ -232,14 +232,20 @@ class Features {
/**
* Conditionally loads the beta features tracking modal.
*
* @param array $settings Settings.
* @return array
* @param string $hook Page hook.
*/
public static function maybe_load_beta_features_modal( $settings ) {
public static function maybe_load_beta_features_modal( $hook ) {
if (
'woocommerce_page_wc-settings' !== $hook ||
! isset( $_GET['tab'] ) || 'advanced' !== $_GET['tab'] || // phpcs:ignore CSRF ok.
! isset( $_GET['section'] ) || 'features' !== $_GET['section'] // phpcs:ignore CSRF ok.
) {
return;
}
$tracking_enabled = get_option( 'woocommerce_allow_tracking', 'no' );
if ( 'yes' === $tracking_enabled ) {
return $settings;
return;
}
$rtl = is_rtl() ? '.rtl' : '';
@ -258,8 +264,6 @@ class Features {
Loader::get_file_version( 'js' ),
true
);
return $settings;
}
/**