LogoLogo
WordPress.orgExtensionsSupport
Version 6
Version 6
  • Notification – Custom Notifications and Alerts for WordPress
  • Known issues
  • User guide
    • How Notification plugin works
    • Who can use this plugin
    • How to create Notifications
    • Custom Post Type support
    • How to escape { character
    • Background processing
    • Troubleshooting
    • How to setup different FROM address for different Notifications
  • Developer
    • General
      • Plugin loading chain
      • Extension possibilities
      • Creating an extension
      • Bundling Notification plugin
      • White label mode
    • Notifications
      • Suppressing the Notification
      • JSON synchronization
      • Programmatic Notifications
    • Triggers
      • List of all default Triggers
      • Custom Trigger
      • Enable support for non-public Custom Post Type
      • Adding Merge Tags to existing Triggers
      • Postponing the Trigger action
      • Delaying Trigger execution with Cron
    • Carriers
      • Suppressing the Carrier
    • Snippets
      • General
        • Automatic Trigger testing
        • Allow other roles to edit Notifications
      • Triggers
        • Post
        • User
      • Integations
        • WP All Import
        • MemberPress
        • Gutenberg
  • Extensions
    • Installation
    • Planned extensions
    • 3rd Party Extensions
    • Custom Fields
    • Scheduled Triggers
Powered by GitBook
On this page

Was this helpful?

  1. Developer
  2. Triggers

Delaying Trigger execution with Cron

Useful with AJAX requests or when you have to wait for the data to be saved in database

First, you have to hook into your desired action. This is not the action added to Trigger.

// Delay the execution with cron.
add_action( 'your_desired_triggering_action', function() {

	$event_name   = 'ntfn_your_desired_triggering_action_proxy';
	$proxy_params = [ '1', 'param2_value' ];

	if ( ! wp_next_scheduled( $event_name, $proxy_params ) ) {
		wp_schedule_single_event( time() + 5, $event_name, $proxy_params );
	}

}, 10, 1 );

This action registers a single cron even, executed after 5 seconds. Be sure to pass along all the params you need to identify the action.

Then, create the proxy action, called from cron, in which you call the real trigger action. Make sure here to compose all the parameters the Trigger'saction method need.

// Cron proxy action.
add_action( 'ntfn_your_desired_triggering_action_proxy', function( $param1, $param2 ) {
	$post = get_post( $param1 );
	do_action( 'action_registered_in_trigger', $post, $param2 );
}, 10, 2 );
PreviousPostponing the Trigger actionNextCarriers

Last updated 5 years ago

Was this helpful?