/** * Duplicates a product image. * * Uses a portion of code from media_sideload_image() in `wp-admin/includes/media.php` * to check file before downloading from URL. * * @since 3.9.0 * * @uses WPSC_Duplicate_Product Duplicate product class. * * @param object $post The post object. * @param bool $new_parent_id The parent post id. * @return int|bool Attachment ID or false. * * @deprecated since 4.0 */ function wpsc_duplicate_product_image_process($child_post, $new_parent_id) { _wpsc_deprecated_function(__FUNCTION__, '4.0', 'WPSC_Duplicate_Product->duplicate_product_image_process()'); $duplicate = new WPSC_Duplicate_Product($child_post->ID, $new_parent_id); $duplicate->duplicate_product_image_process(); }
/** * Duplicates product children and meta * * @since 4.0 * * @uses get_posts() Gets an array of posts given array of arguments. * * @return array Array mapping old child IDs to duplicated child IDs. */ private function duplicate_children() { $new_parent_id = $this->get_new_post_id(); // Map duplicate child IDs $converted_child_ids = array(); if ($new_parent_id) { // Get children products and duplicate them $child_posts = get_posts(array('post_parent' => $this->get_post_id(), 'post_type' => 'any', 'post_status' => 'any', 'numberposts' => -1, 'order' => 'ASC')); // Duplicate product images and child posts foreach ($child_posts as $child_post) { $duplicate_child = new WPSC_Duplicate_Product($child_post->ID, $new_parent_id); // Duplicate image or post if ('attachment' == get_post_type($child_post)) { $new_child_id = $duplicate_child->duplicate_product_image_process(); } else { $new_child_id = $duplicate_child->duplicate_product_process(); } // Map child ID to new child ID if ($new_child_id && !is_wp_error($new_child_id)) { $converted_child_ids[$child_post->ID] = $new_child_id; } do_action('wpsc_duplicate_product_child', $child_post, $new_parent_id, $new_child_id); } } return $converted_child_ids; }