Filter
uncanny-automator
automator_elem_user_creates_post_cron_enabled
Filters whether the cron job for creating posts from Elementor templates is enabled when a user creates a post.
add_filter( 'automator_elem_user_creates_post_cron_enabled', $callback, 10, 4 );
Description
Allows developers to control whether Elementor-created post triggers use cron. By default, cron processing is enabled. Developers can return `false` to disable cron and run the trigger immediately, or modify other parameters for advanced control over the trigger's execution flow.
Usage
add_filter( 'automator_elem_user_creates_post_cron_enabled', 'your_function_name', 10, 4 );
Parameters
-
$post_id(mixed) - This parameter is a boolean value indicating whether the cron job for post creation is enabled.
-
$post(mixed) - This parameter contains the ID of the post that was just created or updated.
-
$update(mixed) - This parameter contains the post object.
-
$this(mixed) - This parameter contains a reference to the current instance of the `automator_elem_user_creates_post_cron_enabled` class.
Return Value
The filtered value.
Examples
/**
* Example function to conditionally disable cron processing for Elementor post creation.
*
* This filter allows you to override the default behavior and decide whether
* to use cron for processing automations when a post is published using Elementor.
* For example, you might want to disable cron for very simple posts or during
* specific maintenance periods.
*
* @param bool $cron_enabled Whether cron processing is enabled (default is true).
* @param int $post_id The ID of the post that was just published.
* @param object $post The WP_Post object for the published post.
* @param bool $update Whether this is an update to an existing post.
* @param object $this The instance of the elem-post-published class.
*
* @return bool The new value for $cron_enabled.
*/
add_filter( 'automator_elem_user_creates_post_cron_enabled', function ( $cron_enabled, $post_id, $post, $update, $elem_post_published_instance ) {
// Example: Disable cron processing if the post is a draft and not an update.
// This might be useful if you only want automations to trigger on actual
// public post publications, not draft saves.
if ( 'draft' === $post->post_status && ! $update ) {
return false; // Disable cron processing
}
// Example: If the post title contains "testing", disable cron.
if ( strpos( $post->post_title, 'testing' ) !== false ) {
return false; // Disable cron processing
}
// Otherwise, keep the default cron enabled behavior.
return $cron_enabled;
}, 10, 5 );
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/elementor/triggers/elem-post-published.php:144
public function schedule_a_post( $post_id, $post, $update, $post_before ) {
// only run when posts
// are published first time
if ( ! Automator()->utilities->is_wp_post_being_published( $post, $post_before ) ) {
return;
}
// if post is not published with Elementor.
$created_by_elem = get_post_meta( $post_id, '_elementor_edit_mode', true );
if ( empty( $created_by_elem ) ) {
// Immediately run validate_conditions
return;
}
$cron_enabled = apply_filters( 'automator_elem_user_creates_post_cron_enabled', true, $post_id, $post, $update, $this );
// Allow people to disable cron processing.
if ( false === $cron_enabled ) {
// Immediately run post_publised if cron not enabled.
$this->post_published( $post_id );
return;
}
if ( wp_next_scheduled( 'elem_wp_after_insert_post', array( $post_id ) ) ) {
return;
}
// Scheduling for 10 sec so that all tax/terms are stored
return wp_schedule_single_event(
apply_filters( 'automator_schedule_a_post_time_for_elem', time() + 10, $post_id, $post, $update ),
'elem_wp_after_insert_post',
array(
$post_id,
)
);
}