add_action("admin_head","adminHead");
function adminHead()// jquery hack :) and tinymce textare
{
global $wp_query,$post;
if((isset($_GET['post_type']) && $_GET['post_type'] == "wpsc-
product") || (isset($_GET['post']) && isset($_GET['action']) &&
$_GET['action'] == "edit" && $post->post_type == "wpsc-product"))
{
?>
<script type="text/javascript">
jQuery(document).ready(function()
{
var input =
jQuery('#wpsc_product_download_forms').find('input[type="file"]');
jQuery('<br/><span>Description:</span><br/><textarea
id="wpsc_product_file_text" name="wpsc_product_file_text"
style="height:300px;"></textarea>').insertAfter(input);
jQuery("#wpsc_product_file_text").addClass("mceEditor");
tinyMCE.execCommand("mceAddControl",false,"wpsc_product_file_text");
});
</script>
<?php
}
}
add_action("wpsc_edit_product","saveProductFileText");
function saveProductFileText($product_id){ // attach text...
$args = array(
'post_type' => 'wpsc-product-file',
'post_parent' => $product_id,
'numberposts' => -1,
'post_status' => 'all'
);
$attached_files = (array)get_posts( $args );
if(!empty($attached_files) && isset($_POST['wpsc_product_file_text'])
&& strlen($_POST['wpsc_product_file_text']) > 0)
{
$meta = get_post_meta($attached_files[0]-
>ID,"_wpsc_product_file_text",true );
if($meta == "")
{
add_post_meta($attached_files[0]->ID, "_wpsc_product_file_text",
$_POST['wpsc_product_file_text'],true);
}
else
{
update_post_meta($attached_files[0]->ID, "_wpsc_product_file_text",
$_POST['wpsc_product_file_text']);
}
}
}
function wpsc_get_product_files($productId) // get files + text....
{
$args = array(
'post_type' => 'wpsc-product-file',
'post_parent' => $productId,
'numberposts' => -1,
'post_status' => 'all'
);
$attached_files = (array)get_posts( $args );
$tmp = $attached_files;
foreach($attached_files as $key => $value)
{
$attached_files[$key]->wpsc_product_file_text =
get_post_meta($attached_files[$key]-
>ID,"_wpsc_product_file_text",true);
}
return $attached_files;
}
by egg