Add features section and settings (https://github.com/woocommerce/woocommerce-admin/pull/5381)
* Add features section and settings * Force page refresh on option update
This commit is contained in:
parent
84e006cc62
commit
0809b07254
|
@ -22,6 +22,7 @@ class Navigation {
|
|||
public function __construct() {
|
||||
add_filter( 'woocommerce_admin_preload_options', array( $this, 'preload_options' ) );
|
||||
add_filter( 'woocommerce_admin_features', array( $this, 'maybe_remove_nav_feature' ), 0 );
|
||||
add_action( 'update_option_woocommerce_navigation_enabled', array( $this, 'reload_page_on_toggle' ), 10, 2 );
|
||||
|
||||
if ( Loader::is_feature_enabled( 'navigation' ) ) {
|
||||
add_action( 'in_admin_header', array( __CLASS__, 'embed_navigation' ) );
|
||||
|
@ -88,4 +89,20 @@ class Navigation {
|
|||
Loader::get_file_version( 'css' )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the page when the option is toggled to make sure all nav features are loaded.
|
||||
*
|
||||
* @param string $old_value Old value.
|
||||
* @param string $value New value.
|
||||
*/
|
||||
public static function reload_page_on_toggle( $old_value, $value ) {
|
||||
if ( $old_value === $value ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
|
||||
wp_safe_redirect( wp_unslash( $_SERVER['REQUEST_URI'] ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,8 @@ class Loader {
|
|||
add_action( 'init', array( __CLASS__, 'define_tables' ) );
|
||||
// Load feature before WooCommerce update hooks.
|
||||
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_action( 'admin_enqueue_scripts', array( __CLASS__, 'register_scripts' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'inject_wc_settings_dependencies' ), 14 );
|
||||
add_action( 'admin_enqueue_scripts', array( __CLASS__, 'load_scripts' ), 15 );
|
||||
|
@ -232,6 +234,52 @@ class Loader {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Features section to the advanced tab of WooCommerce Settings
|
||||
*
|
||||
* @param array $sections Sections.
|
||||
* @return array
|
||||
*/
|
||||
public static function add_features_section( $sections ) {
|
||||
$sections['features'] = __( 'Features', 'woocommerce-admin' );
|
||||
return $sections;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the Features settings.
|
||||
*
|
||||
* @param array $settings Settings.
|
||||
* @param string $current_section Current section slug.
|
||||
* @return array
|
||||
*/
|
||||
public static function add_features_settings( $settings, $current_section ) {
|
||||
if ( 'features' !== $current_section ) {
|
||||
return $settings;
|
||||
}
|
||||
|
||||
return apply_filters(
|
||||
'woocommerce_settings_features',
|
||||
array(
|
||||
array(
|
||||
'title' => __( 'Features', 'woocommerce-admin' ),
|
||||
'type' => 'title',
|
||||
'desc' => __( 'Start using new features that are being progressively rolled out to improve the store management experience.', 'woocommerce-admin' ),
|
||||
'id' => 'features_options',
|
||||
),
|
||||
array(
|
||||
'title' => __( 'Navigation', 'woocommerce-admin' ),
|
||||
'desc' => __( 'Adds the new WooCommerce navigation experience to the dashboard', 'woocommerce-admin' ),
|
||||
'id' => 'woocommerce_navigation_enabled',
|
||||
'type' => 'checkbox',
|
||||
),
|
||||
array(
|
||||
'type' => 'sectionend',
|
||||
'id' => 'features_options',
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects existing WooCommerce pages.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue