Action uncanny-automator

automator_recipe_part_duplicated

Fires after a recipe part is successfully duplicated, providing access to the new part's ID and original recipe information.

add_action( 'automator_recipe_part_duplicated', $callback, 10, 5 );

Description

Fires after a single recipe part has been successfully duplicated. Developers can use this hook to perform custom actions on the newly created recipe part, such as updating its meta data or integrating with other systems. It provides the new part's ID, the ID of the recipe it belongs to, the original recipe part object, the original recipe's ID, and the type of the part.


Usage

add_action( 'automator_recipe_part_duplicated', 'your_function_name', 10, 5 );

Parameters

$new_id (mixed)
The ID of the newly duplicated recipe part.
$new_recipe_id (mixed)
The ID of the newly created recipe part.
$recipe_part (mixed)
This parameter holds the ID of the recipe where the recipe part is being duplicated.
$recipe_id (mixed)
This parameter contains the recipe part object that was just duplicated.
$type (mixed)
The original ID of the recipe from which the recipe part was copied.

Examples

add_action(
	'automator_recipe_part_duplicated',
	function ( $new_id, $new_recipe_id, $recipe_part, $recipe_id, $type ) {
		// Example: Log the duplication of a recipe part for auditing purposes.
		// This could be useful for debugging or tracking changes to recipes.
		if ( WP_DEBUG ) {
			error_log(
				sprintf(
					'Automator: Recipe part duplicated. New Part ID: %s, New Recipe ID: %s, Original Recipe ID: %s, Part Type: %s, Original Part Object: %s',
					$new_id,
					$new_recipe_id,
					$recipe_id,
					$type,
					print_r( $recipe_part, true ) // Log the full recipe part object for detailed info
				)
			);
		}
	},
	10, // Priority: Default is 10
	5  // Accepted Args: The hook provides 5 arguments
);

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

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

public function copy_recipe_part( $recipe_id, $new_recipe_id, $type ) {
		$recipe_parts = $this->get_recipe_parts_posts( $type, $recipe_id );

		if ( empty( $recipe_parts ) ) {
			return false;
		}

		foreach ( $recipe_parts as $recipe_part ) {
			if ( $type !== $recipe_part->post_type ) {
				continue;
			}

			$new_id = $this->copy( $recipe_part->ID, $new_recipe_id );

			// Part duplicated
			do_action( 'automator_recipe_part_duplicated', $new_id, $new_recipe_id, $recipe_part, $recipe_id, $type );
		}

		// Parts duplicated
		do_action( 'automator_recipe_parts_duplicated', $new_recipe_id, $recipe_id );

		return true;
	}


Scroll to Top