updated plugin GP Premium
version 1.11.2
This commit is contained in:
@ -1,5 +1,13 @@
|
||||
<?php
|
||||
defined( 'WPINC' ) or die;
|
||||
/**
|
||||
* Functions specific to featured images.
|
||||
*
|
||||
* @package GP Premium
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // No direct access, please.
|
||||
}
|
||||
|
||||
/**
|
||||
* Collects all available image sizes which we use in the Customizer.
|
||||
@ -95,13 +103,13 @@ if ( ! function_exists( 'generate_get_blog_image_attributes' ) ) {
|
||||
$ignore_crop = array( '', '0', '9999' );
|
||||
|
||||
$atts = array(
|
||||
'width' => ( in_array( $settings["{$single}post_image_width"], $ignore_crop ) ) ? 9999 : absint( $settings["{$single}post_image_width"] ),
|
||||
'height' => ( in_array( $settings["{$single}post_image_height"], $ignore_crop ) ) ? 9999 : absint( $settings["{$single}post_image_height"] ),
|
||||
'crop' => ( in_array( $settings["{$single}post_image_width"], $ignore_crop ) || in_array( $settings["{$single}post_image_height"], $ignore_crop ) ) ? false : true
|
||||
'width' => ( in_array( $settings[ "{$single}post_image_width" ], $ignore_crop ) ) ? 9999 : absint( $settings[ "{$single}post_image_width" ] ),
|
||||
'height' => ( in_array( $settings[ "{$single}post_image_height" ], $ignore_crop ) ) ? 9999 : absint( $settings[ "{$single}post_image_height" ] ),
|
||||
'crop' => ( in_array( $settings[ "{$single}post_image_width" ], $ignore_crop ) || in_array( $settings[ "{$single}post_image_height" ], $ignore_crop ) ) ? false : true,
|
||||
);
|
||||
|
||||
// If there's no height or width, empty the array
|
||||
if ( 9999 == $atts[ 'width' ] && 9999 == $atts[ 'height' ] ) {
|
||||
// If there's no height or width, empty the array.
|
||||
if ( 9999 == $atts['width'] && 9999 == $atts['height'] ) { // phpcs:ignore
|
||||
$atts = array();
|
||||
}
|
||||
|
||||
@ -122,13 +130,13 @@ if ( ! function_exists( 'generate_blog_setup' ) ) {
|
||||
generate_blog_get_defaults()
|
||||
);
|
||||
|
||||
// Move our featured images to above the title
|
||||
if ( 'post-image-above-header' == $settings['post_image_position'] ) {
|
||||
// Move our featured images to above the title.
|
||||
if ( 'post-image-above-header' === $settings['post_image_position'] ) {
|
||||
remove_action( 'generate_after_entry_header', 'generate_post_image' );
|
||||
add_action( 'generate_before_content', 'generate_post_image' );
|
||||
|
||||
// If we're using the Page Header add-on, move those as well
|
||||
if ( function_exists('generate_page_header_post_image') ) {
|
||||
// If we're using the Page Header add-on, move those as well.
|
||||
if ( function_exists( 'generate_page_header_post_image' ) ) {
|
||||
remove_action( 'generate_after_entry_header', 'generate_page_header_post_image' );
|
||||
add_action( 'generate_before_content', 'generate_page_header_post_image' );
|
||||
}
|
||||
@ -137,12 +145,13 @@ if ( ! function_exists( 'generate_blog_setup' ) ) {
|
||||
$page_header_content = false;
|
||||
if ( function_exists( 'generate_page_header_get_options' ) ) {
|
||||
$options = generate_page_header_get_options();
|
||||
if ( '' !== $options[ 'content' ] ) {
|
||||
|
||||
if ( $options && '' !== $options['content'] ) {
|
||||
$page_header_content = true;
|
||||
}
|
||||
|
||||
// If our Page Header has no content, remove it
|
||||
// This will allow the Blog add-on to add an image for us
|
||||
// If our Page Header has no content, remove it.
|
||||
// This will allow the Blog add-on to add an image for us.
|
||||
if ( ! $page_header_content && is_singular() ) {
|
||||
remove_action( 'generate_before_content', 'generate_page_header' );
|
||||
remove_action( 'generate_after_entry_header', 'generate_page_header' );
|
||||
@ -150,23 +159,23 @@ if ( ! function_exists( 'generate_blog_setup' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
// Remove the core theme featured image
|
||||
// I would like to filter instead one day
|
||||
// Remove the core theme featured image.
|
||||
// I would like to filter instead one day.
|
||||
remove_action( 'generate_after_header', 'generate_featured_page_header' );
|
||||
remove_action( 'generate_before_content', 'generate_featured_page_header_inside_single' );
|
||||
|
||||
$location = generate_blog_get_singular_template();
|
||||
|
||||
if ( $settings[$location . '_post_image'] && is_singular() && ! $page_header_content ) {
|
||||
if ( 'below-title' == $settings[$location . '_post_image_position'] ) {
|
||||
if ( $settings[ $location . '_post_image' ] && is_singular() && ! $page_header_content ) {
|
||||
if ( 'below-title' === $settings[ $location . '_post_image_position' ] ) {
|
||||
add_action( 'generate_after_entry_header', 'generate_blog_single_featured_image' );
|
||||
}
|
||||
|
||||
if ( 'inside-content' == $settings[$location . '_post_image_position'] ) {
|
||||
if ( 'inside-content' === $settings[ $location . '_post_image_position' ] ) {
|
||||
add_action( 'generate_before_content', 'generate_blog_single_featured_image' );
|
||||
}
|
||||
|
||||
if ( 'above-content' == $settings[$location . '_post_image_position'] ) {
|
||||
if ( 'above-content' === $settings[ $location . '_post_image_position' ] ) {
|
||||
add_action( 'generate_after_header', 'generate_blog_single_featured_image' );
|
||||
}
|
||||
}
|
||||
@ -178,6 +187,7 @@ add_filter( 'generate_featured_image_output', 'generate_blog_featured_image' );
|
||||
* Remove featured image if set or using WooCommerce.
|
||||
*
|
||||
* @since 1.5
|
||||
* @param string $output The existing output.
|
||||
* @return string The image HTML
|
||||
*/
|
||||
function generate_blog_featured_image( $output ) {
|
||||
@ -219,15 +229,27 @@ function generate_blog_single_featured_image() {
|
||||
|
||||
$location = generate_blog_get_singular_template();
|
||||
|
||||
if ( ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) || ! $settings[$location . '_post_image'] || ! $image_id ) {
|
||||
if ( ( function_exists( 'is_woocommerce' ) && is_woocommerce() ) || ! $settings[ $location . '_post_image' ] || ! $image_id ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$image_html = apply_filters( 'post_thumbnail_html',
|
||||
wp_get_attachment_image( $image_id, apply_filters( 'generate_page_header_default_size', 'full' ), '',
|
||||
array(
|
||||
'itemprop' => 'image',
|
||||
)
|
||||
$attrs = array(
|
||||
'itemprop' => 'image',
|
||||
);
|
||||
|
||||
if ( function_exists( 'generate_get_schema_type' ) ) {
|
||||
if ( 'microdata' !== generate_get_schema_type() ) {
|
||||
$attrs = array();
|
||||
}
|
||||
}
|
||||
|
||||
$image_html = apply_filters(
|
||||
'post_thumbnail_html', // phpcs:ignore -- Core filter.
|
||||
wp_get_attachment_image(
|
||||
$image_id,
|
||||
apply_filters( 'generate_page_header_default_size', 'full' ),
|
||||
'',
|
||||
$attrs
|
||||
),
|
||||
get_the_ID(),
|
||||
$image_id,
|
||||
@ -240,18 +262,23 @@ function generate_blog_single_featured_image() {
|
||||
$classes = array(
|
||||
is_page() ? 'page-header-image' : null,
|
||||
is_singular() && ! is_page() ? 'page-header-image-single' : null,
|
||||
'above-content' == $settings[$location . '_post_image_position'] ? 'grid-container grid-parent' : null,
|
||||
'above-content' === $settings[ $location . '_post_image_position' ] ? 'grid-container grid-parent' : null,
|
||||
);
|
||||
|
||||
$image_html = apply_filters( 'generate_single_featured_image_html', $image_html );
|
||||
|
||||
echo apply_filters( 'generate_single_featured_image_output', sprintf(
|
||||
'<div class="featured-image %2$s">
|
||||
%1$s
|
||||
</div>',
|
||||
$image_html,
|
||||
implode( ' ', $classes )
|
||||
), $image_html );
|
||||
// phpcs:ignore -- No need to escape here.
|
||||
echo apply_filters(
|
||||
'generate_single_featured_image_output',
|
||||
sprintf(
|
||||
'<div class="featured-image %2$s">
|
||||
%1$s
|
||||
</div>',
|
||||
$image_html,
|
||||
implode( ' ', $classes )
|
||||
),
|
||||
$image_html
|
||||
);
|
||||
}
|
||||
|
||||
add_filter( 'generate_blog_image_attributes', 'generate_blog_page_header_image_atts' );
|
||||
@ -274,13 +301,13 @@ function generate_blog_page_header_image_atts( $atts ) {
|
||||
|
||||
$options = generate_page_header_get_options();
|
||||
|
||||
if ( 'enable' == $options[ 'image_resize' ] ) {
|
||||
if ( $options && 'enable' === $options['image_resize'] ) {
|
||||
$ignore_crop = array( '', '0', '9999' );
|
||||
|
||||
$atts = array(
|
||||
'width' => ( in_array( $options[ 'image_width' ], $ignore_crop ) ) ? 9999 : absint( $options[ 'image_width' ] ),
|
||||
'height' => ( in_array( $options[ 'image_height' ], $ignore_crop ) ) ? 9999 : absint( $options[ 'image_height' ] ),
|
||||
'crop' => ( in_array( $options[ 'image_width' ], $ignore_crop ) || in_array( $options[ 'image_height' ], $ignore_crop ) ) ? false : true
|
||||
'width' => ( in_array( $options['image_width'], $ignore_crop ) ) ? 9999 : absint( $options['image_width'] ),
|
||||
'height' => ( in_array( $options['image_height'], $ignore_crop ) ) ? 9999 : absint( $options['image_height'] ),
|
||||
'crop' => ( in_array( $options['image_width'], $ignore_crop ) || in_array( $options['image_height'], $ignore_crop ) ) ? false : true,
|
||||
);
|
||||
}
|
||||
|
||||
@ -304,7 +331,7 @@ function generate_blog_page_header_link( $image_html ) {
|
||||
$options = generate_page_header_get_options();
|
||||
|
||||
if ( ! empty( $options['image_link'] ) ) {
|
||||
return '<a href="' . esc_url( $options[ 'image_link' ] ) . '"' . apply_filters( 'generate_page_header_link_target', '' ) . '>' . $image_html . '</a>';
|
||||
return '<a href="' . esc_url( $options['image_link'] ) . '"' . apply_filters( 'generate_page_header_link_target', '' ) . '>' . $image_html . '</a>';
|
||||
} else {
|
||||
return $image_html;
|
||||
}
|
||||
|
Reference in New Issue
Block a user