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 10.7.0
function wc_prepare_attachment_for_js( $response ) {
/*
* 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;
}