← All changes
|
modules/theme-tools/content-options/customizer.php
+442
-401
13.2.4
→
16.3-a.1
View file →
| @@ -4,495 +4,536 @@ | ||
| 4 | 4 | * |
| 5 | 5 | * @package automattic/jetpack |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | -/** | |
| 9 | - * Add Content section to the Theme Customizer. | |
| 10 | - * | |
| 11 | - * @param WP_Customize_Manager $wp_customize Theme Customizer object. | |
| 12 | - */ | |
| 13 | -function jetpack_content_options_customize_register( $wp_customize ) { | |
| 14 | - $options = get_theme_support( 'jetpack-content-options' ); | |
| 15 | - $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; | |
| 16 | - $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); | |
| 17 | - sort( $blog_display ); | |
| 18 | - $blog_display = implode( ', ', $blog_display ); | |
| 19 | - $blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; | |
| 20 | - $author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null; | |
| 21 | - $author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1; | |
| 22 | - $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; | |
| 23 | - $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; | |
| 24 | - $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; | |
| 25 | - $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; | |
| 26 | - $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; | |
| 27 | - $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; | |
| 28 | - $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; | |
| 29 | - $fi_archive = ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null; | |
| 30 | - $fi_post = ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null; | |
| 31 | - $fi_page = ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null; | |
| 32 | - $fi_portfolio = ( ! empty( $featured_images['portfolio'] ) ) ? $featured_images['portfolio'] : null; | |
| 33 | - $fi_fallback = ( ! empty( $featured_images['fallback'] ) ) ? $featured_images['fallback'] : null; | |
| 34 | - $fi_archive_default = ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1; | |
| 35 | - $fi_post_default = ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1; | |
| 36 | - $fi_page_default = ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1; | |
| 37 | - $fi_portfolio_default = ( isset( $featured_images['portfolio-default'] ) && false === $featured_images['portfolio-default'] ) ? '' : 1; | |
| 38 | - $fi_fallback_default = ( isset( $featured_images['fallback-default'] ) && false === $featured_images['fallback-default'] ) ? '' : 1; | |
| 8 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 9 | + exit( 0 ); | |
| 10 | +} | |
| 39 | 11 | |
| 40 | - // 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. | |
| 41 | - if ( ( ! in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ), true ) ) | |
| 42 | - && ( true !== $author_bio ) | |
| 43 | - && ( ( empty( $post_details['stylesheet'] ) ) | |
| 44 | - && ( empty( $date ) | |
| 45 | - || empty( $categories ) | |
| 46 | - || empty( $tags ) | |
| 47 | - || empty( $author ) | |
| 48 | - || empty( $comment ) ) ) | |
| 49 | - && ( true !== $fi_archive && true !== $fi_post && true !== $fi_page && true !== $fi_portfolio && true !== $fi_fallback ) ) { | |
| 50 | - return; | |
| 51 | - } | |
| 12 | +if ( ! function_exists( 'jetpack_content_options_customize_register' ) ) { | |
| 52 | 13 | |
| 53 | 14 | /** |
| 54 | - * New Customizer control type: Title. | |
| 15 | + * Add Content section to the Theme Customizer. | |
| 16 | + * | |
| 17 | + * @deprecated 13.9 Moved to Classic Theme Helper package. | |
| 18 | + * | |
| 19 | + * @param WP_Customize_Manager $wp_customize Theme Customizer object. | |
| 55 | 20 | */ |
| 56 | - class Jetpack_Customize_Control_Title extends WP_Customize_Control { | |
| 57 | - /** | |
| 58 | - * Customizer control type. | |
| 59 | - * | |
| 60 | - * @var string | |
| 61 | - */ | |
| 62 | - public $type = 'title'; | |
| 21 | + function jetpack_content_options_customize_register( $wp_customize ) { | |
| 22 | + _deprecated_function( __FUNCTION__, 'jetpack-13.9' ); | |
| 23 | + $options = get_theme_support( 'jetpack-content-options' ); | |
| 24 | + $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; | |
| 25 | + $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); | |
| 26 | + sort( $blog_display ); | |
| 27 | + $blog_display = implode( ', ', $blog_display ); | |
| 28 | + $blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; | |
| 29 | + $author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null; | |
| 30 | + $author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1; | |
| 31 | + $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; | |
| 32 | + $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; | |
| 33 | + $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; | |
| 34 | + $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; | |
| 35 | + $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; | |
| 36 | + $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; | |
| 37 | + $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; | |
| 38 | + $fi_archive = ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null; | |
| 39 | + $fi_post = ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null; | |
| 40 | + $fi_page = ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null; | |
| 41 | + $fi_portfolio = ( ! empty( $featured_images['portfolio'] ) ) ? $featured_images['portfolio'] : null; | |
| 42 | + $fi_fallback = ( ! empty( $featured_images['fallback'] ) ) ? $featured_images['fallback'] : null; | |
| 43 | + $fi_archive_default = ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1; | |
| 44 | + $fi_post_default = ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1; | |
| 45 | + $fi_page_default = ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1; | |
| 46 | + $fi_portfolio_default = ( isset( $featured_images['portfolio-default'] ) && false === $featured_images['portfolio-default'] ) ? '' : 1; | |
| 47 | + $fi_fallback_default = ( isset( $featured_images['fallback-default'] ) && false === $featured_images['fallback-default'] ) ? '' : 1; | |
| 63 | 48 | |
| 64 | - /** | |
| 65 | - * Render the control's content. | |
| 66 | - */ | |
| 67 | - public function render_content() { // phpcs:ignore MediaWiki.Usage.NestedFunctions.NestedFunction | |
| 68 | - ?> | |
| 69 | - <span class="customize-control-title"><?php echo wp_kses_post( $this->label ); ?></span> | |
| 70 | - <?php | |
| 49 | + // 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. | |
| 50 | + if ( ( ! in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ), true ) ) | |
| 51 | + && ( true !== $author_bio ) | |
| 52 | + && ( ( empty( $post_details['stylesheet'] ) ) | |
| 53 | + && ( empty( $date ) | |
| 54 | + || empty( $categories ) | |
| 55 | + || empty( $tags ) | |
| 56 | + || empty( $author ) | |
| 57 | + || empty( $comment ) ) ) | |
| 58 | + && ( true !== $fi_archive && true !== $fi_post && true !== $fi_page && true !== $fi_portfolio && true !== $fi_fallback ) ) { | |
| 59 | + return; | |
| 71 | 60 | } |
| 72 | - } | |
| 73 | 61 | |
| 74 | - // Add Content section. | |
| 75 | - $wp_customize->add_section( | |
| 76 | - 'jetpack_content_options', | |
| 77 | - array( | |
| 78 | - 'title' => esc_html__( 'Content Options', 'jetpack' ), | |
| 79 | - 'theme_supports' => 'jetpack-content-options', | |
| 80 | - 'priority' => 100, | |
| 81 | - ) | |
| 82 | - ); | |
| 62 | + if ( ! class_exists( 'Jetpack_Customize_Control_Title' ) ) { | |
| 83 | 63 | |
| 84 | - // Add Blog Display option. | |
| 85 | - if ( in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ), true ) ) { | |
| 86 | - if ( 'mixed' === $blog_display ) { | |
| 87 | - $blog_display_choices = array( | |
| 88 | - 'content' => esc_html__( 'Full post', 'jetpack' ), | |
| 89 | - 'excerpt' => esc_html__( 'Post excerpt', 'jetpack' ), | |
| 90 | - 'mixed' => esc_html__( 'Default', 'jetpack' ), | |
| 91 | - ); | |
| 64 | + /** | |
| 65 | + * New Customizer control type: Title. | |
| 66 | + */ | |
| 67 | + class Jetpack_Customize_Control_Title extends WP_Customize_Control { | |
| 68 | + /** | |
| 69 | + * Customizer control type. | |
| 70 | + * | |
| 71 | + * @var string | |
| 72 | + */ | |
| 73 | + public $type = 'title'; | |
| 92 | 74 | |
| 93 | - $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' ); | |
| 94 | - } else { | |
| 95 | - $blog_display_choices = array( | |
| 96 | - 'content' => esc_html__( 'Full post', 'jetpack' ), | |
| 97 | - 'excerpt' => esc_html__( 'Post excerpt', 'jetpack' ), | |
| 98 | - ); | |
| 75 | + /** | |
| 76 | + * Render the control's content. | |
| 77 | + */ | |
| 78 | + public function render_content() { | |
| 79 | + ?> | |
| 80 | + <span class="customize-control-title"><?php echo wp_kses_post( $this->label ); ?></span> | |
| 81 | + <?php | |
| 82 | + } | |
| 83 | + } | |
| 99 | 84 | |
| 100 | - $blog_display_description = esc_html__( 'Choose between a full post or an excerpt for the blog and archive pages.', 'jetpack' ); | |
| 101 | - | |
| 102 | - if ( 'mixed' === get_option( 'jetpack_content_blog_display' ) ) { | |
| 103 | - update_option( 'jetpack_content_blog_display', $blog_display ); | |
| 104 | - } | |
| 105 | 85 | } |
| 106 | 86 | |
| 107 | - $wp_customize->add_setting( | |
| 108 | - 'jetpack_content_blog_display', | |
| 87 | + // Add Content section. | |
| 88 | + $wp_customize->add_section( | |
| 89 | + 'jetpack_content_options', | |
| 109 | 90 | array( |
| 110 | - 'default' => $blog_display, | |
| 111 | - 'type' => 'option', | |
| 112 | - 'transport' => 'postMessage', | |
| 113 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_blog_display', | |
| 91 | + 'title' => esc_html__( 'Content Options', 'jetpack' ), | |
| 92 | + 'theme_supports' => 'jetpack-content-options', | |
| 93 | + 'priority' => 100, | |
| 114 | 94 | ) |
| 115 | 95 | ); |
| 116 | 96 | |
| 117 | - $wp_customize->add_control( | |
| 118 | - 'jetpack_content_blog_display', | |
| 119 | - array( | |
| 120 | - 'section' => 'jetpack_content_options', | |
| 121 | - 'label' => esc_html__( 'Blog Display', 'jetpack' ), | |
| 122 | - 'description' => $blog_display_description, | |
| 123 | - 'type' => 'radio', | |
| 124 | - 'choices' => $blog_display_choices, | |
| 125 | - ) | |
| 126 | - ); | |
| 127 | - } | |
| 97 | + // Add Blog Display option. | |
| 98 | + if ( in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ), true ) ) { | |
| 99 | + if ( 'mixed' === $blog_display ) { | |
| 100 | + $blog_display_choices = array( | |
| 101 | + 'content' => esc_html__( 'Full post', 'jetpack' ), | |
| 102 | + 'excerpt' => esc_html__( 'Post excerpt', 'jetpack' ), | |
| 103 | + 'mixed' => esc_html__( 'Default', 'jetpack' ), | |
| 104 | + ); | |
| 128 | 105 | |
| 129 | - // Add Author Bio option. | |
| 130 | - if ( true === $author_bio ) { | |
| 131 | - $wp_customize->add_setting( 'jetpack_content_author_bio_title' ); | |
| 106 | + $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' ); | |
| 107 | + } else { | |
| 108 | + $blog_display_choices = array( | |
| 109 | + 'content' => esc_html__( 'Full post', 'jetpack' ), | |
| 110 | + 'excerpt' => esc_html__( 'Post excerpt', 'jetpack' ), | |
| 111 | + ); | |
| 132 | 112 | |
| 133 | - $wp_customize->add_control( | |
| 134 | - new Jetpack_Customize_Control_Title( | |
| 135 | - $wp_customize, | |
| 136 | - 'jetpack_content_author_bio_title', | |
| 137 | - array( | |
| 138 | - 'section' => 'jetpack_content_options', | |
| 139 | - 'label' => esc_html__( 'Author Bio', 'jetpack' ), | |
| 140 | - 'type' => 'title', | |
| 141 | - ) | |
| 142 | - ) | |
| 143 | - ); | |
| 113 | + $blog_display_description = esc_html__( 'Choose between a full post or an excerpt for the blog and archive pages.', 'jetpack' ); | |
| 144 | 114 | |
| 145 | - $wp_customize->add_setting( | |
| 146 | - 'jetpack_content_author_bio', | |
| 147 | - array( | |
| 148 | - 'default' => $author_bio_default, | |
| 149 | - 'type' => 'option', | |
| 150 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 151 | - ) | |
| 152 | - ); | |
| 115 | + if ( 'mixed' === get_option( 'jetpack_content_blog_display' ) ) { | |
| 116 | + update_option( 'jetpack_content_blog_display', $blog_display ); | |
| 117 | + } | |
| 118 | + } | |
| 153 | 119 | |
| 154 | - $wp_customize->add_control( | |
| 155 | - 'jetpack_content_author_bio', | |
| 156 | - array( | |
| 157 | - 'section' => 'jetpack_content_options', | |
| 158 | - 'label' => esc_html__( 'Display on single posts', 'jetpack' ), | |
| 159 | - 'type' => 'checkbox', | |
| 160 | - ) | |
| 161 | - ); | |
| 162 | - } | |
| 163 | - | |
| 164 | - // Add Post Details options. | |
| 165 | - if ( ( ! empty( $post_details ) ) | |
| 166 | - && ( ! empty( $post_details['stylesheet'] ) ) | |
| 167 | - && ( ! empty( $date ) | |
| 168 | - || ! empty( $categories ) | |
| 169 | - || ! empty( $tags ) | |
| 170 | - || ! empty( $author ) | |
| 171 | - || ! empty( $comment ) ) ) { | |
| 172 | - $wp_customize->add_setting( 'jetpack_content_post_details_title' ); | |
| 173 | - | |
| 174 | - $wp_customize->add_control( | |
| 175 | - new Jetpack_Customize_Control_Title( | |
| 176 | - $wp_customize, | |
| 177 | - 'jetpack_content_post_details_title', | |
| 178 | - array( | |
| 179 | - 'section' => 'jetpack_content_options', | |
| 180 | - 'label' => esc_html__( 'Post Details', 'jetpack' ), | |
| 181 | - 'type' => 'title', | |
| 182 | - ) | |
| 183 | - ) | |
| 184 | - ); | |
| 185 | - | |
| 186 | - // Post Details: Date. | |
| 187 | - if ( ! empty( $date ) ) { | |
| 188 | 120 | $wp_customize->add_setting( |
| 189 | - 'jetpack_content_post_details_date', | |
| 121 | + 'jetpack_content_blog_display', | |
| 190 | 122 | array( |
| 191 | - 'default' => 1, | |
| 123 | + 'default' => $blog_display, | |
| 192 | 124 | 'type' => 'option', |
| 193 | 125 | 'transport' => 'postMessage', |
| 194 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 126 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_blog_display', | |
| 195 | 127 | ) |
| 196 | 128 | ); |
| 197 | 129 | |
| 198 | 130 | $wp_customize->add_control( |
| 199 | - 'jetpack_content_post_details_date', | |
| 131 | + 'jetpack_content_blog_display', | |
| 200 | 132 | array( |
| 201 | - 'section' => 'jetpack_content_options', | |
| 202 | - 'label' => esc_html__( 'Display date', 'jetpack' ), | |
| 203 | - 'type' => 'checkbox', | |
| 133 | + 'section' => 'jetpack_content_options', | |
| 134 | + 'label' => esc_html__( 'Blog Display', 'jetpack' ), | |
| 135 | + 'description' => $blog_display_description, | |
| 136 | + 'type' => 'radio', | |
| 137 | + 'choices' => $blog_display_choices, | |
| 204 | 138 | ) |
| 205 | 139 | ); |
| 206 | 140 | } |
| 207 | 141 | |
| 208 | - // Post Details: Categories. | |
| 209 | - if ( ! empty( $categories ) ) { | |
| 210 | - $wp_customize->add_setting( | |
| 211 | - 'jetpack_content_post_details_categories', | |
| 212 | - array( | |
| 213 | - 'default' => 1, | |
| 214 | - 'type' => 'option', | |
| 215 | - 'transport' => 'postMessage', | |
| 216 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 217 | - ) | |
| 218 | - ); | |
| 142 | + // Add Author Bio option. | |
| 143 | + if ( true === $author_bio ) { | |
| 144 | + $wp_customize->add_setting( 'jetpack_content_author_bio_title' ); | |
| 219 | 145 | |
| 220 | 146 | $wp_customize->add_control( |
| 221 | - 'jetpack_content_post_details_categories', | |
| 222 | - array( | |
| 223 | - 'section' => 'jetpack_content_options', | |
| 224 | - 'label' => esc_html__( 'Display categories', 'jetpack' ), | |
| 225 | - 'type' => 'checkbox', | |
| 147 | + new Jetpack_Customize_Control_Title( | |
| 148 | + $wp_customize, | |
| 149 | + 'jetpack_content_author_bio_title', | |
| 150 | + array( | |
| 151 | + 'section' => 'jetpack_content_options', | |
| 152 | + 'label' => esc_html__( 'Author Bio', 'jetpack' ), | |
| 153 | + 'type' => 'title', | |
| 154 | + ) | |
| 226 | 155 | ) |
| 227 | 156 | ); |
| 228 | - } | |
| 229 | 157 | |
| 230 | - // Post Details: Tags. | |
| 231 | - if ( ! empty( $tags ) ) { | |
| 232 | 158 | $wp_customize->add_setting( |
| 233 | - 'jetpack_content_post_details_tags', | |
| 159 | + 'jetpack_content_author_bio', | |
| 234 | 160 | array( |
| 235 | - 'default' => 1, | |
| 161 | + 'default' => $author_bio_default, | |
| 236 | 162 | 'type' => 'option', |
| 237 | - 'transport' => 'postMessage', | |
| 238 | 163 | 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', |
| 239 | 164 | ) |
| 240 | 165 | ); |
| 241 | 166 | |
| 242 | 167 | $wp_customize->add_control( |
| 243 | - 'jetpack_content_post_details_tags', | |
| 168 | + 'jetpack_content_author_bio', | |
| 244 | 169 | array( |
| 245 | 170 | 'section' => 'jetpack_content_options', |
| 246 | - 'label' => esc_html__( 'Display tags', 'jetpack' ), | |
| 171 | + 'label' => esc_html__( 'Display on single posts', 'jetpack' ), | |
| 247 | 172 | 'type' => 'checkbox', |
| 248 | 173 | ) |
| 249 | 174 | ); |
| 250 | 175 | } |
| 251 | 176 | |
| 252 | - // Post Details: Author. | |
| 253 | - if ( ! empty( $author ) ) { | |
| 254 | - $wp_customize->add_setting( | |
| 255 | - 'jetpack_content_post_details_author', | |
| 256 | - array( | |
| 257 | - 'default' => 1, | |
| 258 | - 'type' => 'option', | |
| 259 | - 'transport' => 'postMessage', | |
| 260 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 261 | - ) | |
| 262 | - ); | |
| 177 | + // Add Post Details options. | |
| 178 | + if ( ( ! empty( $post_details ) ) | |
| 179 | + && ( ! empty( $post_details['stylesheet'] ) ) | |
| 180 | + && ( ! empty( $date ) | |
| 181 | + || ! empty( $categories ) | |
| 182 | + || ! empty( $tags ) | |
| 183 | + || ! empty( $author ) | |
| 184 | + || ! empty( $comment ) ) ) { | |
| 185 | + $wp_customize->add_setting( 'jetpack_content_post_details_title' ); | |
| 263 | 186 | |
| 264 | 187 | $wp_customize->add_control( |
| 265 | - 'jetpack_content_post_details_author', | |
| 266 | - array( | |
| 267 | - 'section' => 'jetpack_content_options', | |
| 268 | - 'label' => esc_html__( 'Display author', 'jetpack' ), | |
| 269 | - 'type' => 'checkbox', | |
| 188 | + new Jetpack_Customize_Control_Title( | |
| 189 | + $wp_customize, | |
| 190 | + 'jetpack_content_post_details_title', | |
| 191 | + array( | |
| 192 | + 'section' => 'jetpack_content_options', | |
| 193 | + 'label' => esc_html__( 'Post Details', 'jetpack' ), | |
| 194 | + 'type' => 'title', | |
| 195 | + ) | |
| 270 | 196 | ) |
| 271 | 197 | ); |
| 272 | - } | |
| 273 | 198 | |
| 274 | - // Post Details: Comment link. | |
| 275 | - if ( ! empty( $comment ) ) { | |
| 276 | - $wp_customize->add_setting( | |
| 277 | - 'jetpack_content_post_details_comment', | |
| 278 | - array( | |
| 279 | - 'default' => 1, | |
| 280 | - 'type' => 'option', | |
| 281 | - 'transport' => 'postMessage', | |
| 282 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 283 | - ) | |
| 284 | - ); | |
| 199 | + // Post Details: Date. | |
| 200 | + if ( ! empty( $date ) ) { | |
| 201 | + $wp_customize->add_setting( | |
| 202 | + 'jetpack_content_post_details_date', | |
| 203 | + array( | |
| 204 | + 'default' => 1, | |
| 205 | + 'type' => 'option', | |
| 206 | + 'transport' => 'postMessage', | |
| 207 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 208 | + ) | |
| 209 | + ); | |
| 285 | 210 | |
| 286 | - $wp_customize->add_control( | |
| 287 | - 'jetpack_content_post_details_comment', | |
| 288 | - array( | |
| 289 | - 'section' => 'jetpack_content_options', | |
| 290 | - 'label' => esc_html__( 'Display comment link', 'jetpack' ), | |
| 291 | - 'type' => 'checkbox', | |
| 292 | - ) | |
| 293 | - ); | |
| 294 | - } | |
| 295 | - } | |
| 211 | + $wp_customize->add_control( | |
| 212 | + 'jetpack_content_post_details_date', | |
| 213 | + array( | |
| 214 | + 'section' => 'jetpack_content_options', | |
| 215 | + 'label' => esc_html__( 'Display date', 'jetpack' ), | |
| 216 | + 'type' => 'checkbox', | |
| 217 | + ) | |
| 218 | + ); | |
| 219 | + } | |
| 296 | 220 | |
| 297 | - // Add Featured Images options. | |
| 298 | - if ( true === $fi_archive || true === $fi_post || true === $fi_page || true === $fi_portfolio || true === $fi_fallback ) { | |
| 299 | - $wp_customize->add_setting( 'jetpack_content_featured_images_title' ); | |
| 221 | + // Post Details: Categories. | |
| 222 | + if ( ! empty( $categories ) ) { | |
| 223 | + $wp_customize->add_setting( | |
| 224 | + 'jetpack_content_post_details_categories', | |
| 225 | + array( | |
| 226 | + 'default' => 1, | |
| 227 | + 'type' => 'option', | |
| 228 | + 'transport' => 'postMessage', | |
| 229 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 230 | + ) | |
| 231 | + ); | |
| 300 | 232 | |
| 301 | - $wp_customize->add_control( | |
| 302 | - new Jetpack_Customize_Control_Title( | |
| 303 | - $wp_customize, | |
| 304 | - 'jetpack_content_featured_images_title', | |
| 305 | - array( | |
| 306 | - 'section' => 'jetpack_content_options', | |
| 307 | - 'label' => esc_html__( 'Featured Images', 'jetpack' ) . sprintf( '<a href="https://en.support.wordpress.com/featured-images/" class="customize-help-toggle dashicons dashicons-editor-help" title="%1$s" rel="noopener noreferrer" target="_blank"><span class="screen-reader-text">%1$s</span></a>', esc_html__( 'Learn more about Featured Images', 'jetpack' ) ), | |
| 308 | - 'type' => 'title', | |
| 309 | - 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 310 | - ) | |
| 311 | - ) | |
| 312 | - ); | |
| 233 | + $wp_customize->add_control( | |
| 234 | + 'jetpack_content_post_details_categories', | |
| 235 | + array( | |
| 236 | + 'section' => 'jetpack_content_options', | |
| 237 | + 'label' => esc_html__( 'Display categories', 'jetpack' ), | |
| 238 | + 'type' => 'checkbox', | |
| 239 | + ) | |
| 240 | + ); | |
| 241 | + } | |
| 313 | 242 | |
| 314 | - // Featured Images: Archive. | |
| 315 | - if ( true === $fi_archive ) { | |
| 316 | - $wp_customize->add_setting( | |
| 317 | - 'jetpack_content_featured_images_archive', | |
| 318 | - array( | |
| 319 | - 'default' => $fi_archive_default, | |
| 320 | - 'type' => 'option', | |
| 321 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 322 | - ) | |
| 323 | - ); | |
| 243 | + // Post Details: Tags. | |
| 244 | + if ( ! empty( $tags ) ) { | |
| 245 | + $wp_customize->add_setting( | |
| 246 | + 'jetpack_content_post_details_tags', | |
| 247 | + array( | |
| 248 | + 'default' => 1, | |
| 249 | + 'type' => 'option', | |
| 250 | + 'transport' => 'postMessage', | |
| 251 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 252 | + ) | |
| 253 | + ); | |
| 324 | 254 | |
| 325 | - $wp_customize->add_control( | |
| 326 | - 'jetpack_content_featured_images_archive', | |
| 327 | - array( | |
| 328 | - 'section' => 'jetpack_content_options', | |
| 329 | - 'label' => esc_html__( 'Display on blog and archives', 'jetpack' ), | |
| 330 | - 'type' => 'checkbox', | |
| 331 | - 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 332 | - ) | |
| 333 | - ); | |
| 255 | + $wp_customize->add_control( | |
| 256 | + 'jetpack_content_post_details_tags', | |
| 257 | + array( | |
| 258 | + 'section' => 'jetpack_content_options', | |
| 259 | + 'label' => esc_html__( 'Display tags', 'jetpack' ), | |
| 260 | + 'type' => 'checkbox', | |
| 261 | + ) | |
| 262 | + ); | |
| 263 | + } | |
| 264 | + | |
| 265 | + // Post Details: Author. | |
| 266 | + if ( ! empty( $author ) ) { | |
| 267 | + $wp_customize->add_setting( | |
| 268 | + 'jetpack_content_post_details_author', | |
| 269 | + array( | |
| 270 | + 'default' => 1, | |
| 271 | + 'type' => 'option', | |
| 272 | + 'transport' => 'postMessage', | |
| 273 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 274 | + ) | |
| 275 | + ); | |
| 276 | + | |
| 277 | + $wp_customize->add_control( | |
| 278 | + 'jetpack_content_post_details_author', | |
| 279 | + array( | |
| 280 | + 'section' => 'jetpack_content_options', | |
| 281 | + 'label' => esc_html__( 'Display author', 'jetpack' ), | |
| 282 | + 'type' => 'checkbox', | |
| 283 | + ) | |
| 284 | + ); | |
| 285 | + } | |
| 286 | + | |
| 287 | + // Post Details: Comment link. | |
| 288 | + if ( ! empty( $comment ) ) { | |
| 289 | + $wp_customize->add_setting( | |
| 290 | + 'jetpack_content_post_details_comment', | |
| 291 | + array( | |
| 292 | + 'default' => 1, | |
| 293 | + 'type' => 'option', | |
| 294 | + 'transport' => 'postMessage', | |
| 295 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 296 | + ) | |
| 297 | + ); | |
| 298 | + | |
| 299 | + $wp_customize->add_control( | |
| 300 | + 'jetpack_content_post_details_comment', | |
| 301 | + array( | |
| 302 | + 'section' => 'jetpack_content_options', | |
| 303 | + 'label' => esc_html__( 'Display comment link', 'jetpack' ), | |
| 304 | + 'type' => 'checkbox', | |
| 305 | + ) | |
| 306 | + ); | |
| 307 | + } | |
| 334 | 308 | } |
| 335 | 309 | |
| 336 | - // Featured Images: Post. | |
| 337 | - if ( true === $fi_post ) { | |
| 338 | - $wp_customize->add_setting( | |
| 339 | - 'jetpack_content_featured_images_post', | |
| 340 | - array( | |
| 341 | - 'default' => $fi_post_default, | |
| 342 | - 'type' => 'option', | |
| 343 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 344 | - ) | |
| 345 | - ); | |
| 310 | + // Add Featured Images options. | |
| 311 | + if ( true === $fi_archive || true === $fi_post || true === $fi_page || true === $fi_portfolio || true === $fi_fallback ) { | |
| 312 | + $wp_customize->add_setting( 'jetpack_content_featured_images_title' ); | |
| 346 | 313 | |
| 347 | 314 | $wp_customize->add_control( |
| 348 | - 'jetpack_content_featured_images_post', | |
| 349 | - array( | |
| 350 | - 'section' => 'jetpack_content_options', | |
| 351 | - 'label' => esc_html__( 'Display on single posts', 'jetpack' ), | |
| 352 | - 'type' => 'checkbox', | |
| 353 | - 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 315 | + new Jetpack_Customize_Control_Title( | |
| 316 | + $wp_customize, | |
| 317 | + 'jetpack_content_featured_images_title', | |
| 318 | + array( | |
| 319 | + 'section' => 'jetpack_content_options', | |
| 320 | + 'label' => esc_html__( 'Featured Images', 'jetpack' ) . sprintf( '<a href="https://en.support.wordpress.com/featured-images/" class="customize-help-toggle dashicons dashicons-editor-help" title="%1$s" rel="noopener noreferrer" target="_blank"><span class="screen-reader-text">%1$s</span></a>', esc_html__( 'Learn more about Featured Images', 'jetpack' ) ), | |
| 321 | + 'type' => 'title', | |
| 322 | + 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 323 | + ) | |
| 354 | 324 | ) |
| 355 | 325 | ); |
| 356 | - } | |
| 357 | 326 | |
| 358 | - // Featured Images: Page. | |
| 359 | - if ( true === $fi_page ) { | |
| 360 | - $wp_customize->add_setting( | |
| 361 | - 'jetpack_content_featured_images_page', | |
| 362 | - array( | |
| 363 | - 'default' => $fi_page_default, | |
| 364 | - 'type' => 'option', | |
| 365 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 366 | - ) | |
| 367 | - ); | |
| 327 | + // Featured Images: Archive. | |
| 328 | + if ( true === $fi_archive ) { | |
| 329 | + $wp_customize->add_setting( | |
| 330 | + 'jetpack_content_featured_images_archive', | |
| 331 | + array( | |
| 332 | + 'default' => $fi_archive_default, | |
| 333 | + 'type' => 'option', | |
| 334 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 335 | + ) | |
| 336 | + ); | |
| 368 | 337 | |
| 369 | - $wp_customize->add_control( | |
| 370 | - 'jetpack_content_featured_images_page', | |
| 371 | - array( | |
| 372 | - 'section' => 'jetpack_content_options', | |
| 373 | - 'label' => esc_html__( 'Display on pages', 'jetpack' ), | |
| 374 | - 'type' => 'checkbox', | |
| 375 | - 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 376 | - ) | |
| 377 | - ); | |
| 378 | - } | |
| 338 | + $wp_customize->add_control( | |
| 339 | + 'jetpack_content_featured_images_archive', | |
| 340 | + array( | |
| 341 | + 'section' => 'jetpack_content_options', | |
| 342 | + 'label' => esc_html__( 'Display on blog and archives', 'jetpack' ), | |
| 343 | + 'type' => 'checkbox', | |
| 344 | + 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 345 | + ) | |
| 346 | + ); | |
| 347 | + } | |
| 379 | 348 | |
| 380 | - // Featured Images: Portfolio. | |
| 381 | - if ( true === $fi_portfolio && post_type_exists( 'jetpack-portfolio' ) ) { | |
| 382 | - $wp_customize->add_setting( | |
| 383 | - 'jetpack_content_featured_images_portfolio', | |
| 384 | - array( | |
| 385 | - 'default' => $fi_portfolio_default, | |
| 386 | - 'type' => 'option', | |
| 387 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 388 | - ) | |
| 389 | - ); | |
| 349 | + // Featured Images: Post. | |
| 350 | + if ( true === $fi_post ) { | |
| 351 | + $wp_customize->add_setting( | |
| 352 | + 'jetpack_content_featured_images_post', | |
| 353 | + array( | |
| 354 | + 'default' => $fi_post_default, | |
| 355 | + 'type' => 'option', | |
| 356 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 357 | + ) | |
| 358 | + ); | |
| 390 | 359 | |
| 391 | - $wp_customize->add_control( | |
| 392 | - 'jetpack_content_featured_images_portfolio', | |
| 393 | - array( | |
| 394 | - 'section' => 'jetpack_content_options', | |
| 395 | - 'label' => esc_html__( 'Display on single projects', 'jetpack' ), | |
| 396 | - 'type' => 'checkbox', | |
| 397 | - 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 398 | - ) | |
| 399 | - ); | |
| 400 | - } | |
| 360 | + $wp_customize->add_control( | |
| 361 | + 'jetpack_content_featured_images_post', | |
| 362 | + array( | |
| 363 | + 'section' => 'jetpack_content_options', | |
| 364 | + 'label' => esc_html__( 'Display on single posts', 'jetpack' ), | |
| 365 | + 'type' => 'checkbox', | |
| 366 | + 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 367 | + ) | |
| 368 | + ); | |
| 369 | + } | |
| 401 | 370 | |
| 402 | - // Featured Images: Fallback. | |
| 403 | - if ( true === $fi_fallback ) { | |
| 404 | - $wp_customize->add_setting( | |
| 405 | - 'jetpack_content_featured_images_fallback', | |
| 406 | - array( | |
| 407 | - 'default' => $fi_fallback_default, | |
| 408 | - 'type' => 'option', | |
| 409 | - 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 410 | - ) | |
| 411 | - ); | |
| 371 | + // Featured Images: Page. | |
| 372 | + if ( true === $fi_page ) { | |
| 373 | + $wp_customize->add_setting( | |
| 374 | + 'jetpack_content_featured_images_page', | |
| 375 | + array( | |
| 376 | + 'default' => $fi_page_default, | |
| 377 | + 'type' => 'option', | |
| 378 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 379 | + ) | |
| 380 | + ); | |
| 412 | 381 | |
| 413 | - $wp_customize->add_control( | |
| 414 | - 'jetpack_content_featured_images_fallback', | |
| 415 | - array( | |
| 416 | - 'section' => 'jetpack_content_options', | |
| 417 | - 'label' => esc_html__( 'Automatically use first image in post', 'jetpack' ), | |
| 418 | - 'type' => 'checkbox', | |
| 419 | - 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 420 | - ) | |
| 421 | - ); | |
| 382 | + $wp_customize->add_control( | |
| 383 | + 'jetpack_content_featured_images_page', | |
| 384 | + array( | |
| 385 | + 'section' => 'jetpack_content_options', | |
| 386 | + 'label' => esc_html__( 'Display on pages', 'jetpack' ), | |
| 387 | + 'type' => 'checkbox', | |
| 388 | + 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 389 | + ) | |
| 390 | + ); | |
| 391 | + } | |
| 392 | + | |
| 393 | + // Featured Images: Portfolio. | |
| 394 | + if ( true === $fi_portfolio && post_type_exists( 'jetpack-portfolio' ) ) { | |
| 395 | + $wp_customize->add_setting( | |
| 396 | + 'jetpack_content_featured_images_portfolio', | |
| 397 | + array( | |
| 398 | + 'default' => $fi_portfolio_default, | |
| 399 | + 'type' => 'option', | |
| 400 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 401 | + ) | |
| 402 | + ); | |
| 403 | + | |
| 404 | + $wp_customize->add_control( | |
| 405 | + 'jetpack_content_featured_images_portfolio', | |
| 406 | + array( | |
| 407 | + 'section' => 'jetpack_content_options', | |
| 408 | + 'label' => esc_html__( 'Display on single projects', 'jetpack' ), | |
| 409 | + 'type' => 'checkbox', | |
| 410 | + 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 411 | + ) | |
| 412 | + ); | |
| 413 | + } | |
| 414 | + | |
| 415 | + // Featured Images: Fallback. | |
| 416 | + if ( true === $fi_fallback ) { | |
| 417 | + $wp_customize->add_setting( | |
| 418 | + 'jetpack_content_featured_images_fallback', | |
| 419 | + array( | |
| 420 | + 'default' => $fi_fallback_default, | |
| 421 | + 'type' => 'option', | |
| 422 | + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', | |
| 423 | + ) | |
| 424 | + ); | |
| 425 | + | |
| 426 | + $wp_customize->add_control( | |
| 427 | + 'jetpack_content_featured_images_fallback', | |
| 428 | + array( | |
| 429 | + 'section' => 'jetpack_content_options', | |
| 430 | + 'label' => esc_html__( 'Automatically use first image in post', 'jetpack' ), | |
| 431 | + 'type' => 'checkbox', | |
| 432 | + 'active_callback' => 'jetpack_post_thumbnail_supports', | |
| 433 | + ) | |
| 434 | + ); | |
| 435 | + } | |
| 422 | 436 | } |
| 423 | 437 | } |
| 438 | + add_action( 'customize_register', 'jetpack_content_options_customize_register' ); | |
| 439 | + | |
| 424 | 440 | } |
| 425 | -add_action( 'customize_register', 'jetpack_content_options_customize_register' ); | |
| 426 | 441 | |
| 427 | -/** | |
| 428 | - * Return whether the theme supports Post Thumbnails. | |
| 429 | - */ | |
| 430 | -function jetpack_post_thumbnail_supports() { | |
| 431 | - return ( current_theme_supports( 'post-thumbnails' ) ); | |
| 442 | +if ( ! function_exists( 'jetpack_post_thumbnail_supports' ) ) { | |
| 443 | + | |
| 444 | + /** | |
| 445 | + * Return whether the theme supports Post Thumbnails. | |
| 446 | + * | |
| 447 | + * @deprecated 13.9 Moved to Classic Theme Helper package. | |
| 448 | + */ | |
| 449 | + function jetpack_post_thumbnail_supports() { | |
| 450 | + _deprecated_function( __FUNCTION__, 'jetpack-13.9' ); | |
| 451 | + return ( current_theme_supports( 'post-thumbnails' ) ); | |
| 452 | + } | |
| 453 | + | |
| 432 | 454 | } |
| 433 | 455 | |
| 434 | -/** | |
| 435 | - * Sanitize the checkbox. | |
| 436 | - * | |
| 437 | - * @param int $input The unsanitized value from the setting. | |
| 438 | - * @return boolean|string | |
| 439 | - */ | |
| 440 | -function jetpack_content_options_sanitize_checkbox( $input ) { | |
| 441 | - return ( 1 === (int) $input ) ? 1 : ''; | |
| 456 | +if ( ! function_exists( 'jetpack_content_options_sanitize_checkbox' ) ) { | |
| 457 | + | |
| 458 | + /** | |
| 459 | + * Sanitize the checkbox. | |
| 460 | + * | |
| 461 | + * @deprecated 13.9 Moved to Classic Theme Helper package. | |
| 462 | + * @param int $input The unsanitized value from the setting. | |
| 463 | + * @return boolean|string | |
| 464 | + */ | |
| 465 | + function jetpack_content_options_sanitize_checkbox( $input ) { | |
| 466 | + _deprecated_function( __FUNCTION__, 'jetpack-13.9' ); | |
| 467 | + return ( 1 === (int) $input ) ? 1 : ''; | |
| 468 | + } | |
| 469 | + | |
| 442 | 470 | } |
| 443 | 471 | |
| 444 | -/** | |
| 445 | - * Sanitize the Display value. | |
| 446 | - * | |
| 447 | - * @param string $display The unsanitized value from the setting. | |
| 448 | - * @return string. | |
| 449 | - */ | |
| 450 | -function jetpack_content_options_sanitize_blog_display( $display ) { | |
| 451 | - if ( ! in_array( $display, array( 'content', 'excerpt', 'mixed' ), true ) ) { | |
| 452 | - $display = 'content'; | |
| 472 | +if ( ! function_exists( 'jetpack_content_options_sanitize_blog_display' ) ) { | |
| 473 | + | |
| 474 | + /** | |
| 475 | + * Sanitize the Display value. | |
| 476 | + * | |
| 477 | + * @deprecated 13.9 Moved to Classic Theme Helper package. | |
| 478 | + * @param string $display The unsanitized value from the setting. | |
| 479 | + * @return string | |
| 480 | + */ | |
| 481 | + function jetpack_content_options_sanitize_blog_display( $display ) { | |
| 482 | + _deprecated_function( __FUNCTION__, 'jetpack-13.9' ); | |
| 483 | + if ( ! in_array( $display, array( 'content', 'excerpt', 'mixed' ), true ) ) { | |
| 484 | + $display = 'content'; | |
| 485 | + } | |
| 486 | + return $display; | |
| 453 | 487 | } |
| 454 | - return $display; | |
| 488 | + | |
| 455 | 489 | } |
| 456 | 490 | |
| 457 | -/** | |
| 458 | - * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. | |
| 459 | - */ | |
| 460 | -function jetpack_content_options_customize_preview_js() { | |
| 461 | - $options = get_theme_support( 'jetpack-content-options' ); | |
| 462 | - $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; | |
| 463 | - $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); | |
| 464 | - sort( $blog_display ); | |
| 465 | - $blog_display = implode( ', ', $blog_display ); | |
| 466 | - $blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; | |
| 467 | - $masonry = ( ! empty( $options[0]['masonry'] ) ) ? $options[0]['masonry'] : null; | |
| 468 | - $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; | |
| 469 | - $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; | |
| 470 | - $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; | |
| 471 | - $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; | |
| 472 | - $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; | |
| 473 | - $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; | |
| 491 | +if ( ! function_exists( 'jetpack_content_options_customize_preview_js' ) ) { | |
| 474 | 492 | |
| 475 | - wp_enqueue_script( 'jetpack-content-options-customizer', plugins_url( 'customizer.js', __FILE__ ), array( 'jquery', 'customize-preview' ), '1.0', true ); | |
| 493 | + /** | |
| 494 | + * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. | |
| 495 | + * | |
| 496 | + * @deprecated 13.9 Moved to Classic Theme Helper package. | |
| 497 | + */ | |
| 498 | + function jetpack_content_options_customize_preview_js() { | |
| 499 | + _deprecated_function( __FUNCTION__, 'jetpack-13.9' ); | |
| 500 | + $options = get_theme_support( 'jetpack-content-options' ); | |
| 501 | + $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; | |
| 502 | + $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); | |
| 503 | + sort( $blog_display ); | |
| 504 | + $blog_display = implode( ', ', $blog_display ); | |
| 505 | + $blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; | |
| 506 | + $masonry = ( ! empty( $options[0]['masonry'] ) ) ? $options[0]['masonry'] : null; | |
| 507 | + $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; | |
| 508 | + $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; | |
| 509 | + $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; | |
| 510 | + $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; | |
| 511 | + $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; | |
| 512 | + $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; | |
| 476 | 513 | |
| 477 | - wp_localize_script( | |
| 478 | - 'jetpack-content-options-customizer', | |
| 479 | - 'blogDisplay', | |
| 480 | - array( | |
| 481 | - 'display' => get_option( 'jetpack_content_blog_display', $blog_display ), | |
| 482 | - 'masonry' => $masonry, | |
| 483 | - ) | |
| 484 | - ); | |
| 514 | + wp_enqueue_script( 'jetpack-content-options-customizer', plugins_url( 'customizer.js', __FILE__ ), array( 'jquery', 'customize-preview' ), '1.0', true ); | |
| 485 | 515 | |
| 486 | - wp_localize_script( | |
| 487 | - 'jetpack-content-options-customizer', | |
| 488 | - 'postDetails', | |
| 489 | - array( | |
| 490 | - 'date' => $date, | |
| 491 | - 'categories' => $categories, | |
| 492 | - 'tags' => $tags, | |
| 493 | - 'author' => $author, | |
| 494 | - 'comment' => $comment, | |
| 495 | - ) | |
| 496 | - ); | |
| 516 | + wp_localize_script( | |
| 517 | + 'jetpack-content-options-customizer', | |
| 518 | + 'blogDisplay', | |
| 519 | + array( | |
| 520 | + 'display' => get_option( 'jetpack_content_blog_display', $blog_display ), | |
| 521 | + 'masonry' => $masonry, | |
| 522 | + ) | |
| 523 | + ); | |
| 524 | + | |
| 525 | + wp_localize_script( | |
| 526 | + 'jetpack-content-options-customizer', | |
| 527 | + 'postDetails', | |
| 528 | + array( | |
| 529 | + 'date' => $date, | |
| 530 | + 'categories' => $categories, | |
| 531 | + 'tags' => $tags, | |
| 532 | + 'author' => $author, | |
| 533 | + 'comment' => $comment, | |
| 534 | + ) | |
| 535 | + ); | |
| 536 | + } | |
| 537 | + add_action( 'customize_preview_init', 'jetpack_content_options_customize_preview_js' ); | |
| 538 | + | |
| 497 | 539 | } |
| 498 | -add_action( 'customize_preview_init', 'jetpack_content_options_customize_preview_js' ); | |