Filter uncanny-automator

automator_recipe_import_draft_post_types

Filters the post types that can be imported as drafts during the Automator recipe import process.

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

Description

Allows modification of the default post types considered for draft recipes during import. Developers can filter this to include or exclude specific post types, ensuring tailored recipe import behavior. This filter is applied before draft post types are determined.


Usage

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

Parameters

$this (mixed)
This parameter is an array of post types that will be considered for importing as drafts.

Return Value

The filtered value.


Examples

/**
 * Exclude 'attachment' post type from being imported as drafts.
 *
 * This filter allows developers to modify the list of post types that
 * can be imported as drafts when importing Automator recipes. By default,
 * certain post types like 'attachment' might be included, but for some
 * use cases, it's better to exclude them to avoid import issues or
 * unwanted behavior.
 *
 * @param array $draft_post_types An array of post type slugs that can be imported as drafts.
 * @return array The modified array of post type slugs.
 */
add_filter( 'automator_recipe_import_draft_post_types', function( $draft_post_types ) {
    // Remove 'attachment' post type from the list if it exists.
    if ( ( $key = array_search( 'attachment', $draft_post_types, true ) ) !== false ) {
        unset( $draft_post_types[ $key ] );
    }

    // Optionally, add a custom post type if you want to ensure it's included.
    // For example, if you have a custom post type called 'my_recipe_type'.
    // if ( ! in_array( 'my_recipe_type', $draft_post_types, true ) ) {
    //     $draft_post_types[] = 'my_recipe_type';
    // }

    return $draft_post_types;
}, 10, 1 );

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-import-recipe.php:282

public function pre_import_filters() {
		$this->draft_post_types        = apply_filters( 'automator_recipe_import_draft_post_types', $this->draft_post_types );
		$this->published_trigger_codes = apply_filters( 'automator_recipe_import_published_trigger_codes', $this->published_trigger_codes );

		// Maybe adjust hardcoded meta URLs.
		add_filter( 'automator_recipe_part_meta_value', array( $this, 'maybe_adjust_hardcoded_meta_urls' ), 10, 4 );
	}


Scroll to Top