Filter
uncanny-automator
automator_wp_post_updates_ignore_statuses
Filters post update statuses to ignore, preventing automations for specific post states.
add_filter( 'automator_wp_post_updates_ignore_statuses', $callback, 10, 3 );
Description
Filter to modify the post statuses that are ignored by the WordPress post update triggers. By default, it ignores 'trash', 'draft', and 'future' statuses. Developers can return a modified array of post statuses to prevent Automator from triggering actions for specific post status changes, offering granular control over automation workflows.
Usage
add_filter( 'automator_wp_post_updates_ignore_statuses', 'your_function_name', 10, 3 );
Parameters
-
$post_id(mixed) - This parameter contains an array of post statuses that should be ignored when triggering automations for post updates.
-
$wp_post_after(mixed) - This parameter contains the ID of the post that was updated.
-
$wp_post_before(mixed) - This parameter contains the post object *after* the update has occurred.
Return Value
The filtered value.
Examples
/**
* Example: Ignore post updates for specific post types if they are in draft status.
*
* This filter allows you to define additional post statuses that should be ignored
* by the WordPress post update triggers in Automator.
*
* @param array $ignore_statuses An array of post statuses to ignore.
* @param int $post_id The ID of the post being updated.
* @param object $wp_post_after The WP_Post object after the update.
* @param object $wp_post_before The WP_Post object before the update.
* @return array Modified array of post statuses to ignore.
*/
add_filter(
'automator_wp_post_updates_ignore_statuses',
function ( $ignore_statuses, $post_id, $wp_post_after, $wp_post_before ) {
// Add 'auto-draft' to the ignore list if the post type is 'custom_post_type'.
if ( 'custom_post_type' === $wp_post_after->post_type && 'auto-draft' === $wp_post_after->post_status ) {
$ignore_statuses[] = 'auto-draft';
}
// You could also add logic here to ignore updates for specific post IDs,
// for example, if a specific post is meant to be a template and shouldn't
// trigger Automator workflows.
// if ( 123 === $post_id ) {
// $ignore_statuses[] = 'any'; // A placeholder to ensure it's ignored
// }
return $ignore_statuses;
},
10, // Priority
4 // Accepted args
);
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/triggers/wp-user-updates-post.php:92
src/integrations/wp/triggers/wp-anon-updates-post.php:97
protected function validate_trigger( ...$args ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return false;
}
list( $post_id, $wp_post_after, $wp_post_before ) = $args[0];
// Prevent if publishing a post.
if ( 'publish' === $wp_post_after->post_status && 'publish' !== $wp_post_before->post_status ) {
return false;
}
$ignore_statuses = apply_filters(
'automator_wp_post_updates_ignore_statuses',
array(
'trash',
'draft',
'future',
),
$post_id,
$wp_post_after,
$wp_post_before
);
// Prevent if the status is excluded
if ( in_array( $wp_post_after->post_status, $ignore_statuses, true ) ) {
return false;
}
$include_non_public_posts = apply_filters( 'automator_wp_post_updates_include_non_public_posts', false, $post_id );
if ( false === $include_non_public_posts ) {
$__object = get_post_type_object( $wp_post_after->post_type );
if ( false === $__object->public ) {
return false;
}
}
if ( empty( $post_id ) ) {
return false;
}
return apply_filters( 'automator_wp_post_updates_post_updated', true, $post_id, $wp_post_after, $wp_post_before );
}