diff --git a/wp-content/plugins/gp-premium/blog/functions/customizer.php b/wp-content/plugins/gp-premium/blog/functions/customizer.php index c8c16f8f..6eefcb53 100644 --- a/wp-content/plugins/gp-premium/blog/functions/customizer.php +++ b/wp-content/plugins/gp-premium/blog/functions/customizer.php @@ -537,13 +537,33 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { ) ); + $wp_customize->add_setting( + 'generate_blog_settings[post_image_size]', + array( + 'default' => $defaults['post_image_size'], + 'type' => 'option', + 'sanitize_callback' => 'generate_premium_sanitize_choices', + ) + ); + + $wp_customize->add_control( + 'generate_blog_settings[post_image_size]', + array( + 'type' => 'select', + 'label' => __( 'Media Attachment Size', 'gp-premium' ), + 'section' => 'generate_blog_section', + 'choices' => generate_blog_get_image_sizes(), + 'settings' => 'generate_blog_settings[post_image_size]', + 'active_callback' => 'generate_premium_featured_image_active', + ) + ); + // Width $wp_customize->add_setting( 'generate_blog_settings[post_image_width]', array( 'default' => $defaults['post_image_width'], 'capability' => 'edit_theme_options', 'type' => 'option', - 'transport' => 'postMessage', 'sanitize_callback' => 'generate_premium_sanitize_empty_absint', ) ); @@ -554,11 +574,6 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'type' => 'number', 'label' => __( 'Width', 'gp-premium' ), 'section' => 'generate_blog_section', - 'input_attrs' => array( - 'style' => 'text-align:center;', - 'placeholder' => __( 'Auto', 'gp-premium' ), - 'min' => 5, - ), 'settings' => 'generate_blog_settings[post_image_width]', 'active_callback' => 'generate_premium_featured_image_active', ) @@ -570,7 +585,6 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'default' => $defaults['post_image_height'], 'capability' => 'edit_theme_options', 'type' => 'option', - 'transport' => 'postMessage', 'sanitize_callback' => 'generate_premium_sanitize_empty_absint', ) ); @@ -581,24 +595,21 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'type' => 'number', 'label' => __( 'Height', 'gp-premium' ), 'section' => 'generate_blog_section', - 'input_attrs' => array( - 'style' => 'text-align:center;', - 'placeholder' => __( 'Auto', 'gp-premium' ), - 'min' => 5, - ), 'settings' => 'generate_blog_settings[post_image_height]', 'active_callback' => 'generate_premium_featured_image_active', ) ); - // Save dimensions $wp_customize->add_control( - new GeneratePress_Refresh_Button_Customize_Control( + new GeneratePress_Information_Customize_Control( $wp_customize, - 'post_image_apply_sizes', + 'generate_regenerate_images_notice', array( - 'section' => 'generate_blog_section', - 'label' => __( 'Apply', 'gp-premium' ), + 'section' => 'generate_blog_section', + 'description' => sprintf( + __( 'We will attempt to serve exact image sizes based on your width/height settings. If that is not possible, we will resize your images using CSS. Learn more about featured image sizing %s.', 'gp-premium' ), + '' . __( 'here', 'gp-premium' ) . '' + ), 'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname', 'active_callback' => 'generate_premium_featured_image_active', ) @@ -701,13 +712,33 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { ) ); + $wp_customize->add_setting( + 'generate_blog_settings[single_post_image_size]', + array( + 'default' => $defaults['single_post_image_size'], + 'type' => 'option', + 'sanitize_callback' => 'generate_premium_sanitize_choices', + ) + ); + + $wp_customize->add_control( + 'generate_blog_settings[single_post_image_size]', + array( + 'type' => 'select', + 'label' => __( 'Media Attachment Size', 'gp-premium' ), + 'section' => 'generate_blog_section', + 'choices' => generate_blog_get_image_sizes(), + 'settings' => 'generate_blog_settings[single_post_image_size]', + 'active_callback' => 'generate_premium_featured_image_active', + ) + ); + // Width $wp_customize->add_setting( 'generate_blog_settings[single_post_image_width]', array( 'default' => $defaults['single_post_image_width'], 'capability' => 'edit_theme_options', 'type' => 'option', - 'transport' => 'postMessage', 'sanitize_callback' => 'generate_premium_sanitize_empty_absint', ) ); @@ -718,13 +749,8 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'type' => 'number', 'label' => __( 'Width', 'gp-premium' ), 'section' => 'generate_blog_section', - 'input_attrs' => array( - 'style' => 'text-align:center;', - 'placeholder' => __( 'Auto', 'gp-premium' ), - 'min' => 5, - ), 'settings' => 'generate_blog_settings[single_post_image_width]', - 'active_callback' => 'generate_premium_single_featured_image_active', + 'active_callback' => 'generate_premium_featured_image_active', ) ); @@ -734,7 +760,6 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'default' => $defaults['single_post_image_height'], 'capability' => 'edit_theme_options', 'type' => 'option', - 'transport' => 'postMessage', 'sanitize_callback' => 'generate_premium_sanitize_empty_absint', ) ); @@ -745,26 +770,23 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'type' => 'number', 'label' => __( 'Height', 'gp-premium' ), 'section' => 'generate_blog_section', - 'input_attrs' => array( - 'style' => 'text-align:center;', - 'placeholder' => __( 'Auto', 'gp-premium' ), - 'min' => 5, - ), 'settings' => 'generate_blog_settings[single_post_image_height]', - 'active_callback' => 'generate_premium_single_featured_image_active', + 'active_callback' => 'generate_premium_featured_image_active', ) ); - // Save dimensions $wp_customize->add_control( - new GeneratePress_Refresh_Button_Customize_Control( + new GeneratePress_Information_Customize_Control( $wp_customize, - 'single_post_image_apply_sizes', + 'generate_regenerate_single_post_images_notice', array( - 'section' => 'generate_blog_section', - 'label' => __( 'Apply', 'gp-premium' ), + 'section' => 'generate_blog_section', + 'description' => sprintf( + __( 'We will attempt to serve exact image sizes based on your width/height settings. If that is not possible, we will resize your images using CSS. Learn more about featured image sizing %s.', 'gp-premium' ), + '' . __( 'here', 'gp-premium' ) . '' + ), 'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname', - 'active_callback' => 'generate_premium_single_featured_image_active', + 'active_callback' => 'generate_premium_featured_image_active', ) ) ); @@ -865,13 +887,33 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { ) ); + $wp_customize->add_setting( + 'generate_blog_settings[page_post_image_size]', + array( + 'default' => $defaults['page_post_image_size'], + 'type' => 'option', + 'sanitize_callback' => 'generate_premium_sanitize_choices', + ) + ); + + $wp_customize->add_control( + 'generate_blog_settings[page_post_image_size]', + array( + 'type' => 'select', + 'label' => __( 'Media Attachment Size', 'gp-premium' ), + 'section' => 'generate_blog_section', + 'choices' => generate_blog_get_image_sizes(), + 'settings' => 'generate_blog_settings[page_post_image_size]', + 'active_callback' => 'generate_premium_featured_image_active', + ) + ); + // Width $wp_customize->add_setting( 'generate_blog_settings[page_post_image_width]', array( 'default' => $defaults['page_post_image_width'], 'capability' => 'edit_theme_options', 'type' => 'option', - 'transport' => 'postMessage', 'sanitize_callback' => 'generate_premium_sanitize_empty_absint', ) ); @@ -882,13 +924,8 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'type' => 'number', 'label' => __( 'Width', 'gp-premium' ), 'section' => 'generate_blog_section', - 'input_attrs' => array( - 'style' => 'text-align:center;', - 'placeholder' => __( 'Auto', 'gp-premium' ), - 'min' => 5, - ), 'settings' => 'generate_blog_settings[page_post_image_width]', - 'active_callback' => 'generate_premium_single_page_featured_image_active', + 'active_callback' => 'generate_premium_featured_image_active', ) ); @@ -898,7 +935,6 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'default' => $defaults['page_post_image_height'], 'capability' => 'edit_theme_options', 'type' => 'option', - 'transport' => 'postMessage', 'sanitize_callback' => 'generate_premium_sanitize_empty_absint', ) ); @@ -909,26 +945,23 @@ if ( ! function_exists( 'generate_blog_customize_register' ) ) { 'type' => 'number', 'label' => __( 'Height', 'gp-premium' ), 'section' => 'generate_blog_section', - 'input_attrs' => array( - 'style' => 'text-align:center;', - 'placeholder' => __( 'Auto', 'gp-premium' ), - 'min' => 5, - ), 'settings' => 'generate_blog_settings[page_post_image_height]', - 'active_callback' => 'generate_premium_single_page_featured_image_active', + 'active_callback' => 'generate_premium_featured_image_active', ) ); - // Save dimensions $wp_customize->add_control( - new GeneratePress_Refresh_Button_Customize_Control( + new GeneratePress_Information_Customize_Control( $wp_customize, - 'page_post_image_apply_sizes', + 'generate_regenerate_page_images_notice', array( - 'section' => 'generate_blog_section', - 'label' => __( 'Apply', 'gp-premium' ), + 'section' => 'generate_blog_section', + 'description' => sprintf( + __( 'We will attempt to serve exact image sizes based on your width/height settings. If that is not possible, we will resize your images using CSS. Learn more about featured image sizing %s.', 'gp-premium' ), + '' . __( 'here', 'gp-premium' ) . '' + ), 'settings' => ( isset( $wp_customize->selective_refresh ) ) ? array() : 'blogname', - 'active_callback' => 'generate_premium_single_page_featured_image_active', + 'active_callback' => 'generate_premium_featured_image_active', ) ) ); @@ -1042,34 +1075,6 @@ add_action( 'customize_controls_print_styles', 'generate_blog_customizer_control function generate_blog_customizer_controls_css() { ?> true, 'post_image_position' => '', 'post_image_alignment' => 'post-image-aligned-center', + 'post_image_size' => 'full', 'post_image_width' => '', 'post_image_height' => '', 'post_image_padding' => true, 'single_post_image' => true, 'single_post_image_position' => 'inside-content', 'single_post_image_alignment' => 'center', + 'single_post_image_size' => 'full', 'single_post_image_width' => '', 'single_post_image_height' => '', 'single_post_image_padding' => true, 'page_post_image' => true, 'page_post_image_position' => 'above-content', 'page_post_image_alignment' => 'center', + 'page_post_image_size' => 'full', 'page_post_image_width' => '', 'page_post_image_height' => '', 'page_post_image_padding' => true, @@ -47,7 +50,7 @@ if ( ! function_exists( 'generate_blog_get_defaults' ) ) { 'single_post_navigation' => true, 'column_layout' => false, 'columns' => '50', - 'featured_column' => false + 'featured_column' => false, ); return apply_filters( 'generate_blog_option_defaults', $generate_blog_defaults ); diff --git a/wp-content/plugins/gp-premium/blog/functions/generate-blog.php b/wp-content/plugins/gp-premium/blog/functions/generate-blog.php index 5a2cacb8..23a5373a 100644 --- a/wp-content/plugins/gp-premium/blog/functions/generate-blog.php +++ b/wp-content/plugins/gp-premium/blog/functions/generate-blog.php @@ -122,6 +122,22 @@ if ( ! function_exists( 'generate_blog_post_classes' ) ) { $classes[] = 'no-featured-image-padding'; } + $atts = generate_get_blog_image_attributes(); + + if ( ! is_singular() && has_post_thumbnail() && ! empty( $atts ) ) { + $values = array( + $atts['width'], + $atts['height'], + $atts['crop'], + ); + + $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID(), 'full' ), $values ); + + if ( $image_src && ( ! $image_src[3] || ! apply_filters( 'generate_use_featured_image_size_match', true ) ) ) { + $classes[] = 'resize-featured-image'; + } + } + return $classes; } } @@ -288,6 +304,36 @@ if ( ! function_exists( 'generate_blog_css' ) ) { $return .= '}'; } + $atts = generate_get_blog_image_attributes(); + + if ( ! empty( $atts ) ) { + $image_width = $atts['width'] && 9999 !== $atts['width'] ? 'width: ' . $atts['width'] . 'px;' : ''; + $image_height = $atts['height'] && 9999 !== $atts['height'] ? 'height: ' . $atts['height'] . 'px;' : ''; + $image_crop = $atts['crop'] ? '-o-object-fit: cover;object-fit: cover;' : ''; + + if ( ! $image_width && $image_height ) { + $image_crop = '-o-object-fit: cover;object-fit: cover;'; + } + + if ( ! is_singular() ) { + $return .= '.resize-featured-image .post-image img {' . $image_width . $image_height . $image_crop . '}'; + } + + if ( is_single() || is_page() ) { + $values = array( + $atts['width'], + $atts['height'], + $atts['crop'], + ); + + $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID(), 'full' ), $values ); + + if ( $image_src && ( ! $image_src[3] || ! apply_filters( 'generate_use_featured_image_size_match', true ) ) ) { + $return .= '.featured-image img {' . $image_width . $image_height . $image_crop . '}'; + } + } + } + return $return; } } diff --git a/wp-content/plugins/gp-premium/blog/functions/images.php b/wp-content/plugins/gp-premium/blog/functions/images.php index 78dba4c5..ddd62801 100644 --- a/wp-content/plugins/gp-premium/blog/functions/images.php +++ b/wp-content/plugins/gp-premium/blog/functions/images.php @@ -1,8 +1,73 @@ 'full', + ); + + foreach ( $sizes as $key => $name ) { + $new_sizes[ $name ] = $name; + } + + return $new_sizes; +} + +add_filter( 'generate_page_header_default_size', 'generate_blog_set_featured_image_size' ); +/** + * Set our featured image sizes. + * + * @since 1.10.0 + * + * @param string $size The existing size. + * @return string The new size. + */ +function generate_blog_set_featured_image_size( $size ) { + $settings = wp_parse_args( + get_option( 'generate_blog_settings', array() ), + generate_blog_get_defaults() + ); + + if ( ! is_singular() ) { + $size = $settings['post_image_size']; + } + + if ( is_single() ) { + $size = $settings['single_post_image_size']; + } + + if ( is_page() ) { + $size = $settings['page_post_image_size']; + } + + $atts = generate_get_blog_image_attributes(); + + if ( ! empty( $atts ) ) { + $values = array( + $atts['width'], + $atts['height'], + $atts['crop'], + ); + + $image_src = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID(), 'full' ), $values ); + + if ( $image_src && $image_src[3] && apply_filters( 'generate_use_featured_image_size_match', true ) ) { + return $values; + } else { + return $size; + } + } + + return $size; } if ( ! function_exists( 'generate_get_blog_image_attributes' ) ) { @@ -110,7 +175,7 @@ if ( ! function_exists( 'generate_blog_setup' ) ) { add_filter( 'generate_featured_image_output', 'generate_blog_featured_image' ); /** - * Filter our core featured image so we can include support for resized images. + * Remove featured image if set or using WooCommerce. * * @since 1.5 * @return string The image HTML @@ -121,35 +186,11 @@ function generate_blog_featured_image( $output ) { generate_blog_get_defaults() ); - $image_atts = generate_get_blog_image_attributes(); - $image_id = get_post_thumbnail_id( get_the_ID(), 'full' ); - if ( ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) || ! $settings['post_image'] ) { return false; } - if ( $image_atts && function_exists( 'ipq_get_theme_image' ) ) { - $image_html = ipq_get_theme_image( $image_id, - array( - array( $image_atts[ 'width' ], $image_atts[ 'height' ], $image_atts[ 'crop' ] ) - ), - array( - 'itemprop' => 'image', - ) - ); - } else { - return $output; - } - - return apply_filters( 'generate_resized_featured_image_output', sprintf( - '