This repository has been archived by the owner on Jul 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
customizer.php
196 lines (166 loc) · 5.34 KB
/
customizer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
/**
* Theme Customizer
*
* @package Pocket
* @since Pocket 1.0
*/
add_action( 'customize_register', 'pocket_customizer_register' );
// Add CSS textarea
if( ! pocket_is_wpcom() ) {
if ( class_exists( 'WP_Customize_Control' ) && ! class_exists( 'Pocket_Textarea_Control' ) && ! pocket_is_wpcom() ) {
class Pocket_Textarea_Control extends WP_Customize_Control {
public $type = 'textarea';
public function render_content() {
?>
<label>
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
<textarea rows="8" style="width:100%; font-family: 'Courier 10 Pitch', Courier, monospace;" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
</label>
<?php
}
}
}
}
/**
* Sanitize strings
*/
function pocket_sanitize_text( $input ) {
return wp_kses_post( force_balance_tags( $input ) );
}
/**
* Sanitize grayscale image effect
*/
function pocket_sanitize_bw_select( $input ) {
$valid = array(
'disable' => __( 'Disable', 'pocket' ),
'enable' => __( 'Enable', 'pocket' ),
);
if ( array_key_exists( $input, $valid ) ) {
return $input;
} else {
return '';
}
}
/**
* Sanitize color scheme
*/
function pocket_sanitize_scheme_select( $input ) {
$valid = array(
'dark' => __( 'Dark', 'pocket' ),
'light' => __( 'Light', 'pocket' ),
);
if ( array_key_exists( $input, $valid ) ) {
return $input;
} else {
return '';
}
}
/**
* @param WP_Customize_Manager $wp_customize
*/
function pocket_customizer_register( $wp_customize ) {
// Pocket Style Options
$wp_customize->add_section( 'pocket_customizer_basic', array(
'title' => __( 'Theme Options', 'pocket' ),
'priority' => 1
) );
// Logo Image
$wp_customize->add_setting( 'pocket_customizer_logo', array() );
$wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'pocket_customizer_logo', array(
'label' => __( 'Logo Upload', 'pocket' ),
'section' => 'pocket_customizer_basic',
'settings' => 'pocket_customizer_logo'
) ) );
// Accent Color
if( ! pocket_is_wpcom() ) {
$wp_customize->add_setting( 'pocket_customizer_accent', array(
'default' => '#DD574C',
'sanitize_callback' => 'sanitize_hex_color',
) );
$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'pocket_customizer_accent', array(
'label' => __( 'Accent Color', 'pocket' ),
'section' => 'pocket_customizer_basic',
'settings' => 'pocket_customizer_accent'
) ) );
}
// Color Scheme
if( ! pocket_is_wpcom() ) {
$wp_customize->add_setting( 'pocket_customizer_color_scheme', array(
'default' => 'dark',
'capability' => 'edit_theme_options',
'type' => 'option',
'sanitize_callback' => 'pocket_sanitize_scheme_select'
));
$wp_customize->add_control( 'pocket_customizer_color_scheme_select', array(
'settings' => 'pocket_customizer_color_scheme',
'label' => __( 'Color Scheme', 'pocket' ),
'section' => 'pocket_customizer_basic',
'type' => 'select',
'choices' => array(
'dark' => __( 'Dark', 'pocket' ),
'light' => __( 'Light', 'pocket' ),
),
) );
}
// Featured Image Grayscale Effect
$wp_customize->add_setting( 'pocket_customizer_bw_image', array(
'default' => 'disable',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'pocket_sanitize_bw_select',
'type' => 'option',
));
$wp_customize->add_control( 'pocket_customizer_bw_image_select', array(
'settings' => 'pocket_customizer_bw_image',
'label' => __( 'Grayscale Featured Image Effect', 'pocket' ),
'section' => 'pocket_customizer_basic',
'type' => 'select',
'choices' => array(
'disable' => __( 'Disable', 'pocket' ),
'enable' => __( 'Enable', 'pocket' ),
),
));
// Custom CSS
if( ! pocket_is_wpcom() ) {
$wp_customize->add_setting( 'pocket_customizer_css', array(
'default' => '',
'sanitize_callback' => 'pocket_sanitize_text'
) );
$wp_customize->add_control( new Pocket_Textarea_Control( $wp_customize, 'pocket_customizer_css', array(
'label' => __( 'Custom CSS', 'pocket' ),
'section' => 'pocket_customizer_basic',
'settings' => 'pocket_customizer_css',
) ) );
}
/**
* Footer tagline
*/
$wp_customize->add_setting( 'pocket_footer_text', array(
'sanitize_callback' => 'pocket_sanitize_text',
'transport' => 'postMessage',
) );
$wp_customize->add_control( 'pocket_footer_text', array(
'label' => esc_html__( 'Footer Tagline', 'pocket' ),
'section' => 'pocket_customizer_basic',
'settings' => 'pocket_footer_text',
'type' => 'text',
'priority' => 20
)
);
}
/**
* Replaces the footer tagline text
*/
function pocket_filter_footer_text() {
// Get the footer copyright text
$footer_copy_text = get_theme_mod( 'pocket_footer_text' );
if ( $footer_copy_text ) {
// If we have footer text, use it
$footer_text = $footer_copy_text;
} else {
// Otherwise show the fallback theme text
$footer_text = '© ' . date("Y") . sprintf( esc_html__( ' %1$s Theme by %2$s.', 'pocket' ), 'Pocket', '<a href="https://arraythemes.com/" rel="nofollow">Array</a>' );
}
return $footer_text;
}
add_filter( 'pocket_footer_text', 'pocket_filter_footer_text' );