Show settings only when needed #3165

This commit is contained in:
Mike Jolley 2013-08-02 12:27:31 +01:00
parent 54fa720768
commit 7dee74ba9e
2 changed files with 31 additions and 21 deletions

View File

@ -27,6 +27,8 @@ class WC_Settings_General extends WC_Settings_Page {
add_filter( 'woocommerce_settings_tabs_array', array( $this, 'add_settings_page' ), 20 );
add_action( 'woocommerce_settings_' . $this->id, array( $this, 'output' ) );
add_action( 'woocommerce_settings_save_' . $this->id, array( $this, 'save' ) );
if ( ( $styles = WC_Frontend_Scripts::get_styles() ) && array_key_exists( 'woocommerce-general', $styles ) )
add_action( 'woocommerce_admin_field_frontend_styles', array( $this, 'frontend_styles_setting' ) );
}

View File

@ -13,6 +13,33 @@ class WC_Frontend_Scripts {
add_filter( 'woocommerce_enqueue_styles', array( $this, 'backwards_compat' ) );
}
/**
* Get styles for the frontend
* @return array
*/
public static function get_styles() {
return apply_filters( 'woocommerce_enqueue_styles', array(
'woocommerce-layout' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-layout.css',
'deps' => '',
'version' => WOOCOMMERCE_VERSION,
'media' => ''
),
'woocommerce-smallscreen' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce-smallscreen.css',
'deps' => 'woocommerce-layout',
'version' => WOOCOMMERCE_VERSION,
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
),
'woocommerce-general' => array(
'src' => str_replace( array( 'http:', 'https:' ), '', WC()->plugin_url() ) . '/assets/css/woocommerce.css',
'deps' => '',
'version' => WOOCOMMERCE_VERSION,
'media' => ''
),
) );
}
/**
* Register/queue frontend scripts.
*
@ -119,26 +146,7 @@ class WC_Frontend_Scripts {
) ) );
// CSS Styles
$enqueue_styles = apply_filters( 'woocommerce_enqueue_styles', array(
'woocommerce-layout' => array(
'src' => $assets_path . 'css/woocommerce-layout.css',
'deps' => '',
'version' => WOOCOMMERCE_VERSION,
'media' => ''
),
'woocommerce-smallscreen' => array(
'src' => $assets_path . 'css/woocommerce-smallscreen.css',
'deps' => 'woocommerce-layout',
'version' => WOOCOMMERCE_VERSION,
'media' => 'only screen and (max-width: ' . apply_filters( 'woocommerce_style_smallscreen_breakpoint', $breakpoint = '768px' ) . ')'
),
'woocommerce-general' => array(
'src' => $assets_path . 'css/woocommerce.css',
'deps' => '',
'version' => WOOCOMMERCE_VERSION,
'media' => ''
),
) );
$enqueue_styles = $this->get_styles();
if ( $enqueue_styles )
foreach ( $enqueue_styles as $handle => $args )