Merge pull request #16760 from woocommerce/update/16746

Handle external URLs for images
This commit is contained in:
Claudiu Lodromanean 2017-09-08 09:33:37 -07:00 committed by GitHub
commit fcb7da5599
2 changed files with 25 additions and 1 deletions

View File

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

View File

@ -1857,3 +1857,27 @@ function wc_delete_expired_transients() {
return absint( $rows + $rows2 );
}
add_action( 'woocommerce_installed', 'wc_delete_expired_transients' );
/**
* Make a URL relative, if possible.
*
* @since 3.2.0
* @param string $url URL to make relative.
* @return string
*/
function wc_get_relative_url( $url ) {
return wc_is_external_resource( $url ) ? $url : str_replace( array( 'http://', 'https://' ), '//', $url );
}
/**
* See if a resource is remote.
*
* @since 3.2.0
* @param string $url URL to check.
* @return bool
*/
function wc_is_external_resource( $url ) {
$wp_base = str_replace( array( 'http://', 'https://' ), '//', get_home_url( null, '/', 'http' ) );
return strstr( $url, '://' ) && strstr( $wp_base, $url );
}