1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* bitsy Theme Customizer. |
4
|
|
|
* |
5
|
|
|
* @package bitsy |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Add postMessage support for site title and description for the Theme Customizer. |
10
|
|
|
* |
11
|
|
|
* @param WP_Customize_Manager $wp_customize Theme Customizer object. |
12
|
|
|
*/ |
13
|
|
|
if ( ! function_exists( 'bitsy_customize_register' ) ) { |
14
|
|
|
/** |
15
|
|
|
* Register basic customizer support. |
16
|
|
|
* |
17
|
|
|
* @param object $wp_customize Customizer reference. |
18
|
|
|
*/ |
19
|
|
|
function bitsy_customize_register( $wp_customize ) { |
20
|
|
|
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; |
21
|
|
|
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; |
22
|
|
|
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; |
23
|
|
|
} |
24
|
|
|
} |
25
|
|
|
add_action( 'customize_register', 'bitsy_customize_register' ); |
26
|
|
|
|
27
|
|
|
if ( ! function_exists( 'bitsy_theme_customize_register' ) ) { |
28
|
|
|
/** |
29
|
|
|
* Register individual settings through customizer's API. |
30
|
|
|
* |
31
|
|
|
* @param WP_Customize_Manager $wp_customize Customizer reference. |
32
|
|
|
*/ |
33
|
|
|
function bitsy_theme_customize_register( $wp_customize ) { |
34
|
|
|
|
35
|
|
|
// Theme layout settings. |
36
|
|
|
$wp_customize->add_section( 'bitsy_theme_layout_options', array( |
37
|
|
|
'title' => __( 'Theme Layout Settings', 'spurs' ), |
38
|
|
|
'capability' => 'edit_theme_options', |
39
|
|
|
'description' => __( 'Container width and sidebar defaults', 'spurs' ), |
40
|
|
|
'priority' => 160, |
41
|
|
|
) ); |
42
|
|
|
|
43
|
|
|
//select sanitization function |
44
|
|
|
function bitsy_theme_slug_sanitize_select( $input, $setting ) { |
45
|
|
|
|
46
|
|
|
//input must be a slug: lowercase alphanumeric characters, dashes and underscores are allowed only |
47
|
|
|
$input = sanitize_key( $input ); |
|
|
|
|
48
|
|
|
|
49
|
|
|
//get the list of possible select options |
50
|
|
|
$choices = $setting->manager->get_control( $setting->id )->choices; |
51
|
|
|
|
52
|
|
|
//return input if valid or return default option |
53
|
|
|
return ( array_key_exists( $input, $choices ) ? $input : $setting->default ); |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$wp_customize->add_setting( 'bitsy_container_type', array( |
58
|
|
|
'default' => 'container', |
59
|
|
|
'type' => 'theme_mod', |
60
|
|
|
'sanitize_callback' => 'bitsy_theme_slug_sanitize_select', |
61
|
|
|
'capability' => 'edit_theme_options', |
62
|
|
|
) ); |
63
|
|
|
|
64
|
|
|
$wp_customize->add_control( |
65
|
|
|
new WP_Customize_Control( |
66
|
|
|
$wp_customize, |
67
|
|
|
'bitsy_container_type', array( |
68
|
|
|
'label' => __( 'Container Width', 'spurs' ), |
69
|
|
|
'description' => __( 'Use fixed or fluid container?', 'spurs' ), |
70
|
|
|
'section' => 'bitsy_theme_layout_options', |
71
|
|
|
'settings' => 'bitsy_container_type', |
72
|
|
|
'type' => 'select', |
73
|
|
|
'choices' => array( |
74
|
|
|
'container' => __( 'Fixed-width container', 'spurs' ), |
75
|
|
|
'container-fluid' => __( 'Full-width container', 'spurs' ), |
76
|
|
|
), |
77
|
|
|
'priority' => '10', |
78
|
|
|
) |
79
|
|
|
) ); |
|
|
|
|
80
|
|
|
|
81
|
|
|
$wp_customize->add_setting( 'bitsy_sidebar_position', array( |
82
|
|
|
'default' => 'right', |
83
|
|
|
'type' => 'theme_mod', |
84
|
|
|
'sanitize_callback' => 'sanitize_text_field', |
85
|
|
|
'capability' => 'edit_theme_options', |
86
|
|
|
) ); |
87
|
|
|
|
88
|
|
|
$wp_customize->add_control( |
89
|
|
|
new WP_Customize_Control( |
90
|
|
|
$wp_customize, |
91
|
|
|
'bitsy_sidebar_position', array( |
92
|
|
|
'label' => __( 'Default Sidebar Position', 'spurs' ), |
93
|
|
|
'description' => __( '<b>Applies to all pages and posts.</b> <br /> |
94
|
|
|
<b>Select:</b> right, left, both, or none. <br /> |
95
|
|
|
<b>Note:</b> you can override on individual pages.', |
96
|
|
|
'spurs' ), |
|
|
|
|
97
|
|
|
'section' => 'bitsy_theme_layout_options', |
98
|
|
|
'settings' => 'bitsy_sidebar_position', |
99
|
|
|
'type' => 'select', |
100
|
|
|
'sanitize_callback' => 'bitsy_theme_slug_sanitize_select', |
101
|
|
|
'choices' => array( |
102
|
|
|
'right' => __( 'Right sidebar', 'spurs' ), |
103
|
|
|
'left' => __( 'Left sidebar', 'spurs' ), |
104
|
|
|
'both' => __( 'Left & Right sidebars', 'spurs' ), |
105
|
|
|
'none' => __( 'No sidebar', 'spurs' ), |
106
|
|
|
), |
107
|
|
|
'priority' => '20', |
108
|
|
|
) |
109
|
|
|
) ); |
|
|
|
|
110
|
|
|
} |
111
|
|
|
} // endif function_exists( 'bitsy_theme_customize_register' ). |
112
|
|
|
add_action( 'customize_register', 'bitsy_theme_customize_register' ); |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously. |
116
|
|
|
*/ |
117
|
|
|
if ( ! function_exists( 'bitsy_customize_preview_js' ) ) { |
118
|
|
|
/** |
119
|
|
|
* Setup JS integration for live previewing. |
120
|
|
|
*/ |
121
|
|
|
function bitsy_customize_preview_js() { |
122
|
|
|
wp_enqueue_script( 'bitsy_customizer', get_template_directory_uri() . '/js/customizer.js', |
123
|
|
|
array( 'customize-preview' ), '20130508', true ); |
|
|
|
|
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
add_action( 'customize_preview_init', 'bitsy_customize_preview_js' ); |