Snippets

Visser Labs Trigger a Scheduled Export via a WordPress Action

Created by Michael Visser

File functions.php Added

  • Ignore whitespace
  • Hide word diff
+<?php
+function custom_trigger_scheduled_export_url() {
+
+    $secret_key = ( isset( $_GET['secret_key'] ) ? sanitize_text_field( $_GET['secret_key'] ) : false );
+    if( empty( $secret_key ) ) {
+        return;
+    }
+    if( $secret_key == 'SECRET_KEY_PASSED_VIA_CRON' ) {
+        // This is the Post ID of the Scheduled Export you wish to trigger
+        $scheduled_export = 100;
+        $time = current_time( 'timestamp', 1 );
+        $hook = 'woo_ce_auto_export_schedule_' . $scheduled_export;
+        $args = array(
+            'id' => $scheduled_export
+        );
+        wp_schedule_single_event( $time, $hook, $args );
+        echo 1;
+        exit(); 
+    }
+
+}
+add_action( 'init', 'custom_trigger_scheduled_export_url', 11 ); 
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.