|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Add Content section to the Theme Customizer. |
|
4
|
|
|
* |
|
5
|
|
|
* @param WP_Customize_Manager $wp_customize Theme Customizer object. |
|
6
|
|
|
*/ |
|
7
|
|
|
function jetpack_content_options_customize_register( $wp_customize ) { |
|
8
|
|
|
$options = get_theme_support( 'jetpack-content-options' ); |
|
9
|
|
|
$blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; |
|
10
|
|
|
$blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); |
|
11
|
|
|
sort( $blog_display ); |
|
12
|
|
|
$blog_display = implode( ', ', $blog_display ); |
|
13
|
|
|
$blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; |
|
14
|
|
|
$author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null; |
|
15
|
|
|
$author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1; |
|
16
|
|
|
$post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; |
|
17
|
|
|
$date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; |
|
18
|
|
|
$categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; |
|
19
|
|
|
$tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; |
|
20
|
|
|
$author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; |
|
21
|
|
|
$featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; |
|
22
|
|
|
$fi_archive = ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null; |
|
23
|
|
|
$fi_post = ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null; |
|
24
|
|
|
$fi_page = ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null; |
|
25
|
|
|
$fi_archive_default = ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1; |
|
26
|
|
|
$fi_post_default = ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1; |
|
27
|
|
|
$fi_page_default = ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1; |
|
28
|
|
|
|
|
29
|
|
|
// If the theme doesn't support 'jetpack-content-options[ 'blog-display' ]', 'jetpack-content-options[ 'author-bio' ]', 'jetpack-content-options[ 'post-details' ]' and 'jetpack-content-options[ 'featured-images' ]', don't continue. |
|
30
|
|
|
if ( ( ! in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ) ) ) |
|
31
|
|
|
&& ( true !== $author_bio ) |
|
32
|
|
|
&& ( ( empty( $post_details['stylesheet'] ) ) |
|
33
|
|
|
&& ( empty( $date ) |
|
34
|
|
|
|| empty( $categories ) |
|
35
|
|
|
|| empty( $tags ) |
|
36
|
|
|
|| empty( $author ) ) ) |
|
37
|
|
|
&& ( true !== $fi_archive && true !== $fi_post && true !== $fi_page ) ) { |
|
38
|
|
|
return; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// New control type: Title. |
|
42
|
|
|
class Jetpack_Customize_Control_Title extends WP_Customize_Control { |
|
43
|
|
|
public $type = 'title'; |
|
44
|
|
|
|
|
45
|
|
|
public function render_content() { |
|
46
|
|
|
?> |
|
47
|
|
|
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> |
|
48
|
|
|
<?php |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
// Add Content section. |
|
53
|
|
|
$wp_customize->add_section( 'jetpack_content_options', array( |
|
54
|
|
|
'title' => esc_html__( 'Content Options', 'jetpack' ), |
|
55
|
|
|
'theme_supports' => 'jetpack-content-options', |
|
56
|
|
|
'priority' => 100, |
|
57
|
|
|
) ); |
|
58
|
|
|
|
|
59
|
|
|
// Add Blog Display option. |
|
60
|
|
|
if ( in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ) ) ) { |
|
61
|
|
|
if ( 'mixed' === $blog_display ) { |
|
62
|
|
|
$blog_display_choices = array( |
|
63
|
|
|
'content' => esc_html__( 'Full post', 'jetpack' ), |
|
64
|
|
|
'excerpt' => esc_html__( 'Post excerpt', 'jetpack' ), |
|
65
|
|
|
'mixed' => esc_html__( 'Default', 'jetpack' ), |
|
66
|
|
|
); |
|
67
|
|
|
|
|
68
|
|
|
$blog_display_description = esc_html__( 'Choose between a full post or an excerpt for the blog and archive pages, or opt for the theme\'s default combination of excerpt and full post.', 'jetpack' ); |
|
69
|
|
|
} else { |
|
70
|
|
|
$blog_display_choices = array( |
|
71
|
|
|
'content' => esc_html__( 'Full post', 'jetpack' ), |
|
72
|
|
|
'excerpt' => esc_html__( 'Post excerpt', 'jetpack' ), |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$blog_display_description = esc_html__( 'Choose between a full post or an excerpt for the blog and archive pages.', 'jetpack' ); |
|
76
|
|
|
|
|
77
|
|
|
if ( 'mixed' === get_option( 'jetpack_content_blog_display' ) ) { |
|
78
|
|
|
update_option( 'jetpack_content_blog_display', $blog_display ); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
$wp_customize->add_setting( 'jetpack_content_blog_display', array( |
|
83
|
|
|
'default' => $blog_display, |
|
84
|
|
|
'type' => 'option', |
|
85
|
|
|
'transport' => 'postMessage', |
|
86
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_blog_display', |
|
87
|
|
|
) ); |
|
88
|
|
|
|
|
89
|
|
|
$wp_customize->add_control( 'jetpack_content_blog_display', array( |
|
90
|
|
|
'section' => 'jetpack_content_options', |
|
91
|
|
|
'label' => esc_html__( 'Blog Display', 'jetpack' ), |
|
92
|
|
|
'description' => $blog_display_description, |
|
93
|
|
|
'type' => 'radio', |
|
94
|
|
|
'choices' => $blog_display_choices, |
|
95
|
|
|
) ); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
// Add Author Bio option. |
|
99
|
|
|
if ( true === $author_bio ) { |
|
100
|
|
|
$wp_customize->add_setting( 'jetpack_content_author_bio_title' ); |
|
101
|
|
|
|
|
102
|
|
|
$wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_author_bio_title', array( |
|
103
|
|
|
'section' => 'jetpack_content_options', |
|
104
|
|
|
'label' => esc_html__( 'Author Bio', 'jetpack' ), |
|
105
|
|
|
'type' => 'title', |
|
106
|
|
|
) ) ); |
|
107
|
|
|
|
|
108
|
|
|
$wp_customize->add_setting( 'jetpack_content_author_bio', array( |
|
109
|
|
|
'default' => $author_bio_default, |
|
110
|
|
|
'type' => 'option', |
|
111
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
|
112
|
|
|
) ); |
|
113
|
|
|
|
|
114
|
|
|
$wp_customize->add_control( 'jetpack_content_author_bio', array( |
|
115
|
|
|
'section' => 'jetpack_content_options', |
|
116
|
|
|
'label' => esc_html__( 'Display on single posts', 'jetpack' ), |
|
117
|
|
|
'type' => 'checkbox', |
|
118
|
|
|
) ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
// Add Post Details options. |
|
122
|
|
|
if ( ( ! empty( $post_details ) ) |
|
123
|
|
|
&& ( ! empty( $post_details['stylesheet'] ) ) |
|
124
|
|
|
&& ( ! empty( $date ) |
|
125
|
|
|
|| ! empty( $categories ) |
|
126
|
|
|
|| ! empty( $tags ) |
|
127
|
|
|
|| ! empty( $author ) ) ) { |
|
128
|
|
|
$wp_customize->add_setting( 'jetpack_content_post_details_title' ); |
|
129
|
|
|
|
|
130
|
|
|
$wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_post_details_title', array( |
|
131
|
|
|
'section' => 'jetpack_content_options', |
|
132
|
|
|
'label' => esc_html__( 'Post Details', 'jetpack' ), |
|
133
|
|
|
'type' => 'title', |
|
134
|
|
|
) ) ); |
|
135
|
|
|
|
|
136
|
|
|
// Post Details: Date |
|
137
|
|
View Code Duplication |
if ( ! empty( $date ) ) { |
|
138
|
|
|
$wp_customize->add_setting( 'jetpack_content_post_details_date', array( |
|
139
|
|
|
'default' => 1, |
|
140
|
|
|
'type' => 'option', |
|
141
|
|
|
'transport' => 'postMessage', |
|
142
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
|
143
|
|
|
) ); |
|
144
|
|
|
|
|
145
|
|
|
$wp_customize->add_control( 'jetpack_content_post_details_date', array( |
|
146
|
|
|
'section' => 'jetpack_content_options', |
|
147
|
|
|
'label' => esc_html__( 'Display date', 'jetpack' ), |
|
148
|
|
|
'type' => 'checkbox', |
|
149
|
|
|
) ); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
// Post Details: Categories |
|
153
|
|
View Code Duplication |
if ( ! empty( $categories ) ) { |
|
154
|
|
|
$wp_customize->add_setting( 'jetpack_content_post_details_categories', array( |
|
155
|
|
|
'default' => 1, |
|
156
|
|
|
'type' => 'option', |
|
157
|
|
|
'transport' => 'postMessage', |
|
158
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
|
159
|
|
|
) ); |
|
160
|
|
|
|
|
161
|
|
|
$wp_customize->add_control( 'jetpack_content_post_details_categories', array( |
|
162
|
|
|
'section' => 'jetpack_content_options', |
|
163
|
|
|
'label' => esc_html__( 'Display categories', 'jetpack' ), |
|
164
|
|
|
'type' => 'checkbox', |
|
165
|
|
|
) ); |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
// Post Details: Tags |
|
169
|
|
View Code Duplication |
if ( ! empty( $tags ) ) { |
|
170
|
|
|
$wp_customize->add_setting( 'jetpack_content_post_details_tags', array( |
|
171
|
|
|
'default' => 1, |
|
172
|
|
|
'type' => 'option', |
|
173
|
|
|
'transport' => 'postMessage', |
|
174
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
|
175
|
|
|
) ); |
|
176
|
|
|
|
|
177
|
|
|
$wp_customize->add_control( 'jetpack_content_post_details_tags', array( |
|
178
|
|
|
'section' => 'jetpack_content_options', |
|
179
|
|
|
'label' => esc_html__( 'Display tags', 'jetpack' ), |
|
180
|
|
|
'type' => 'checkbox', |
|
181
|
|
|
) ); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
// Post Details: Author |
|
185
|
|
View Code Duplication |
if ( ! empty( $author ) ) { |
|
186
|
|
|
$wp_customize->add_setting( 'jetpack_content_post_details_author', array( |
|
187
|
|
|
'default' => 1, |
|
188
|
|
|
'type' => 'option', |
|
189
|
|
|
'transport' => 'postMessage', |
|
190
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
|
191
|
|
|
) ); |
|
192
|
|
|
|
|
193
|
|
|
$wp_customize->add_control( 'jetpack_content_post_details_author', array( |
|
194
|
|
|
'section' => 'jetpack_content_options', |
|
195
|
|
|
'label' => esc_html__( 'Display author', 'jetpack' ), |
|
196
|
|
|
'type' => 'checkbox', |
|
197
|
|
|
) ); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
|
|
201
|
|
|
// Add Featured Images options. |
|
202
|
|
|
if ( true === $fi_archive || true === $fi_post || true === $fi_page ) { |
|
203
|
|
|
$wp_customize->add_setting( 'jetpack_content_featured_images_title' ); |
|
204
|
|
|
|
|
205
|
|
|
$wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_featured_images_title', array( |
|
206
|
|
|
'section' => 'jetpack_content_options', |
|
207
|
|
|
'label' => esc_html__( 'Featured Images', 'jetpack' ), |
|
208
|
|
|
'type' => 'title', |
|
209
|
|
|
) ) ); |
|
210
|
|
|
|
|
211
|
|
|
// Featured Images: Archive |
|
212
|
|
View Code Duplication |
if ( true === $fi_archive ) { |
|
213
|
|
|
$wp_customize->add_setting( 'jetpack_content_featured_images_archive', array( |
|
214
|
|
|
'default' => $fi_archive_default, |
|
215
|
|
|
'type' => 'option', |
|
216
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
|
217
|
|
|
) ); |
|
218
|
|
|
|
|
219
|
|
|
$wp_customize->add_control( 'jetpack_content_featured_images_archive', array( |
|
220
|
|
|
'section' => 'jetpack_content_options', |
|
221
|
|
|
'label' => esc_html__( 'Display on blog and archives', 'jetpack' ), |
|
222
|
|
|
'type' => 'checkbox', |
|
223
|
|
|
) ); |
|
224
|
|
|
} |
|
225
|
|
|
|
|
226
|
|
|
// Featured Images: Post |
|
227
|
|
View Code Duplication |
if ( true === $fi_post ) { |
|
228
|
|
|
$wp_customize->add_setting( 'jetpack_content_featured_images_post', array( |
|
229
|
|
|
'default' => $fi_post_default, |
|
230
|
|
|
'type' => 'option', |
|
231
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
|
232
|
|
|
) ); |
|
233
|
|
|
|
|
234
|
|
|
$wp_customize->add_control( 'jetpack_content_featured_images_post', array( |
|
235
|
|
|
'section' => 'jetpack_content_options', |
|
236
|
|
|
'label' => esc_html__( 'Display on single posts', 'jetpack' ), |
|
237
|
|
|
'type' => 'checkbox', |
|
238
|
|
|
) ); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
// Featured Images: Page |
|
242
|
|
View Code Duplication |
if ( true === $fi_page ) { |
|
243
|
|
|
$wp_customize->add_setting( 'jetpack_content_featured_images_page', array( |
|
244
|
|
|
'default' => $fi_page_default, |
|
245
|
|
|
'type' => 'option', |
|
246
|
|
|
'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
|
247
|
|
|
) ); |
|
248
|
|
|
|
|
249
|
|
|
$wp_customize->add_control( 'jetpack_content_featured_images_page', array( |
|
250
|
|
|
'section' => 'jetpack_content_options', |
|
251
|
|
|
'label' => esc_html__( 'Display on pages', 'jetpack' ), |
|
252
|
|
|
'type' => 'checkbox', |
|
253
|
|
|
) ); |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
} |
|
257
|
|
|
add_action( 'customize_register', 'jetpack_content_options_customize_register' ); |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Sanitize the checkbox. |
|
261
|
|
|
* |
|
262
|
|
|
* @param int $input. |
|
|
|
|
|
|
263
|
|
|
* @return boolean|string |
|
264
|
|
|
*/ |
|
265
|
|
|
function jetpack_content_options_sanitize_checkbox( $input ) { |
|
266
|
|
|
return ( 1 == $input ) ? 1 : ''; |
|
267
|
|
|
} |
|
268
|
|
|
|
|
269
|
|
|
/** |
|
270
|
|
|
* Sanitize the Display value. |
|
271
|
|
|
* |
|
272
|
|
|
* @param string $display. |
|
|
|
|
|
|
273
|
|
|
* @return string. |
|
|
|
|
|
|
274
|
|
|
*/ |
|
275
|
|
|
function jetpack_content_options_sanitize_blog_display( $display ) { |
|
276
|
|
|
if ( ! in_array( $display, array( 'content', 'excerpt', 'mixed' ) ) ) { |
|
277
|
|
|
$display = 'content'; |
|
278
|
|
|
} |
|
279
|
|
|
return $display; |
|
280
|
|
|
} |
|
281
|
|
|
|
|
282
|
|
|
/** |
|
283
|
|
|
* Binds JS handlers to make Theme Customizer preview reload changes asynchronously. |
|
284
|
|
|
*/ |
|
285
|
|
|
function jetpack_content_options_customize_preview_js() { |
|
286
|
|
|
$options = get_theme_support( 'jetpack-content-options' ); |
|
287
|
|
|
$blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; |
|
288
|
|
|
$blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); |
|
289
|
|
|
sort( $blog_display ); |
|
290
|
|
|
$blog_display = implode( ', ', $blog_display ); |
|
291
|
|
|
$blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; |
|
292
|
|
|
$masonry = ( ! empty( $options[0]['masonry'] ) ) ? $options[0]['masonry'] : null; |
|
293
|
|
|
$post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; |
|
294
|
|
|
$date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; |
|
295
|
|
|
$categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; |
|
296
|
|
|
$tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; |
|
297
|
|
|
$author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; |
|
298
|
|
|
|
|
299
|
|
|
wp_enqueue_script( 'jetpack-content-options-customizer', plugins_url( 'customizer.js', __FILE__ ), array( 'customize-preview' ), '1.0', true ); |
|
300
|
|
|
|
|
301
|
|
|
wp_localize_script( 'jetpack-content-options-customizer', 'blogDisplay', array( |
|
302
|
|
|
'display' => get_option( 'jetpack_content_blog_display', $blog_display ), |
|
303
|
|
|
'masonry' => $masonry, |
|
304
|
|
|
) ); |
|
305
|
|
|
|
|
306
|
|
|
wp_localize_script( 'jetpack-content-options-customizer', 'postDetails', array( |
|
307
|
|
|
'date' => $date, |
|
308
|
|
|
'categories' => $categories, |
|
309
|
|
|
'tags' => $tags, |
|
310
|
|
|
'author' => $author, |
|
311
|
|
|
) ); |
|
312
|
|
|
} |
|
313
|
|
|
add_action( 'customize_preview_init', 'jetpack_content_options_customize_preview_js' ); |
|
314
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.