0,
'parent' => 0
) );
// Loop through each variation set
foreach ( (array)$variation_sets as $variation_set ) :
$set_checked_state = '';
// If this Product includes this variation, check it
if ( in_array( $variation_set->term_id, $product_terms ) )
$set_checked_state = "checked='checked'"; ?>
0,
'parent' => $variation_set->term_id
) );
// Loop through the variations
foreach ( (array)$variations as $variation ) :
$checked_state = '';
if ( in_array( $variation->term_id, $product_terms ) )
$checked_state = "checked='checked'";
?>
ID );
$output = '';
$product_data['meta'] = $product_meta = array();
if ( !empty( $product_data['_wpsc_product_metadata'] ) )
$product_data['meta'] = $product_meta = maybe_unserialize( $product_data['_wpsc_product_metadata'][0] );
$upload_max = wpsc_get_max_upload_size();
?>
ID ); ?>
:
:
'wpsc-preview-file',
'post_parent' => $post->ID,
'numberposts' => -1,
'post_status' => 'all'
);
$preview_files = (array)get_posts( $args );
foreach ($preview_files as $preview)
echo $preview->post_title . ' ';
?>
id != 'wpsc-product' )
return $context;
return __( 'Upload Image%s', 'wpsc' );
}
function change_link( $link ) {
global $post_ID, $current_screen;
if ( $current_screen->id != 'wpsc-product' )
return $link;
$uploading_iframe_ID = $post_ID;
$media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
return $media_upload_iframe_src . "&type=image&parent_page=wpsc-edit-products";
}
function wpsc_form_multipart_encoding() {
echo ' enctype="multipart/form-data"';
}
add_action( 'post_edit_form_tag', 'wpsc_form_multipart_encoding' );
add_filter( 'media_buttons_context', 'change_context' );
add_filter( 'image_upload_iframe_src', "change_link" );
/*
* Modifications to Media Gallery
*/
if ( ( isset( $_REQUEST['parent_page'] ) && ( $_REQUEST['parent_page'] == 'wpsc-edit-products' ) ) ) {
add_filter( 'media_upload_tabs', 'wpsc_media_upload_tab_gallery', 12 );
add_filter( 'attachment_fields_to_save', 'wpsc_save_attachment_fields', 9, 2 );
add_filter( 'media_upload_form_url', 'wpsc_media_upload_url', 9, 1 );
add_action( 'admin_head', 'wpsc_gallery_css_mods' );
}
add_filter( 'gettext', 'wpsc_filter_delete_text', 12 , 3 );
add_filter( 'attachment_fields_to_edit', 'wpsc_attachment_fields', 11, 2 );
add_filter( 'gettext', 'wpsc_filter_feature_image_text', 12, 3 );
add_filter( 'gettext_with_context', 'wpsc_filter_gettex_with_context', 12, 4);
if ( isset( $_REQUEST["save"] ) && isset( $_REQUEST["attachments"] ) && is_array( $_REQUEST["attachments"] ) ) {
//wpsc_regenerate_thumbnails();
}
/*
* This filter overrides string with context translations
*
* @param $translation The current translation
* @param $text The text being translated
* @param $context The domain for the translation
* @param $domain The domain for the translation
* @return string The translated / filtered text.
*/
function wpsc_filter_gettex_with_context( $translation, $text, $context, $domain ) {
if ( 'Taxonomy Parent' == $context && 'Parent' == $text && isset($_GET['taxonomy']) && 'wpsc-variation' == $_GET['taxonomy'] ) {
$translations = &get_translations_for_domain( $domain );
return $translations->translate( 'Variation set', 'wpsc' );
//this will never happen, this is here only for gettex to pick up the translation
return __( 'Variation set', 'wpsc' );
}
return $translation;
}
/*
* This filter translates string before it is displayed
* specifically for the words 'Use as featured image' with 'Use as Product Thumbnail' when the user is selecting a Product Thumbnail
* using media gallery.
*
* @param $translation The current translation
* @param $text The text being translated
* @param $domain The domain for the translation
* @return string The translated / filtered text.
*/
function wpsc_filter_feature_image_text( $translation, $text, $domain ) {
if ( 'Use as featured image' == $text && isset( $_REQUEST['post_id'] ) ) {
$post = get_post( $_REQUEST['post_id'] );
if ( $post->post_type != 'wpsc-product' ) return $translation;
$translations = &get_translations_for_domain( $domain );
return $translations->translate( 'Use as Product Thumbnail', 'wpsc' );
//this will never happen, this is here only for gettex to pick up the translation
return __( 'Use as Product Thumbnail', 'wpsc' );
}
if ( 'The name is how it appears on your site.' == $text && isset($_GET['taxonomy']) && 'wpsc-variation' == $_GET['taxonomy'] ){
$translations = &get_translations_for_domain( $domain );
return $translations->translate( 'The name is how it appears on your site.
Please read this carefully before starting to work with variations: Variations in WP e-Commerce are divided into sets. For example set Color could have variations Red, Green, and Blue. To create a variation set simply enter the name and push Enter key on your keyboard or click Add New Variation/Set button in the bottom of this page. Then you will be able to select it from Variation set drop-down menu and add some variations to it. To add a new variation set just select None in Variation set drop-down menu.
', 'wpsc' );
//this will never happen, this is here only for gettex to pick up the translation
return __( 'The name is how it appears on your site.
Please read this carefully before starting to work with variations: Variations in WP e-Commerce are divided into sets. For example set Color could have variations Red, Green, and Blue. To create a set simply enter Name and push Enter key on your keyboard or click Add New Variation/Set button in the bottom of this page. Now you can select the variation set that you\'ve just created from Variation set drop-down menu and add some variations to it.
', 'wpsc' );
}
return $translation;
}
function wpsc_attachment_fields( $form_fields, $post ) {
$out = '';
if(isset($_GET["post_id"]))
$parent_post = get_post( absint($_GET["post_id"]) );
else
$parent_post = get_post( $post->post_parent );
if ( $parent_post->post_type == "wpsc-product" ) {
//Unfortunate hack, as I'm not sure why the From Computer tab doesn't process filters the same way the Gallery does
echo '
';
$size_names = array( 'small-product-thumbnail' => __( 'Default Product Thumbnail Size', 'wpsc' ), 'medium-single-product' => __( 'Single Product Image Size', 'wpsc' ), 'full' => __( 'Full Size', 'wpsc' ) );
$check = get_post_meta( $post->ID, '_wpsc_selected_image_size', true );
if ( !$check )
$check = 'medium-single-product';
// regenerate size metadata in case it's missing
if ( ! image_get_intermediate_size( $post->ID, $check ) ) {
$metadata = wp_get_attachment_metadata( $post->ID );
$file = get_attached_file( $post->ID );
$metadata = array_merge( wp_generate_attachment_metadata( $post->ID, $file ), $metadata );
wp_update_attachment_metadata( $post->ID, $metadata );
}
//This loop attaches the custom thumbnail/single image sizes to this page
foreach ( $size_names as $size => $name ) {
$downsize = image_downsize( $post->ID, $size );
// is this size selectable?
$enabled = ( $downsize[3] || 'full' == $size );
$css_id = "image-size-{$size}-{$post->ID}";
// if this size is the default but that's not available, don't select it
$html = "
ID][image-size]' id='{$css_id}' value='{$size}' " . checked( $size, $check, false ) . " />";
$html .= "";
// only show the dimensions if that choice is available
if ( $enabled )
$html .= " ";
$html .= '
';
$out .= $html;
}
unset( $form_fields['post_excerpt'], $form_fields['image_url'], $form_fields['post_content'], $form_fields['post_title'], $form_fields['url'], $form_fields['align'], $form_fields['image_alt']['helps'], $form_fields["image-size"] );
$form_fields['image_alt']['helps'] = __( 'Alt text for the product image, e.g. “Rockstar T-Shirt”', 'wpsc' );
$form_fields["image-size"] = array(
'label' => __( 'Single Product Page Thumbnail:', 'wpsc' ),
'input' => 'html',
'html' => $out,
'helps' => "" . __( 'This is the Thumbnail size that will be displayed on the Single Product page. You can change the default sizes under your store settings', 'wpsc' ) . ""
);
//This is for the custom thumbnail size.
$custom_thumb_size_w = get_post_meta( $post->ID, "_wpsc_custom_thumb_w", true );
$custom_thumb_size_h = get_post_meta( $post->ID, "_wpsc_custom_thumb_h", true );
$custom_thumb_html = "
X
";
$form_fields["wpsc_custom_thumb"] = array(
"label" => __( "Products Page Thumbnail Size:", 'wpsc' ),
"input" => "html", // this is default if "input" is omitted
"helps" => "" . __( 'Custom thumbnail size for this image on the main Product Page', 'wpsc') . "",
"html" => $custom_thumb_html
);
}
return $form_fields;
}
function wpsc_save_attachment_fields( $post, $attachment ) {
if ( isset ( $attachment['wpsc_custom_thumb_w'] ) )
update_post_meta( $post['ID'], '_wpsc_custom_thumb_w', $attachment['wpsc_custom_thumb_w'] );
if ( isset ( $attachment['wpsc_custom_thumb_h'] ) )
update_post_meta( $post['ID'], '_wpsc_custom_thumb_h', $attachment['wpsc_custom_thumb_h'] );
if ( isset ( $attachment['image-size'] ) )
update_post_meta( $post['ID'], '_wpsc_selected_image_size', $attachment['image-size'] );
return $post;
}
function wpsc_media_upload_url( $form_action_url ) {
$form_action_url = esc_url( add_query_arg( array( 'parent_page'=>'wpsc-edit-products' ) ) );
return $form_action_url;
}
function wpsc_gallery_css_mods() {
print '';
print '
';
}
function wpsc_media_upload_tab_gallery( $tabs ) {
unset( $tabs['gallery'] );
$tabs['gallery'] = __( 'Product Image Gallery', 'wpsc' );
return $tabs;
}
function wpsc_filter_delete_text( $translation, $text, $domain ) {
if ( 'Delete' == $text && isset( $_REQUEST['post_id'] ) && isset( $_REQUEST["parent_page"] ) ) {
$translations = &get_translations_for_domain( $domain );
return $translations->translate( 'Trash' ) ;
}
return $translation;
}
function edit_multiple_image_gallery( $post ) {
global $wpdb;
//Make sure thumbnail isn't duplicated
$siteurl = get_option( 'siteurl' );
if ( $post->ID > 0 ) {
if ( has_post_thumbnail( $post->ID ) )
echo get_the_post_thumbnail( $post->ID, 'admin-product-thumbnails' );
$args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => null,
'post_parent' => $post->ID,
'orderby' => 'menu_order',
'order' => 'ASC'
);
$attached_images = (array)get_posts( $args );
if ( count( $attached_images ) > 0 ) {
foreach ( $attached_images as $images ) {
$attached_image = wp_get_attachment_image( $images->ID, 'admin-product-thumbnails' );
echo $attached_image. ' ';
}
}
}
}
/**
* wpsc_save_quickedit_box function
* Saves input for the various meta in the quick edit boxes
*
* @todo UI
* @todo Data validation / sanitization / security
* @todo AJAX should probably return weight unit
* @return $post_id (int) Post ID
*/
function wpsc_save_quickedit_box( $post_id ) {
global $current_screen;
if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || empty( $current_screen ) || $current_screen->id != 'edit-wpsc-product' || ! defined( 'DOING_AJAX' ) || ! DOING_AJAX )
return;
$is_parent = ( bool )wpsc_product_has_children( $post_id );
$product_meta = get_post_meta( $post_id, '_wpsc_product_metadata', true );
$weight_unit = $product_meta["weight_unit"];
$weight = wpsc_convert_weight( $_POST["weight"], $weight_unit, "pound", true );
if ( isset( $product_meta["weight"] ) )
unset( $product_meta["weight"] );
$product_meta["weight"] = $weight;
if ( !$is_parent ) {
update_post_meta( $post_id, '_wpsc_product_metadata', $product_meta );
if(is_numeric($_POST['stock']))
update_post_meta( $post_id, '_wpsc_stock', $_POST['stock'] );
else
update_post_meta( $post_id, '_wpsc_stock', '' );
update_post_meta( $post_id, '_wpsc_price', $_POST['price'] );
update_post_meta( $post_id, '_wpsc_special_price', $_POST['sale_price'] );
}
if($_POST['sku'] == __('N/A', 'wpsc'))
update_post_meta( $post_id, '_wpsc_sku', '' );
else
update_post_meta( $post_id, '_wpsc_sku', $_POST['sku'] );
return $post_id;
}
/**
* wpsc_quick_edit_boxes function
* Creates inputs for the various meta in the quick edit boxes.
*
* @todo UI
* @internal The post_id cannot be accessed here because this gets output at the very end
* of the editor form, and injected within relevant rows using javascript.
*/
function wpsc_quick_edit_boxes( $col_name, $_screen_post_type = null ) {
// Avoid outputting this on term edit screens.
// See http://core.trac.wordpress.org/ticket/16392#comment:9
if ( current_filter() == 'quick_edit_custom_box' && $_screen_post_type == 'edit-tags' )
return;
?>