Filter uncanny-automator

automator_recipe_export_filename

Filters the filename for exported recipes, allowing customization before download.

add_filter( 'automator_recipe_export_filename', $callback, 10, 2 );

Description

Filters the filename used when exporting a single AutomatorWP recipe. Developers can modify the default filename, which is based on the recipe title or ID, to customize export file naming conventions. This hook fires just before the filename is finalized for download.


Usage

add_filter( 'automator_recipe_export_filename', 'your_function_name', 10, 2 );

Parameters

$filename (mixed)
The `$filename` parameter contains the dynamically generated filename for the exported recipe, which can be modified by the filter.
$recipe_id (mixed)
This parameter represents the filename that will be used for the exported recipe.

Return Value

The filtered value.


Examples

/**
 * Modify the export filename for recipes to include a prefix.
 *
 * This function adds a custom prefix "automator-recipe-" to the beginning
 * of the filename generated for exported recipes.
 *
 * @param string $filename    The original filename generated by the plugin.
 * @param int    $recipe_id   The ID of the recipe being exported.
 * @return string The modified filename.
 */
add_filter( 'automator_recipe_export_filename', function( $filename, $recipe_id ) {
	// Ensure the filename is not empty and prepend a custom prefix.
	$prefix = 'automator-recipe-';
	return $prefix . $filename;
}, 10, 2 );

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-export-recipe.php:337

public function generate_filename( $recipe_id ) {

		$filename = 'recipe-';

		// Get the title of the recipe
		$title = get_the_title( $recipe_id );

		// If the title is empty, use the id
		$filename .= ! empty( $title ) ? sanitize_title( $title ) : 'id-' . $recipe_id;

		return apply_filters( 'automator_recipe_export_filename', $filename, $recipe_id );
	}


Scroll to Top