Filter uncanny-automator

automator_wpai_parse_common_tokens_related_import

Filters common import tokens related to import completion.

add_filter( 'automator_wpai_parse_common_tokens_related_import', $callback, 10, 1 );

Description

Fires after WP All Import processes an import completion. Developers can use this filter to modify the trigger codes related to import completion, allowing for custom logic or integrations. The hook provides access to import completion status and related data.


Usage

add_filter( 'automator_wpai_parse_common_tokens_related_import', 'your_function_name', 10, 1 );

Parameters

$pieces (mixed)
This parameter contains an array of string constants that represent specific import completion statuses relevant to the WordPress All-Import integration.

Return Value

The filtered value.


Examples

/**
 * Example function to modify trigger code validations for WP All Import completed imports.
 * This function might be used to dynamically add or remove trigger codes based on specific import conditions.
 *
 * @param array $trigger_codes The original array of trigger codes.
 * @param array $import_data   An array containing data about the WP All Import process.
 *                             Expected keys: 'pieces', 'recipe_id', 'trigger_data', 'user_id'.
 *
 * @return array The modified array of trigger codes.
 */
add_filter( 'automator_wpai_parse_common_tokens_related_import', function( $trigger_codes, $import_data ) {

	// Example: If the import completed with a specific recipe ID, we might want to add a custom trigger code.
	if ( isset( $import_data['recipe_id'] ) && $import_data['recipe_id'] === 123 ) {
		// Let's assume 'WPAI_IMPORT_COMPLETED_FOR_RECIPE_123' is a custom trigger we want to make available.
		$trigger_codes[] = 'WPAI_IMPORT_COMPLETED_FOR_RECIPE_123';
	}

	// Example: If the import involved a large number of items, we might want to ensure a specific trigger is present.
	// Assuming $import_data['pieces']['total'] holds the total number of items imported.
	if ( isset( $import_data['pieces']['total'] ) && $import_data['pieces']['total'] > 500 ) {
		// Ensure 'WPAI_BULK_IMPORT_COMPLETED' is always present for large imports.
		if ( ! in_array( 'WPAI_BULK_IMPORT_COMPLETED', $trigger_codes ) ) {
			$trigger_codes[] = 'WPAI_BULK_IMPORT_COMPLETED';
		}
	}

	// Return the modified array of trigger codes.
	return $trigger_codes;

}, 10, 2 ); // Priority 10, accepts 2 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/integrations/wp-all-import/tokens/wpai-tokens.php:264

'recipe_id'    => $recipe_id,
				'trigger_data' => $trigger_data,
				'user_id'      => $user_id,
				'replace_args' => $replace_args,
			)
		);

		$trigger_code_validations = apply_filters(
			'automator_wpai_parse_common_tokens_related_import',
			array( 'WPAI_IMPORT_COMPLETED' ),
			array(
				'pieces'       => $pieces,
				'recipe_id'    => $recipe_id,
				'trigger_data' => $trigger_data,
				'user_id'      => $user_id,


Scroll to Top