woocommerce/includes/admin/meta-boxes/class-wc-meta-box-product-i...

72 lines
2.5 KiB
PHP
Raw Normal View History

2013-08-06 10:41:20 +00:00
<?php
/**
* Product Images
*
* Display the product images meta box.
*
* @author WooThemes
* @category Admin
* @package WooCommerce/Admin/Meta Boxes
2013-08-06 10:41:20 +00:00
* @version 2.1.0
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
2013-08-06 10:41:20 +00:00
/**
* WC_Meta_Box_Product_Images Class
2013-08-06 10:41:20 +00:00
*/
class WC_Meta_Box_Product_Images {
/**
* Output the metabox
*/
public static function output( $post ) {
?>
<div id="product_images_container">
<ul class="product_images">
<?php
if ( metadata_exists( 'post', $post->ID, '_product_image_gallery' ) ) {
$product_image_gallery = get_post_meta( $post->ID, '_product_image_gallery', true );
} else {
// Backwards compat
$attachment_ids = get_posts( 'post_parent=' . $post->ID . '&numberposts=-1&post_type=attachment&orderby=menu_order&order=ASC&post_mime_type=image&fields=ids&meta_key=_woocommerce_exclude_image&meta_value=0' );
$attachment_ids = array_diff( $attachment_ids, array( get_post_thumbnail_id() ) );
$product_image_gallery = implode( ',', $attachment_ids );
}
$attachments = array_filter( explode( ',', $product_image_gallery ) );
2015-04-01 13:33:56 +00:00
if ( ! empty( $attachments ) ) {
2013-08-06 10:41:20 +00:00
foreach ( $attachments as $attachment_id ) {
2013-11-20 19:11:59 +00:00
echo '<li class="image" data-attachment_id="' . esc_attr( $attachment_id ) . '">
2013-08-06 10:41:20 +00:00
' . wp_get_attachment_image( $attachment_id, 'thumbnail' ) . '
<ul class="actions">
<li><a href="#" class="delete tips" data-tip="' . __( 'Delete image', 'woocommerce' ) . '">' . __( 'Delete', 'woocommerce' ) . '</a></li>
</ul>
</li>';
}
}
2013-08-06 10:41:20 +00:00
?>
</ul>
<input type="hidden" id="product_image_gallery" name="product_image_gallery" value="<?php echo esc_attr( $product_image_gallery ); ?>" />
</div>
<p class="add_product_images hide-if-no-js">
2013-11-28 12:37:44 +00:00
<a href="#" data-choose="<?php _e( 'Add Images to Product Gallery', 'woocommerce' ); ?>" data-update="<?php _e( 'Add to gallery', 'woocommerce' ); ?>" data-delete="<?php _e( 'Delete image', 'woocommerce' ); ?>" data-text="<?php _e( 'Delete', 'woocommerce' ); ?>"><?php _e( 'Add product gallery images', 'woocommerce' ); ?></a>
2013-08-06 10:41:20 +00:00
</p>
<?php
}
/**
* Save meta box data
*/
public static function save( $post_id, $post ) {
$attachment_ids = isset( $_POST['product_image_gallery'] ) ? array_filter( explode( ',', wc_clean( $_POST['product_image_gallery'] ) ) ) : array();
2013-08-06 10:41:20 +00:00
update_post_meta( $post_id, '_product_image_gallery', implode( ',', $attachment_ids ) );
}
}