Copy_Recipe_Parts::copy( $post_id, int $post_parent, string $status = 'draft' )


Parameters Parameters

$post_id

(Required)

$post_parent

(int) (Required)

$status

(string) (Optional)

Default value: 'draft'


Top ↑

Return Return

(false|int|WP_Error)


Source Source

File: src/core/admin/class-copy-recipe-parts.php

	public function copy( $post_id, $post_parent = 0, $status = 'draft' ) {
		$post = get_post( $post_id );
		// We don't want to clone revisions
		if ( 'revision' === $post->post_type ) {
			return false;
		}

		if ( 'attachment' !== $post->post_type ) {
			$status = 'draft';
		}

		$new_post_author = wp_get_current_user();
		$post_title      = 'uo-recipe' === $post->post_type ? $post->post_title . ' ' . __( '(Copy)', 'uncanny-automator' ) : $post->post_title;
		$new_post        = array(
			'menu_order'     => $post->menu_order,
			'comment_status' => $post->comment_status,
			'ping_status'    => $post->ping_status,
			'post_author'    => $new_post_author->ID,
			'post_content'   => $this->modify_tokens( $post->post_content, $post_parent ),
			'post_excerpt'   => $post->post_excerpt,
			'post_mime_type' => $post->post_mime_type,
			'post_parent'    => empty( $post_parent ) ? $post->post_parent : $post_parent,
			'post_password'  => $post->post_password,
			'post_status'    => empty( $status ) ? $post->post_status : $status,
			'post_title'     => $post_title,
			'post_type'      => $post->post_type,
			'post_date'      => $post->post_date,
			'post_date_gmt'  => get_gmt_from_date( $post->post_date ),
		);

		$new_post_id = wp_insert_post( $new_post );
		if ( is_wp_error( $new_post_id ) ) {
			wp_die( esc_html( $new_post_id->get_error_message() ) );
		}

		$this->copy_recipe_metas( $post_id, $new_post_id, $post_parent );

		return $new_post_id;
	}