Skip to content

Commit

Permalink
First pass at implementing settings in Customizer. Incomplete. See #516.
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinSainton committed May 25, 2016
1 parent 95a52da commit 0d37263
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 21 deletions.
4 changes: 1 addition & 3 deletions wpsc-components/theme-engine-v2/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ function _wpsc_te_v2_includes() {
require_once( WPSC_THEME_ENGINE_V2_PATH . '/admin.php' );
}

if ( is_customize_preview() ) {
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-customizer.class.php' );
}
require_once( WPSC_FILE_PATH . '/wpsc-includes/wpsc-customizer.class.php' );

if ( ! is_admin() || ( is_admin() && defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
_wpsc_te2_mvc_init();
Expand Down
7 changes: 6 additions & 1 deletion wpsc-components/theme-engine-v2/helpers/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ function _wpsc_action_check_thumbnail_support() {
$crop
);

add_image_size( 'wpsc_product_cart_thumbnail', 64, 64, $crop );
add_image_size(
'wpsc_product_cart_thumbnail',
64,
64,
$crop
);
}

add_action( 'after_setup_theme', '_wpsc_action_check_thumbnail_support', 99 );
185 changes: 168 additions & 17 deletions wpsc-includes/wpsc-customizer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

/**
* Class used to implement Customizer, and specifically Selective Refresh, functionality.
* Class used to implement Customizer ( specifically Selective Refresh ) functionality.
*
* @since 4.0
*/
Expand All @@ -20,22 +20,23 @@ class WPSC_Customizer {
public $sections = array();

public function __construct() {

$this->settings = apply_filters( 'wpsc_customizer_settings', $this->settings );
$this->sections = apply_filters( 'wpsc_customizer_sections', $this->sections );

$this->init();
}

private function init() {
add_action( 'customize_register', array( $this, 'register_partials' ), 100 );
public function init() {
add_action( 'customize_register', array( $this, 'customizer' ), 100 );
}

/**
* Register selective refresh partial.
*
* @param \WP_Customize_Manager $wp_customize Manager.
*/
public function register_partials( WP_Customize_Manager $wp_customize ) {
public function customizer( WP_Customize_Manager $wp_customize ) {

if ( ! isset( $wp_customize->selective_refresh ) ) {
return;
Expand All @@ -54,33 +55,183 @@ public function register_partials( WP_Customize_Manager $wp_customize ) {
) );
}

foreach ( $this->settings as $name => $setting ) {
foreach ( $this->settings as $name => $settings ) {

$wp_customize->add_setting( $name, $settings['setting'] );

$wp_customize->selective_refresh->add_partial( $name, $setting );
$wp_customize->add_control( $name, $settings['control'] );

if ( isset( $settings['partial'] ) ) {
$wp_customize->selective_refresh->add_partial( $name, $settings['partial'] );
}
}

}
}

function wpsc_default_customizer_settings( $settings ) {
$settings['setting'] = array(
array(
'selector' => '.site-description',
'container_inclusive' => false,

$settings['wpsc_crop_thumbnails'] = array(
'control' => array(
'type' => 'checkbox',
'priority' => 10,
'section' => 'wpsc_thumbnails',
'label' => __( 'Crop Thumbnails' ),
'default' => false,
'description' => __( 'Crop images to the specified dimensions using center positions.' ),
),
'setting' => array(
'type' => 'option',
'capability' => 'manage_options',
'default' => false,
'sanitize_callback' => 'esc_attr',
)
);

// TODO: We need to create a custom control here for thumbnails...which means some modifications will be necessary.

/*
add_image_size(
'wpsc_product_single_thumbnail',
get_option( 'single_view_image_width' ),
get_option( 'single_view_image_height' ),
$crop
);
add_image_size(
'wpsc_product_archive_thumbnail',
get_option( 'product_image_width' ),
get_option( 'product_image_height' ),
$crop
);
add_image_size(
'wpsc_product_taxonomy_thumbnail',
get_option( 'category_image_width' ),
get_option( 'category_image_height' ),
$crop
);
*/

$settings['wpsc_products_per_row'] = array(
'control' => array(
'type' => 'number',
'priority' => 20,
'section' => 'wpsc_general',
'label' => __( 'Products Per Page' ),
'default' => get_option( 'posts_per_page' ),
'description' => __( 'Set the maximum number of products per page.', 'wp-e-commerce' ),
),
'setting' => array(
'type' => 'option',
'capability' => 'manage_options',
'default' => 'auto',
'sanitize_callback' => 'is_numeric',
),
'partial' => array(
'selector' => '#wpsc-products',
'render_callback' => function() {
bloginfo( 'description' );
}
wpsc_get_template_part( 'loop', 'products' );
}
)
);

$settings['wpsc_fancy_notifications'] = array(
'control' => array(
'type' => 'checkbox',
'priority' => 10,
'section' => 'wpsc_general',
'label' => __( 'Add to Cart Notifications' ),
'default' => false,
'description' => __( 'Enable Add to Cart notifications. When adding an item to your cart, this will create a popup notification for users.' ),
),
'setting' => array(
'type' => 'option',
'capability' => 'manage_options',
'default' => false,
'sanitize_callback' => 'esc_attr',
),
'partial' => array(
'selector' => '#wpsc-products',
'render_callback' => function() {
wpsc_get_template_part( 'loop', 'products' );
}
)
);

$settings['wpsc_layout'] = array(
'control' => array(
'type' => 'select',
'priority' => 10,
'section' => 'wpsc_layout',
'label' => __( 'Layout' ),
'default' => 'grid',
'description' => __( 'Change the layout of your store.' ),
'choices' => apply_filters( 'wpsc_layouts', array(
'grid' => __( 'Grid', 'wp-e-commerce' ),
'list' => __( 'List', 'wp-e-commerce' )
) )
),
'setting' => array(
'type' => 'option',
'capability' => 'manage_options',
'default' => 'grid',
'sanitize_callback' => 'sanitize_text_field',
),
'partial' => array(
'selector' => '#wpsc-products',
'render_callback' => function() {
wpsc_get_template_part( 'loop', 'products' );
}
)
);

$settings['wpsc_products_per_row'] = array(
'control' => array(
'type' => 'select',
'priority' => 12,
'section' => 'wpsc_layout',
'label' => __( 'Products Per Row' ),
'default' => 'auto',
'description' => __( 'Set the maximum number of products per row. Defaults to showing as many as will fit, up to six products per row', 'wp-e-commerce' ),
'choices' => apply_filters( 'wpsc_products_per_row_options', array(
'auto' => __( 'Automatic', 'wp-e-commerce' ),
'1' => __( '1', 'wp-e-commerce' ),
'2' => __( '2', 'wp-e-commerce' ),
'3' => __( '3', 'wp-e-commerce' ),
'4' => __( '4', 'wp-e-commerce' ),
'5' => __( '5', 'wp-e-commerce' ),
'6' => __( '6', 'wp-e-commerce' ),
) )
),
'setting' => array(
'type' => 'option',
'capability' => 'manage_options',
'default' => 'auto',
'sanitize_callback' => 'is_numeric',
),
'partial' => array(
'selector' => '#wpsc-products',
'render_callback' => function() {
wpsc_get_template_part( 'loop', 'products' );
}
)
);

return $settings;
}

add_filter( 'wpsc_customizer_settings', 'wpsc_default_customizer_settings' );

function wpsc_default_customizer_sections( $sections ) {
return array(
'general' => __( 'General', 'wp-e-commerce' ),
'layout' => __( 'Layout', 'wp-e-commerce' ),
);
return array_merge( array(
'wpsc_general' => __( 'General', 'wp-e-commerce' ),
'wpsc_layout' => __( 'Layout', 'wp-e-commerce' ),
'wpsc_thumbnails' => __( 'Thumbnails', 'wp-e-commerce' ),
), $sections );
}

add_filter( 'wpsc_customizer_settings', 'wpsc_default_customizer_sections' );
add_filter( 'wpsc_customizer_sections', 'wpsc_default_customizer_sections' );

$c = new WPSC_Customizer();
$c->init();

0 comments on commit 0d37263

Please sign in to comment.