wc_placeholder_img()
Get the placeholder image.
Uses wp_get_attachment_image if using an attachment ID @since 3.6.0 to handle responsiveness.
Хуки из функции
Возвращает
string.
Использование
wc_placeholder_img( $size, $attr );
- $size(строка)
- Image size.
По умолчанию:'woocommerce_thumbnail' - $attr(строка|массив)
- Attributes for the image markup.
По умолчанию:''
Код wc_placeholder_img() wc placeholder img WC 11.2.2
function wc_placeholder_img( $size = 'woocommerce_thumbnail', $attr = '' ) {
$dimensions = wc_get_image_size( $size );
$placeholder_image = get_option( 'woocommerce_placeholder_image', 0 );
$use_attachment_image = wp_attachment_is_image( $placeholder_image );
$image = null;
if ( $use_attachment_image && has_filter( 'woocommerce_placeholder_img_src' ) ) {
$image = wc_placeholder_img_src( $size );
$use_attachment_image = wp_get_attachment_image_url( $placeholder_image, $size ) === $image;
}
$default_attr = array(
'class' => 'woocommerce-placeholder wp-post-image',
'alt' => __( 'Placeholder', 'woocommerce' ),
);
$attr = wp_parse_args( $attr, $default_attr );
if ( $use_attachment_image ) {
$image_html = wp_get_attachment_image(
$placeholder_image,
$size,
false,
$attr
);
} else {
// A changed source cannot use the attachment's srcset, as the browser could select it instead.
$image = $image ?? wc_placeholder_img_src( $size );
$hwstring = image_hwstring( $dimensions['width'], $dimensions['height'] );
$attributes = array();
foreach ( $attr as $name => $value ) {
$attributes[] = esc_attr( $name ) . '="' . esc_attr( $value ) . '"';
}
$image_html = '<img src="' . esc_url( $image ) . '" ' . $hwstring . implode( ' ', $attributes ) . '/>';
}
/**
* Filters the placeholder image HTML.
*
* @param string $image_html The placeholder image HTML.
* @param string $size Image size.
* @param array $dimensions Image width and height.
* @param array $attr Attributes for the image markup.
*
* @since 2.0.0
* @since 11.1.0 Added the `$attr` parameter.
*/
return apply_filters( 'woocommerce_placeholder_img', $image_html, $size, $dimensions, $attr );
}