Merge pull request #19934 from woocommerce/fix/19819

Add protocol to URLs for thumbnails in cart.
This commit is contained in:
Claudiu Lodromanean 2018-05-09 10:09:17 -07:00 committed by GitHub
commit 7a6b0d8cf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 10 deletions

View File

@ -1809,7 +1809,7 @@ class WC_Product extends WC_Abstract_Legacy_Product {
$image = '';
}
return apply_filters( 'woocommerce_product_get_image', wc_get_relative_url( $image ), $this, $size, $attr, $placeholder, $image );
return apply_filters( 'woocommerce_product_get_image', $image, $this, $size, $attr, $placeholder, $image );
}
/**

View File

@ -78,14 +78,14 @@ abstract class WC_Widget extends WP_Widget {
* @return bool true if the widget is cached otherwise false
*/
public function get_cached_widget( $args ) {
$cache = wp_cache_get( apply_filters( 'woocommerce_cached_widget_id', $this->widget_id ), 'widget' );
$cache = wp_cache_get( $this->get_widget_id_for_cache( $this->widget_id ), 'widget' );
if ( ! is_array( $cache ) ) {
$cache = array();
}
if ( isset( $cache[ $args['widget_id'] ] ) ) {
echo $cache[ $args['widget_id'] ]; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
if ( isset( $cache[ $this->get_widget_id_for_cache( $args['widget_id'] ) ] ) ) {
echo $cache[ $this->get_widget_id_for_cache( $args['widget_id'] ) ]; // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
return true;
}
@ -100,15 +100,15 @@ abstract class WC_Widget extends WP_Widget {
* @return string the content that was cached
*/
public function cache_widget( $args, $content ) {
$cache = wp_cache_get( apply_filters( 'woocommerce_cached_widget_id', $this->widget_id ), 'widget' );
$cache = wp_cache_get( $this->get_widget_id_for_cache( $this->widget_id ), 'widget' );
if ( ! is_array( $cache ) ) {
$cache = array();
}
$cache[ $args['widget_id'] ] = $content;
$cache[ $this->get_widget_id_for_cache( $args['widget_id'] ) ] = $content;
wp_cache_set( apply_filters( 'woocommerce_cached_widget_id', $this->widget_id ), $cache, 'widget' );
wp_cache_set( $this->get_widget_id_for_cache( $this->widget_id ), $cache, 'widget' );
return $content;
}
@ -117,7 +117,9 @@ abstract class WC_Widget extends WP_Widget {
* Flush the cache.
*/
public function flush_widget_cache() {
wp_cache_delete( apply_filters( 'woocommerce_cached_widget_id', $this->widget_id ), 'widget' );
foreach ( array( 'https', 'http' ) as $scheme ) {
wp_cache_delete( $this->get_widget_id_for_cache( $this->widget_id, $scheme ), 'widget' );
}
}
/**
@ -347,4 +349,22 @@ abstract class WC_Widget extends WP_Widget {
return $link;
}
/**
* Get widget id plus scheme/protocol to prevent serving mixed content from (persistently) cached widgets.
*
* @since 3.4.0
* @param string $widget_id Id of the cached widget.
* @param string $scheme Scheme for the widget id.
* @return string Widget id including scheme/protocol.
*/
protected function get_widget_id_for_cache( $widget_id, $scheme = '' ) {
if ( $scheme ) {
$widget_id_for_cache = $widget_id . '-' . $scheme;
} else {
$widget_id_for_cache = $widget_id . '-' . ( is_ssl() ? 'https' : 'http' );
}
return apply_filters( 'woocommerce_cached_widget_id', $widget_id_for_cache );
}
}

View File

@ -51,10 +51,10 @@ do_action( 'woocommerce_before_mini_cart' ); ?>
), $cart_item_key );
?>
<?php if ( empty( $product_permalink ) ) : ?>
<?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . $product_name . '&nbsp;'; ?>
<?php echo $thumbnail . $product_name . '&nbsp;'; ?>
<?php else : ?>
<a href="<?php echo esc_url( $product_permalink ); ?>">
<?php echo str_replace( array( 'http:', 'https:' ), '', $thumbnail ) . $product_name . '&nbsp;'; ?>
<?php echo $thumbnail . $product_name . '&nbsp;'; ?>
</a>
<?php endif; ?>
<?php echo wc_get_formatted_cart_item_data( $cart_item ); ?>