LLMS_Lesson_Handler::duplicate( $post_id )
Description Description
Source Source
File: includes/class.llms.lesson.handler.php
public static function duplicate( $post_id ) { //make sure we have a post id and it returns a post if ( ! isset( $post_id ) ) { return false; } $post_obj = get_post( $post_id ); //last check... if ( ! isset( $post_obj ) || null == $post_obj ) { return false; } //no going back now... //create duplicate post $args = array( 'comment_status' => $post_obj->comment_status, 'ping_status' => $post_obj->ping_status, 'post_author' => $post_obj->post_author, 'post_content' => $post_obj->post_content, 'post_excerpt' => $post_obj->post_excerpt, 'post_name' => $post_obj->post_name, 'post_parent' => $post_obj->post_parent, 'post_status' => 'publish', 'post_title' => $post_obj->post_title, 'post_type' => $post_obj->post_type, 'to_ping' => $post_obj->to_ping, 'menu_order' => $post_obj->menu_order, 'post_password' => $post_obj->post_password, ); //create the duplicate post $new_post_id = wp_insert_post( $args ); if ( $new_post_id ) { //get all current post terms and set them to the new post $taxonomies = get_object_taxonomies( $post_obj->post_type ); foreach ( $taxonomies as $taxonomy ) { $post_terms = wp_get_object_terms( $post_obj->ID, $taxonomy, array( 'fields' => 'slugs', ) ); wp_set_object_terms( $new_post_id, $post_terms, $taxonomy, false ); } // duplicate meta $insert_meta = self::duplicate_meta( $post_id, $new_post_id ); } return $new_post_id; }
Expand full source code Collapse full source code View on GitHub