Beispiel #1
0
function eventon_create_duplicate_from_event($post, $parent = 0, $post_status = '')
{
    global $wpdb;
    $new_post_author = wp_get_current_user();
    $new_post_date = current_time('mysql');
    $new_post_date_gmt = get_gmt_from_date($new_post_date);
    if ($parent > 0) {
        $post_parent = $parent;
        $post_status = $post_status ? $post_status : 'publish';
        $suffix = '';
    } else {
        $post_parent = $post->post_parent;
        $post_status = $post_status ? $post_status : 'draft';
        $suffix = ' ' . __('(Copy)', 'eventon');
    }
    // Insert the new template in the post table
    $wpdb->insert($wpdb->posts, array('post_author' => $new_post_author->ID, 'post_date' => $new_post_date, 'post_date_gmt' => $new_post_date_gmt, 'post_content' => $post->post_content, 'post_content_filtered' => $post->post_content_filtered, 'post_title' => $post->post_title . $suffix, 'post_excerpt' => $post->post_excerpt, 'post_status' => $post_status, 'post_type' => $post->post_type, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_password' => $post->post_password, 'to_ping' => $post->to_ping, 'pinged' => $post->pinged, 'post_modified' => $new_post_date, 'post_modified_gmt' => $new_post_date_gmt, 'post_parent' => $post_parent, 'menu_order' => $post->menu_order, 'post_mime_type' => $post->post_mime_type));
    $new_post_id = $wpdb->insert_id;
    // Copy the taxonomies
    eventon_duplicate_post_taxonomies($post->ID, $new_post_id, $post->post_type);
    // Copy the meta information
    eventon_duplicate_post_meta($post->ID, $new_post_id);
    // ONLY for ticket addon event duplication
    if ($post->post_type == 'product') {
        $exclude = apply_filters('woocommerce_duplicate_product_exclude_children', false);
        if (!$exclude && ($children_products = get_children('post_parent=' . $post->ID . '&post_type=product_variation'))) {
            foreach ($children_products as $child) {
                eventon_create_duplicate_from_event(eventon_get_event_to_duplicate($child->ID), $new_post_id, $child->post_status);
            }
        }
    }
    return $new_post_id;
}
/**
 * Function to create the duplicate of the event.
 *
 * @access public
 * @param mixed $post
 * @param int $parent (default: 0)
 * @param string $post_status (default: '')
 * @return void
 */
function eventon_create_duplicate_from_event($post, $parent = 0, $post_status = '')
{
    global $wpdb;
    $new_post_author = wp_get_current_user();
    $new_post_date = current_time('mysql');
    $new_post_date_gmt = get_gmt_from_date($new_post_date);
    if ($parent > 0) {
        $post_parent = $parent;
        $post_status = $post_status ? $post_status : 'publish';
        $suffix = '';
    } else {
        $post_parent = $post->post_parent;
        $post_status = $post_status ? $post_status : 'draft';
        $suffix = ' ' . __('(Copy)', 'eventon');
    }
    $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) . $suffix;
    $post_name = str_replace("'", "''", $post->post_name);
    $comment_status = str_replace("'", "''", $post->comment_status);
    $ping_status = str_replace("'", "''", $post->ping_status);
    // Insert the new template in the post table
    $wpdb->query("INSERT INTO {$wpdb->posts}\n\t\t\t(post_author, post_date, post_date_gmt, post_content, post_content_filtered, post_title, post_excerpt,  post_status, post_type, comment_status, ping_status, post_password, to_ping, pinged, post_modified, post_modified_gmt, post_parent, menu_order, post_mime_type)\n\t\t\tVALUES\n\t\t\t('{$new_post_author->ID}', '{$new_post_date}', '{$new_post_date_gmt}', '{$post_content}', '{$post_content_filtered}', '{$post_title}', '{$post_excerpt}', '{$post_status}', '{$new_post_type}', '{$comment_status}', '{$ping_status}', '{$post->post_password}', '{$post->to_ping}', '{$post->pinged}', '{$new_post_date}', '{$new_post_date_gmt}', '{$post_parent}', '{$post->menu_order}', '{$post->post_mime_type}')");
    $new_post_id = $wpdb->insert_id;
    // Copy the taxonomies
    eventon_duplicate_post_taxonomies($post->ID, $new_post_id, $post->post_type);
    // Copy the meta information
    eventon_duplicate_post_meta($post->ID, $new_post_id);
    // for event tickets addon using WC
    if ($new_post_type == 'product') {
        if ($children_products =& get_children('post_parent=' . $post->ID . '&post_type=product_variation')) {
            if ($children_products) {
                foreach ($children_products as $child) {
                    eventon_create_duplicate_from_event(eventon_get_event_to_duplicate($child->ID), $new_post_id, $child->post_status);
                }
            }
        }
    }
    return $new_post_id;
}