wc_prepare_attachment_for_js()
Prepare attachment for JavaScript.
No Hooks.
Returns
array.
Usage
wc_prepare_attachment_for_js( $response );
- $response(array) (required)
- JS version of a attachment post object.
wc_prepare_attachment_for_js() wc prepare attachment for js code WC 11.1.2
function wc_prepare_attachment_for_js( $response ) {
if (
ProductMediaGallery::is_feature_enabled() &&
isset( $response['id'], $response['type'] ) &&
'video' === $response['type']
) {
$poster_id = absint( get_post_thumbnail_id( $response['id'] ) );
if ( $poster_id ) {
$response['poster_id'] = $poster_id;
}
}
/*
* If the user can manage woocommerce, allow them to
* see the image content.
*/
if ( current_user_can( 'manage_woocommerce' ) ) {
return $response;
}
/*
* If the user does not have the right capabilities,
* filter out the image source and replace with placeholder
* image.
*/
if ( isset( $response['url'] ) && strstr( $response['url'], 'woocommerce_uploads/' ) ) {
$response['full']['url'] = wc_placeholder_img_src();
if ( isset( $response['sizes'] ) ) {
foreach ( $response['sizes'] as $size => $value ) {
$response['sizes'][ $size ]['url'] = wc_placeholder_img_src();
}
}
}
return $response;
}