Completed
Push — master ( e65542...00af8d )
by Justin
06:54
created

wpsc-customizer.class.php ➔ wpsc_default_customizer_settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 11
rs 9.4285
1
<?php
2
3
/**
4
 * API for interfacing WP eCommerce settings with the Customizer
5
 *
6
 * @package WP eCommerce
7
 * @subpackage Customizer
8
 * @since 4.0
9
 */
10
11
/**
12
 * Class used to implement Customizer, and specifically Selective Refresh, functionality.
13
 *
14
 * @since 4.0
15
 */
16
17
class WPSC_Customizer {
18
19
    public $settings = array();
20
    public $sections = array();
21
22
    public function __construct() {
23
        $this->settings = apply_filters( 'wpsc_customizer_settings', $this->settings );
24
        $this->sections = apply_filters( 'wpsc_customizer_sections', $this->sections );
25
26
        $this->init();
27
    }
28
29
    private function init() {
30
        add_action( 'customize_register', array( $this, 'register_partials' ), 100 );
31
    }
32
33
    /**
34
     * Register selective refresh partial.
35
     *
36
     * @param \WP_Customize_Manager $wp_customize Manager.
37
     */
38
    public function register_partials( WP_Customize_Manager $wp_customize ) {
39
40
        if ( ! isset( $wp_customize->selective_refresh ) ) {
41
    		return;
42
    	}
43
44
        $wp_customize->add_panel( 'wpsc', array(
45
            'title'       => __( 'Store', 'wp-e-commerce' ),
46
            'description' => __( 'Presentational settings for your store.' ), // Include html tags such as <p>.
47
            'priority'    => 160, // Mixed with top-level-section hierarchy.
48
        ) );
49
50
        foreach ( $this->sections as $name => $label ) {
51
            $wp_customize->add_section( $name, array(
52
                'title' => $label,
53
                'panel' => 'wpsc',
54
            ) );
55
        }
56
57
        foreach ( $this->settings as $name => $setting ) {
58
59
            $wp_customize->selective_refresh->add_partial( $name, $setting );
60
        }
61
62
    }
63
}
64
65
function wpsc_default_customizer_settings( $settings ) {
66
    $settings['setting'] = array(
67
        array(
68
            'selector'            => '.site-description',
69
            'container_inclusive' => false,
70
            'render_callback'     => function() {
71
                    bloginfo( 'description' );
72
            }
73
        )
74
    );
75
}
76
77
add_filter( 'wpsc_customizer_settings', 'wpsc_default_customizer_settings' );
78
79
function wpsc_default_customizer_sections( $sections ) {
0 ignored issues
show
Unused Code introduced by
The parameter $sections is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
    return array(
81
        'general' => __( 'General', 'wp-e-commerce' ),
82
        'layout'  => __( 'Layout', 'wp-e-commerce' ),
83
    );
84
}
85
86
add_filter( 'wpsc_customizer_settings', 'wpsc_default_customizer_sections' );
87