/** * Duplicates a product * * @uses wp_insert_post() Inserts a new post to the database * @uses wpsc_duplicate_taxonomies() Copy the taxonomies of a post to another post * @uses wpsc_duplicate_product_meta() Copy the metadata of a post to another post * @uses wpsc_duplicate_children() Copy the children of the product * * @param object $post req The post object * @param bool $new_parent_id opt The parent post id * * @return int|WP_Error New post id or error */ function wpsc_duplicate_product_process($post, $new_parent_id = false) { $new_post_date = $post->post_date; $new_post_date_gmt = get_gmt_from_date($new_post_date); $new_post_type = $post->post_type; $post_content = $post->post_content; $post_content_filtered = $post->post_content_filtered; $post_excerpt = $post->post_excerpt; $post_title = sprintf(__('%s (Duplicate)', 'wpsc'), $post->post_title); $post_name = $post->post_name; $comment_status = $post->comment_status; $ping_status = $post->ping_status; $defaults = array('post_status' => $post->post_status, 'post_type' => $new_post_type, 'ping_status' => $ping_status, 'post_parent' => $new_parent_id ? $new_parent_id : $post->post_parent, 'menu_order' => $post->menu_order, 'to_ping' => $post->to_ping, 'pinged' => $post->pinged, 'post_excerpt' => $post_excerpt, 'post_title' => $post_title, 'post_content' => $post_content, 'post_content_filtered' => $post_content_filtered, 'post_mime_type' => $post->post_mime_type, 'import_id' => 0); if ('attachment' == $post->post_type) { $defaults['guid'] = $post->guid; } $defaults = stripslashes_deep($defaults); // Insert the new template in the post table $new_post_id = wp_insert_post($defaults); // Copy the taxonomies wpsc_duplicate_taxonomies($post->ID, $new_post_id, $post->post_type); // Copy the meta information wpsc_duplicate_product_meta($post->ID, $new_post_id); // Finds children (Which includes product files AND product images), their meta values, and duplicates them. wpsc_duplicate_children($post->ID, $new_post_id); return $new_post_id; }
function wpsc_duplicate_product_process($post, $new_parent_id = false) { $new_post_date = $post->post_date; $new_post_date_gmt = get_gmt_from_date($new_post_date); $new_post_type = $post->post_type; $post_content = str_replace("'", "''", $post->post_content); $post_content_filtered = str_replace("'", "''", $post->post_content_filtered); $post_excerpt = str_replace("'", "''", $post->post_excerpt); $post_title = str_replace("'", "''", $post->post_title) . " (Duplicate)"; $post_name = str_replace("'", "''", $post->post_name); $comment_status = str_replace("'", "''", $post->comment_status); $ping_status = str_replace("'", "''", $post->ping_status); $defaults = array('post_status' => $post->post_status, 'post_type' => $new_post_type, 'ping_status' => $ping_status, 'post_parent' => $new_parent_id ? $new_parent_id : $post->post_parent, 'menu_order' => $post->menu_order, 'to_ping' => $post->to_ping, 'pinged' => $post->pinged, 'post_excerpt' => $post_excerpt, 'post_title' => $post_title, 'post_content' => $post_content, 'post_content_filtered' => $post_content_filtered, 'import_id' => 0); // Insert the new template in the post table $new_post_id = wp_insert_post($defaults); // Copy the taxonomies wpsc_duplicate_taxonomies($post->ID, $new_post_id, $post->post_type); // Copy the meta information wpsc_duplicate_product_meta($post->ID, $new_post_id); // Finds children (Which includes product files AND product images), their meta values, and duplicates them. wpsc_duplicate_children($post->ID, $new_post_id); return $new_post_id; }