| @@ -216,8 +216,9 @@ | ||
| 216 | 216 | $saas_base = NOTIFIER_APP_BASE_URL; |
| 217 | 217 | |
| 218 | 218 | $payload = base64_encode( wp_json_encode( array( |
| 219 | 219 | 'store_url' => site_url(), |
| 220 | + 'rest_url' => rest_url(), | |
| 220 | 221 | 'connect_token' => $token, |
| 221 | 222 | 'return_url' => admin_url( 'admin.php?page=notifier' ), |
| 222 | 223 | ) ) ); |
| 223 | 224 | |
| @@ -224,22 +225,30 @@ | ||
| 224 | 225 | return $saas_base . '/integrations/' . $slug . '/connect?payload=' . rawurlencode( $payload ); |
| 225 | 226 | } |
| 226 | 227 | |
| 227 | 228 | // ======================================== |
| 228 | - // 3. TRIGGER DISPATCH (v3 — always via Action Scheduler) | |
| 229 | + // 3. TRIGGER DISPATCH (v3) | |
| 229 | 230 | // ======================================== |
| 230 | 231 | |
| 231 | 232 | /** |
| 232 | - * Dispatch a trigger event via Action Scheduler. | |
| 233 | + * Dispatch a trigger event. | |
| 233 | 234 | * |
| 234 | - * Always async — AS provides built-in retry (3 attempts with backoff). | |
| 235 | + * Default: async via Action Scheduler — AS provides built-in retry (3 attempts with backoff). | |
| 236 | + * When the `notifier_disable_background_processing` option is `yes`, fires synchronously in the | |
| 237 | + * current request instead (no AS queueing, no retry, no dedupe). | |
| 235 | 238 | * |
| 236 | 239 | * @param string $slug Integration slug. |
| 237 | 240 | * @param string $trigger_slug Trigger slug (e.g. 'woo_order_new'). |
| 238 | - * @param array $payload Trigger payload with merge_tags_data and recipient_fields. | |
| 241 | + * @param array $context_args Context args (object_type, object_id, or form entry data). | |
| 239 | 242 | */ |
| 240 | 243 | public static function dispatch_trigger( $slug, $trigger_slug, $context_args ) { |
| 241 | 244 | if ( ! self::is_connected( $slug ) ) { |
| 245 | + return; | |
| 246 | + } | |
| 247 | + | |
| 248 | + // Real-time mode: skip Action Scheduler and fire synchronously in the same request. | |
| 249 | + if ( 'yes' === get_option( 'notifier_disable_background_processing', 'no' ) ) { | |
| 250 | + self::handle_fire_trigger_action( $slug, $trigger_slug, $context_args ); | |
| 242 | 251 | return; |
| 243 | 252 | } |
| 244 | 253 | |
| 245 | 254 | $object_id = isset( $context_args['object_id'] ) ? (int) $context_args['object_id'] : 0; |