diff options
Diffstat (limited to 'plugins/jetpack/modules/theme-tools')
6 files changed, 373 insertions, 58 deletions
diff --git a/plugins/jetpack/modules/theme-tools/content-options.php b/plugins/jetpack/modules/theme-tools/content-options.php index 5a97aee8..fb858718 100644 --- a/plugins/jetpack/modules/theme-tools/content-options.php +++ b/plugins/jetpack/modules/theme-tools/content-options.php @@ -12,19 +12,24 @@ 'author-bio-default' => false, // the default setting of the author bio, if it's being displayed or not: true or false (only required if false). 'masonry' => '.site-main', // a CSS selector matching the elements that triggers a masonry refresh if the theme is using a masonry layout. 'post-details' => array( - 'stylesheet' => 'themeslug-style', // name of the theme's stylesheet. - 'date' => '.posted-on', // a CSS selector matching the elements that display the post date. - 'categories' => '.cat-links', // a CSS selector matching the elements that display the post categories. - 'tags' => '.tags-links', // a CSS selector matching the elements that display the post tags. - 'author' => '.byline', // a CSS selector matching the elements that display the post author. + 'stylesheet' => 'themeslug-style', // name of the theme's stylesheet. + 'date' => '.posted-on', // a CSS selector matching the elements that display the post date. + 'categories' => '.cat-links', // a CSS selector matching the elements that display the post categories. + 'tags' => '.tags-links', // a CSS selector matching the elements that display the post tags. + 'author' => '.byline', // a CSS selector matching the elements that display the post author. + 'comment' => '.comments-link', // a CSS selector matching the elements that display the comment link. ), 'featured-images' => array( - 'archive' => true, // enable or not the featured image check for archive pages: true or false. - 'archive-default' => false, // the default setting of the featured image on archive pages, if it's being displayed or not: true or false (only required if false). - 'post' => true, // enable or not the featured image check for single posts: true or false. - 'post-default' => false, // the default setting of the featured image on single posts, if it's being displayed or not: true or false (only required if false). - 'page' => true, // enable or not the featured image check for single pages: true or false. - 'page-default' => false, // the default setting of the featured image on single pages, if it's being displayed or not: true or false (only required if false). + 'archive' => true, // enable or not the featured image check for archive pages: true or false. + 'archive-default' => false, // the default setting of the featured image on archive pages, if it's being displayed or not: true or false (only required if false). + 'post' => true, // enable or not the featured image check for single posts: true or false. + 'post-default' => false, // the default setting of the featured image on single posts, if it's being displayed or not: true or false (only required if false). + 'page' => true, // enable or not the featured image check for single pages: true or false. + 'page-default' => false, // the default setting of the featured image on single pages, if it's being displayed or not: true or false (only required if false). + 'portfolio' => true, // enable or not the featured image check for single projects: true or false. + 'portfolio-default' => false, // the default setting of the featured image on single projects, if it's being displayed or not: true or false (only required if false). + 'fallback' => true, // enable or not the featured image fallback: true or false. + 'fallback-default' => true, // the default setting for featured image fallbacks: true or false (only required if false) ), ) ); * @@ -57,37 +62,72 @@ function jetpack_content_options_init() { if ( jetpack_featured_images_should_load() ) { require( dirname( __FILE__ ) . '/content-options/featured-images.php' ); } + + // Load Featured Images Fallback function. + if ( jetpack_featured_images_fallback_should_load() ) { + require( dirname( __FILE__ ) . '/content-options/featured-images-fallback.php' ); + } } add_action( 'init', 'jetpack_content_options_init' ); function jetpack_featured_images_get_settings() { $options = get_theme_support( 'jetpack-content-options' ); + $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; $settings = array( - 'archive' => ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null, - 'post' => ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null, - 'page' => ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null, - 'archive-default' => ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1, - 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1, - 'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1, + 'archive' => ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null, + 'post' => ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null, + 'page' => ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null, + 'portfolio' => ( ! empty( $featured_images['portfolio'] ) ) ? $featured_images['portfolio'] : null, + 'archive-default' => ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1, + 'post-default' => ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1, + 'page-default' => ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1, + 'portfolio-default' => ( isset( $featured_images['portfolio-default'] ) && false === $featured_images['portfolio-default'] ) ? '' : 1, + 'fallback' => ( ! empty( $featured_images['fallback'] ) ) ? $featured_images['fallback'] : null, + 'fallback-default' => ( isset( $featured_images['fallback-default'] ) && false === $featured_images['fallback-default'] ) ? '' : 1, ); $settings = array_merge( $settings, array( - 'archive-option' => get_option( 'jetpack_content_featured_images_archive', $settings['archive-default'] ), - 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ), - 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ), + 'archive-option' => get_option( 'jetpack_content_featured_images_archive', $settings['archive-default'] ), + 'post-option' => get_option( 'jetpack_content_featured_images_post', $settings['post-default'] ), + 'page-option' => get_option( 'jetpack_content_featured_images_page', $settings['page-default'] ), + 'portfolio-option' => get_option( 'jetpack_content_featured_images_portfolio', $settings['portfolio-default'] ), + 'fallback-option' => get_option( 'jetpack_content_featured_images_fallback', $settings['fallback-default'] ), ) ); return $settings; } function jetpack_featured_images_should_load() { + // If the theme doesn't support post thumbnails, don't continue. + if ( ! current_theme_supports( 'post-thumbnails' ) ) { + return false; + } + $opts = jetpack_featured_images_get_settings(); // If the theme doesn't support archive, post and page or if all the options are ticked and we aren't in the customizer, don't continue. - if ( ( true !== $opts['archive'] && true !== $opts['post'] && true !== $opts['page'] ) - || ( 1 === $opts['archive-option'] && 1 === $opts['post-option'] && 1 === $opts['page-option'] && ! is_customize_preview() ) ) { + if ( + ( true !== $opts['archive'] && true !== $opts['post'] && true !== $opts['page'] ) + || ( 1 === $opts['archive-option'] && 1 === $opts['post-option'] && 1 === $opts['page-option'] && ! is_customize_preview() ) + ) { + return false; + } + + return true; +} + +function jetpack_featured_images_fallback_should_load() { + // If the theme doesn't support post thumbnails, don't continue. + if ( ! current_theme_supports( 'post-thumbnails' ) ) { + return false; + } + + $opts = jetpack_featured_images_get_settings(); + + // If the theme doesn't support fallback, don't continue. + if ( true !== $opts['fallback'] ) { return false; } diff --git a/plugins/jetpack/modules/theme-tools/content-options/customizer.js b/plugins/jetpack/modules/theme-tools/content-options/customizer.js index 0c8c1c3c..e6b9b132 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/customizer.js +++ b/plugins/jetpack/modules/theme-tools/content-options/customizer.js @@ -189,4 +189,29 @@ } } ); } ); + + // Post Details: Comment link. + wp.customize( 'jetpack_content_post_details_comment', function( value ) { + value.bind( function( to ) { + if ( false === to ) { + $( postDetails.comment ).css( { + 'clip': 'rect(1px, 1px, 1px, 1px)', + 'height': '1px', + 'overflow': 'hidden', + 'position': 'absolute', + 'width': '1px' + } ); + $( 'body' ).addClass( 'comment-hidden' ); + } else { + $( postDetails.comment ).css( { + 'clip': 'auto', + 'height': 'auto', + 'overflow': 'auto', + 'position': 'relative', + 'width': 'auto' + } ); + $( 'body' ).removeClass( 'comment-hidden' ); + } + } ); + } ); } )( jQuery ); diff --git a/plugins/jetpack/modules/theme-tools/content-options/customizer.php b/plugins/jetpack/modules/theme-tools/content-options/customizer.php index 3be1693f..5123d98e 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/customizer.php +++ b/plugins/jetpack/modules/theme-tools/content-options/customizer.php @@ -5,26 +5,31 @@ * @param WP_Customize_Manager $wp_customize Theme Customizer object. */ function jetpack_content_options_customize_register( $wp_customize ) { - $options = get_theme_support( 'jetpack-content-options' ); - $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; - $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); + $options = get_theme_support( 'jetpack-content-options' ); + $blog_display = ( ! empty( $options[0]['blog-display'] ) ) ? $options[0]['blog-display'] : null; + $blog_display = preg_grep( '/^(content|excerpt)$/', (array) $blog_display ); sort( $blog_display ); - $blog_display = implode( ', ', $blog_display ); - $blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; - $author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null; - $author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1; - $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; - $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; - $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; - $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; - $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; - $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; - $fi_archive = ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null; - $fi_post = ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null; - $fi_page = ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null; - $fi_archive_default = ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1; - $fi_post_default = ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1; - $fi_page_default = ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1; + $blog_display = implode( ', ', $blog_display ); + $blog_display = ( 'content, excerpt' === $blog_display ) ? 'mixed' : $blog_display; + $author_bio = ( ! empty( $options[0]['author-bio'] ) ) ? $options[0]['author-bio'] : null; + $author_bio_default = ( isset( $options[0]['author-bio-default'] ) && false === $options[0]['author-bio-default'] ) ? '' : 1; + $post_details = ( ! empty( $options[0]['post-details'] ) ) ? $options[0]['post-details'] : null; + $date = ( ! empty( $post_details['date'] ) ) ? $post_details['date'] : null; + $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; + $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; + $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; + $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; + $featured_images = ( ! empty( $options[0]['featured-images'] ) ) ? $options[0]['featured-images'] : null; + $fi_archive = ( ! empty( $featured_images['archive'] ) ) ? $featured_images['archive'] : null; + $fi_post = ( ! empty( $featured_images['post'] ) ) ? $featured_images['post'] : null; + $fi_page = ( ! empty( $featured_images['page'] ) ) ? $featured_images['page'] : null; + $fi_portfolio = ( ! empty( $featured_images['portfolio'] ) ) ? $featured_images['portfolio'] : null; + $fi_fallback = ( ! empty( $featured_images['fallback'] ) ) ? $featured_images['fallback'] : null; + $fi_archive_default = ( isset( $featured_images['archive-default'] ) && false === $featured_images['archive-default'] ) ? '' : 1; + $fi_post_default = ( isset( $featured_images['post-default'] ) && false === $featured_images['post-default'] ) ? '' : 1; + $fi_page_default = ( isset( $featured_images['page-default'] ) && false === $featured_images['page-default'] ) ? '' : 1; + $fi_portfolio_default = ( isset( $featured_images['portfolio-default'] ) && false === $featured_images['portfolio-default'] ) ? '' : 1; + $fi_fallback_default = ( isset( $featured_images['fallback-default'] ) && false === $featured_images['fallback-default'] ) ? '' : 1; // 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. if ( ( ! in_array( $blog_display, array( 'content', 'excerpt', 'mixed' ) ) ) @@ -33,8 +38,9 @@ function jetpack_content_options_customize_register( $wp_customize ) { && ( empty( $date ) || empty( $categories ) || empty( $tags ) - || empty( $author ) ) ) - && ( true !== $fi_archive && true !== $fi_post && true !== $fi_page ) ) { + || empty( $author ) + || empty( $comment ) ) ) + && ( true !== $fi_archive && true !== $fi_post && true !== $fi_page && true !== $fi_portfolio && true !== $fi_fallback ) ) { return; } @@ -44,7 +50,7 @@ function jetpack_content_options_customize_register( $wp_customize ) { public function render_content() { ?> - <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span> + <span class="customize-control-title"><?php echo wp_kses_post( $this->label ); ?></span> <?php } } @@ -124,7 +130,8 @@ function jetpack_content_options_customize_register( $wp_customize ) { && ( ! empty( $date ) || ! empty( $categories ) || ! empty( $tags ) - || ! empty( $author ) ) ) { + || ! empty( $author ) + || ! empty( $comment ) ) ) { $wp_customize->add_setting( 'jetpack_content_post_details_title' ); $wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_post_details_title', array( @@ -196,16 +203,33 @@ function jetpack_content_options_customize_register( $wp_customize ) { 'type' => 'checkbox', ) ); } + + // Post Details: Comment link + if ( ! empty( $comment ) ) { + $wp_customize->add_setting( 'jetpack_content_post_details_comment', array( + 'default' => 1, + 'type' => 'option', + 'transport' => 'postMessage', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) ); + + $wp_customize->add_control( 'jetpack_content_post_details_comment', array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display comment link', 'jetpack' ), + 'type' => 'checkbox', + ) ); + } } // Add Featured Images options. - if ( true === $fi_archive || true === $fi_post || true === $fi_page ) { + if ( true === $fi_archive || true === $fi_post || true === $fi_page || true === $fi_portfolio || true === $fi_fallback ) { $wp_customize->add_setting( 'jetpack_content_featured_images_title' ); $wp_customize->add_control( new Jetpack_Customize_Control_Title( $wp_customize, 'jetpack_content_featured_images_title', array( 'section' => 'jetpack_content_options', - 'label' => esc_html__( 'Featured Images', 'jetpack' ), + '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" target="_blank"><span class="screen-reader-text">%1$s</span></a>', esc_html__( 'Learn more about Featured Images', 'jetpack' ) ), 'type' => 'title', + 'active_callback' => 'jetpack_post_thumbnail_supports', ) ) ); // Featured Images: Archive @@ -220,6 +244,7 @@ function jetpack_content_options_customize_register( $wp_customize ) { 'section' => 'jetpack_content_options', 'label' => esc_html__( 'Display on blog and archives', 'jetpack' ), 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', ) ); } @@ -235,6 +260,7 @@ function jetpack_content_options_customize_register( $wp_customize ) { 'section' => 'jetpack_content_options', 'label' => esc_html__( 'Display on single posts', 'jetpack' ), 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', ) ); } @@ -250,6 +276,39 @@ function jetpack_content_options_customize_register( $wp_customize ) { 'section' => 'jetpack_content_options', 'label' => esc_html__( 'Display on pages', 'jetpack' ), 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', + ) ); + } + + // Featured Images: Portfolio + if ( true === $fi_portfolio && post_type_exists( 'jetpack-portfolio' ) ) { + $wp_customize->add_setting( 'jetpack_content_featured_images_portfolio', array( + 'default' => $fi_portfolio_default, + 'type' => 'option', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) ); + + $wp_customize->add_control( 'jetpack_content_featured_images_portfolio', array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Display on single projects', 'jetpack' ), + 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', + ) ); + } + + // Featured Images: Fallback + if ( true === $fi_fallback ) { + $wp_customize->add_setting( 'jetpack_content_featured_images_fallback', array( + 'default' => $fi_fallback_default, + 'type' => 'option', + 'sanitize_callback' => 'jetpack_content_options_sanitize_checkbox', + ) ); + + $wp_customize->add_control( 'jetpack_content_featured_images_fallback', array( + 'section' => 'jetpack_content_options', + 'label' => esc_html__( 'Automatically use first image in post', 'jetpack' ), + 'type' => 'checkbox', + 'active_callback' => 'jetpack_post_thumbnail_supports', ) ); } } @@ -257,6 +316,13 @@ function jetpack_content_options_customize_register( $wp_customize ) { add_action( 'customize_register', 'jetpack_content_options_customize_register' ); /** + * Return whether the theme supports Post Thumbnails. + */ +function jetpack_post_thumbnail_supports() { + return ( current_theme_supports( 'post-thumbnails' ) ); +} + +/** * Sanitize the checkbox. * * @param int $input. @@ -295,6 +361,7 @@ function jetpack_content_options_customize_preview_js() { $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; + $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; wp_enqueue_script( 'jetpack-content-options-customizer', plugins_url( 'customizer.js', __FILE__ ), array( 'customize-preview' ), '1.0', true ); @@ -308,6 +375,7 @@ function jetpack_content_options_customize_preview_js() { 'categories' => $categories, 'tags' => $tags, 'author' => $author, + 'comment' => $comment, ) ); } add_action( 'customize_preview_init', 'jetpack_content_options_customize_preview_js' ); diff --git a/plugins/jetpack/modules/theme-tools/content-options/featured-images-fallback.php b/plugins/jetpack/modules/theme-tools/content-options/featured-images-fallback.php new file mode 100644 index 00000000..e0547467 --- /dev/null +++ b/plugins/jetpack/modules/theme-tools/content-options/featured-images-fallback.php @@ -0,0 +1,161 @@ +<?php +/** + * Get one image from a specified post in the following order: + * Featured Image then first image from the_content HTML + * and filter the post_thumbnail_html + * + * @param string $html The HTML for the image markup. + * @param int $post_id The post ID to check. + * @param int $post_thumbnail_id The ID of the featured image. + * @param string $size The image size to return, defaults to 'post-thumbnail'. + * @param string|array $attr Optional. Query string or array of attributes. + * + * @return string $html Thumbnail image with markup. + */ +function jetpack_featured_images_fallback_get_image( $html, $post_id, $post_thumbnail_id, $size, $attr ) { + $opts = jetpack_featured_images_get_settings(); + + if ( ! empty( $html ) || (bool) 1 !== (bool) $opts['fallback-option'] ) { + return trim( $html ); + } + + if ( jetpack_featured_images_should_load() ) { + if ( + ( true === $opts['archive'] && ( is_home() || is_archive() || is_search() ) && ! $opts['archive-option'] ) + || ( true === $opts['post'] && is_single() && ! $opts['post-option'] ) + || ! $opts['fallback-option'] + ) { + return trim( $html ); + } + } + + if ( class_exists( 'Jetpack_PostImages' ) ) { + global $_wp_additional_image_sizes; + + $args = array( + 'from_thumbnail' => false, + 'from_slideshow' => true, + 'from_gallery' => true, + 'from_attachment' => false, + ); + + $image = Jetpack_PostImages::get_image( $post_id, $args ); + + if ( ! empty( $image ) ) { + $image['width'] = ''; + $image['height'] = ''; + $image['crop'] = ''; + + if ( array_key_exists( $size, $_wp_additional_image_sizes ) ) { + $image['width'] = $_wp_additional_image_sizes[ $size ]['width']; + $image['height'] = $_wp_additional_image_sizes[ $size ]['height']; + $image['crop'] = $_wp_additional_image_sizes[ $size ]['crop']; + } + + $image_src = Jetpack_PostImages::fit_image_url( $image['src'], $image['width'], $image['height'] ); + + // Use the theme's crop setting rather than forcing to true + $image_src = add_query_arg( 'crop', $image['crop'], $image_src ); + + $html = '<img src="' . esc_url( $image_src ) . '" title="' . esc_attr( strip_tags( get_the_title() ) ) . '" class="attachment-' . esc_attr( $size ) . ' wp-post-image" />'; + + return trim( $html ); + } + } + + return trim( $html ); +} +add_filter( 'post_thumbnail_html', 'jetpack_featured_images_fallback_get_image', 10, 5 ); + +/** + * Get URL of one image from a specified post in the following order: + * Featured Image then first image from the_content HTML + * + * @param int $post_id The post ID to check. + * @param int $post_thumbnail_id The ID of the featured image. + * @param string $size The image size to return, defaults to 'post-thumbnail'. + * + * @return string|null $image_src The URL of the thumbnail image. + */ +function jetpack_featured_images_fallback_get_image_src( $post_id, $post_thumbnail_id, $size ) { + $image_src = wp_get_attachment_image_src( $post_thumbnail_id, $size ); + $image_src = ( ! empty( $image_src[0] ) ) ? $image_src[0] : null; + $opts = jetpack_featured_images_get_settings(); + + if ( ! empty( $image_src ) || (bool) 1 !== (bool) $opts['fallback-option'] ) { + return esc_url( $image_src ); + } + + if ( jetpack_featured_images_should_load() ) { + if ( ( true === $opts['archive'] && ( is_home() || is_archive() || is_search() ) && ! $opts['archive-option'] ) + || ( true === $opts['post'] && is_single() && ! $opts['post-option'] ) ) { + return esc_url( $image_src ); + } + } + + if ( class_exists( 'Jetpack_PostImages' ) ) { + global $_wp_additional_image_sizes; + + $args = array( + 'from_thumbnail' => false, + 'from_slideshow' => true, + 'from_gallery' => true, + 'from_attachment' => false, + ); + + $image = Jetpack_PostImages::get_image( $post_id, $args ); + + if ( ! empty( $image ) ) { + $image['width'] = ''; + $image['height'] = ''; + $image['crop'] = ''; + + if ( array_key_exists( $size, $_wp_additional_image_sizes ) ) { + $image['width'] = $_wp_additional_image_sizes[ $size ]['width']; + $image['height'] = $_wp_additional_image_sizes[ $size ]['height']; + $image['crop'] = $_wp_additional_image_sizes[ $size ]['crop']; + } + + $image_src = Jetpack_PostImages::fit_image_url( $image['src'], $image['width'], $image['height'] ); + + // Use the theme's crop setting rather than forcing to true + $image_src = add_query_arg( 'crop', $image['crop'], $image_src ); + + return esc_url( $image_src ); + } + } + + return esc_url( $image_src ); +} + +/** + * Check if post has an image attached, including a fallback. + * + * @param int $post The post ID to check. + * + * @return bool + */ +function jetpack_has_featured_image( $post = null ) { + return (bool) get_the_post_thumbnail( $post ); +} + +/** + * Adds custom class to the array of post classes. + * + * @param array $classes Classes for the post element. + * @param array $class Optional. Comma separated list of additional classes. + * @param array $post_id Unique The post ID to check + * + * @return array $classes + */ +function jetpack_featured_images_post_class( $classes, $class, $post_id ) { + $post_password_required = post_password_required( $post_id ); + $opts = jetpack_featured_images_get_settings(); + + if ( jetpack_has_featured_image( $post_id ) && (bool) 1 === (bool) $opts['fallback-option'] && ! is_attachment() && ! $post_password_required && 'post' === get_post_type() ) { + $classes[] = 'has-post-thumbnail'; + } + + return $classes; +} +add_filter( 'post_class', 'jetpack_featured_images_post_class', 10, 3 ); diff --git a/plugins/jetpack/modules/theme-tools/content-options/featured-images.php b/plugins/jetpack/modules/theme-tools/content-options/featured-images.php index d5387ad8..048ce760 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/featured-images.php +++ b/plugins/jetpack/modules/theme-tools/content-options/featured-images.php @@ -7,11 +7,19 @@ function jetpack_featured_images_remove_post_thumbnail( $metadata, $object_id, $ // Returns false if the archive option or singular option is unticked. if ( ( true === $opts['archive'] && ( is_home() || is_archive() || is_search() ) && ! $opts['archive-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() ) - || ( true === $opts['post'] && is_single() && ! $opts['post-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() ) - || ( true === $opts['page'] && is_singular() && is_page() && ! $opts['page-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() ) ) { + || ( true === $opts['post'] && is_single() && ! jetpack_is_product() && ! $opts['post-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() ) + || ( true === $opts['page'] && is_singular() && is_page() && ! $opts['page-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() ) + || ( true === $opts['portfolio'] && post_type_exists( 'jetpack-portfolio' ) && is_singular( 'jetpack-portfolio' ) && ! $opts['portfolio-option'] && ( isset( $meta_key ) && '_thumbnail_id' === $meta_key ) && in_the_loop() ) ) { return false; } else { return $metadata; } } add_filter( 'get_post_metadata', 'jetpack_featured_images_remove_post_thumbnail', true, 4 ); + +/** + * Check if we are in a WooCommerce Product in order to exclude it from the is_single check. + */ +function jetpack_is_product() { + return ( function_exists( 'is_product' ) ) ? is_product() : false; +} diff --git a/plugins/jetpack/modules/theme-tools/content-options/post-details.php b/plugins/jetpack/modules/theme-tools/content-options/post-details.php index cb4b5a7b..3116bc3c 100644 --- a/plugins/jetpack/modules/theme-tools/content-options/post-details.php +++ b/plugins/jetpack/modules/theme-tools/content-options/post-details.php @@ -10,8 +10,8 @@ function jetpack_post_details_enqueue_scripts() { return; } - list( $date_option, $categories_option, $tags_option, $author_option ) = $options; - list( $date, $categories, $tags, $author ) = $definied; + list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options; + list( $date, $categories, $tags, $author, $comment ) = $definied; $elements = array(); @@ -35,6 +35,11 @@ function jetpack_post_details_enqueue_scripts() { $elements[] = $author; } + // If comment option is unticked, add it to the list of classes. + if ( 1 != $comment_option && ! empty( $comment ) ) { + $elements[] = $comment; + } + // Get the list of classes. $elements = implode( ', ', $elements ); @@ -57,8 +62,8 @@ function jetpack_post_details_body_classes( $classes ) { return $classes; } - list( $date_option, $categories_option, $tags_option, $author_option ) = $options; - list( $date, $categories, $tags, $author ) = $definied; + list( $date_option, $categories_option, $tags_option, $author_option, $comment_option ) = $options; + list( $date, $categories, $tags, $author, $comment ) = $definied; // If date option is unticked, add a class of 'date-hidden' to the body. if ( 1 != $date_option && ! empty( $date ) ) { @@ -80,6 +85,11 @@ function jetpack_post_details_body_classes( $classes ) { $classes[] = 'author-hidden'; } + // If comment option is unticked, add a class of 'comment-hidden' to the body. + if ( 1 != $comment_option && ! empty( $comment ) ) { + $classes[] = 'comment-hidden'; + } + return $classes; } add_filter( 'body_class', 'jetpack_post_details_body_classes' ); @@ -108,13 +118,15 @@ function jetpack_post_details_should_run() { $categories = ( ! empty( $post_details['categories'] ) ) ? $post_details['categories'] : null; $tags = ( ! empty( $post_details['tags'] ) ) ? $post_details['tags'] : null; $author = ( ! empty( $post_details['author'] ) ) ? $post_details['author'] : null; + $comment = ( ! empty( $post_details['comment'] ) ) ? $post_details['comment'] : null; - // If there is no stylesheet and there are no date, categories, tags or author declared, don't continue. + // If there is no stylesheet and there are no date, categories, tags, author or comment declared, don't continue. if ( empty( $post_details['stylesheet'] ) && ( empty( $date ) || empty( $categories ) || empty( $tags ) - || empty( $author ) ) ) { + || empty( $author ) + || empty( $comment ) ) ) { return $void; } @@ -122,12 +134,13 @@ function jetpack_post_details_should_run() { $categories_option = get_option( 'jetpack_content_post_details_categories', 1 ); $tags_option = get_option( 'jetpack_content_post_details_tags', 1 ); $author_option = get_option( 'jetpack_content_post_details_author', 1 ); + $comment_option = get_option( 'jetpack_content_post_details_comment', 1 ); - $options = array( $date_option, $categories_option, $tags_option, $author_option ); - $definied = array( $date, $categories, $tags, $author ); + $options = array( $date_option, $categories_option, $tags_option, $author_option, $comment_option ); + $definied = array( $date, $categories, $tags, $author, $comment ); // If all the options are ticked, don't continue. - if ( array( 1, 1, 1, 1 ) === $options ) { + if ( array( 1, 1, 1, 1, 1 ) === $options ) { return $void; } |