Copy_Recipe_Parts::copy_recipe_parts()


Source Source

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

	public function copy_recipe_parts() {
		if ( ! automator_filter_has_var( 'action' ) ) {
			return;
		}
		if ( automator_filter_has_var( 'action' ) && 'copy_recipe_parts' !== automator_filter_input( 'action' ) ) {
			return;
		}
		if ( ! automator_filter_has_var( 'post' ) ) {
			return;
		}
		if ( ! automator_filter_has_var( '_wpnonce' ) ) {
			return;
		}
		if ( ! wp_verify_nonce( automator_filter_input( '_wpnonce' ), 'Aut0Mat0R' ) ) {
			return;
		}
		$recipe_id = absint( automator_filter_input( 'post' ) );
		if ( 'uo-recipe' !== get_post_type( $recipe_id ) ) {
			wp_die( esc_attr( sprintf( '%s %s', __( 'Copy creation failed, could not find original recipe:', 'uncanny-automator' ), htmlspecialchars( $recipe_id ) ) ) );
		}
		// Copy the post and insert it
		$new_id = $this->copy_this_recipe( $recipe_id );
		if ( automator_filter_has_var( 'return_to_recipe' ) ) {
			wp_safe_redirect( admin_url( 'post.php?post=' . $new_id . '&action=edit' ) );
		} else {
			wp_safe_redirect( admin_url( 'edit.php?post_type=' . get_post_type( $recipe_id ) ) );
		}
		exit;
	}