Copy_Recipe_Parts::copy_this_recipe( $recipe_id )
Parameters Parameters
- $recipe_id
-
(Required)
Return Return
(false|int|WP_Error)
Source Source
File: src/core/admin/class-copy-recipe-parts.php
public function copy_this_recipe( $recipe_id ) { global $wpdb; $new_recipe_id = $this->copy( $recipe_id ); if ( $this->copy_recipe_part( $recipe_id, $new_recipe_id, 'uo-trigger' ) ) { $this->copy_recipe_part( $recipe_id, $new_recipe_id, 'uo-action' ); $this->copy_recipe_part( $recipe_id, $new_recipe_id, 'uo-closure' ); // Fallback to update tokens for Anonymous recipes that is stored in recipe's post meta itself $this->copy_recipe_metas( $recipe_id, $new_recipe_id ); } $recipe_tax = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(object_id) AS total FROM $wpdb->term_relationships WHERE object_id = %d", $recipe_id ) ); if ( $recipe_tax > 0 ) { //Clone tags and categories $wpdb->query( "DELETE FROM {$wpdb->term_relationships} WHERE object_id={$new_recipe_id};" ); $wpdb->query( "CREATE TEMPORARY TABLE tmpCopyCats SELECT * FROM {$wpdb->term_relationships} WHERE object_id={$recipe_id};" ); $wpdb->query( "UPDATE tmpCopyCats SET object_id={$new_recipe_id} WHERE object_id={$recipe_id};" ); $wpdb->query( "INSERT INTO {$wpdb->term_relationships} SELECT * FROM tmpCopyCats;" ); $wpdb->query( 'DROP TEMPORARY TABLE IF EXISTS tmpCopyCats;' ); } return $new_recipe_id; }
Expand full source code Collapse full source code View on Github