Filter
uncanny-automator
automator_create_post_fire_after_hooks
Filters the arguments used to create a post after the post has been successfully created.
add_filter( 'automator_create_post_fire_after_hooks', $callback, 10, 3 );
Description
Fired after a post has been successfully created by the "Create post" action, this filter allows modification of the final post arguments or the control flow. Developers can use it to adjust post data or potentially prevent further actions by returning `false`.
Usage
add_filter( 'automator_create_post_fire_after_hooks', 'your_function_name', 10, 3 );
Parameters
-
$post_args(mixed) - This parameter controls whether a WordPress `WP_Error` object should be returned if the post creation fails.
-
$recipe_id(mixed) - This parameter contains an array of arguments that will be used to create the WordPress post.
-
$action_data(mixed) - This parameter contains the unique identifier for the automation recipe that is currently being processed.
Return Value
The filtered value.
Examples
add_filter( 'automator_create_post_fire_after_hooks', 'my_automator_create_post_fire_after_hooks_logic', 10, 4 );
/**
* Example filter to conditionally prevent default 'after hooks' execution for post creation.
*
* This function demonstrates how to intercept the 'after hooks' phase of the
* automator_create_post action. In this specific example, it checks if a
* custom meta key 'disable_default_hooks' is present in the $action_data and
* if its value is 'true'. If so, it returns false to prevent the default
* WordPress post creation 'after hooks' from firing.
*
* @param bool $fire_after_hooks The default value, usually true.
* @param array $post_args The arguments being used to create the post.
* @param int $recipe_id The ID of the Automator recipe.
* @param array $action_data The data associated with the current action.
*
* @return bool True to fire default after hooks, false to prevent them.
*/
function my_automator_create_post_fire_after_hooks_logic( $fire_after_hooks, $post_args, $recipe_id, $action_data ) {
// Check if a specific custom meta key is set in the action data to disable default hooks.
if ( isset( $action_data['meta_input']['disable_default_hooks'] ) && 'true' === $action_data['meta_input']['disable_default_hooks'] ) {
// If the custom key is set to 'true', prevent the default 'after hooks' from firing.
return false;
}
// Otherwise, allow the default 'after hooks' to fire.
return $fire_after_hooks;
}
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/actions/wp-createpost.php:461
if ( ! empty( $user ) ) {
$post_args['post_author'] = absint( $user->ID );
break;
}
}
$return_wp_error = apply_filters( 'automator_create_post_return_wp_error', true, $post_args, $recipe_id, $action_data );
$fire_after_hooks = apply_filters( 'automator_create_post_fire_after_hooks', true, $post_args, $recipe_id, $action_data );
$post_id = wp_insert_post( $post_args, $return_wp_error, $fire_after_hooks );
if ( is_wp_error( $post_id ) ) {
$action_data['complete_with_errors'] = true;
Automator()->complete_action( $user_id, $action_data, $recipe_id, $post_id->get_error_message() );