container->set(QueueRepositoryInterface::class, function () { return new QueueRepository(); }); $this->container->set(RetryPolicy::class, function () { return new RetryPolicy(); }); $this->container->set(QueueService::class, function ($c) { return new QueueService( $c->get(SheetsClientInterface::class), $c->get(QueueRepositoryInterface::class), $c->get(FieldMappingManager::class), $c->get(RetryPolicy::class), $c->get(Logger::class) ); }); $this->container->set(CronProcessor::class, function ($c) { return new CronProcessor( $c->get(QueueService::class), $c->get(QueueRepositoryInterface::class) ); }); } /** * @inheritDoc */ public function boot(): void { // Hook WP Cron event. add_action('oneclickformsync_process_queue', function () { $this->container->get(CronProcessor::class)->processQueue(); }); // Hook asynchronous queue processor loopback action. $asyncCallback = function () { $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; if (!wp_verify_nonce($nonce, 'oneclickformsync_process_queue_async_nonce')) { wp_die('Invalid nonce', 403); } $delay = isset($_POST['delay']) ? (int)$_POST['delay'] : 0; if ($delay > 0 && $delay <= 60) { @set_time_limit($delay + 30); sleep($delay); } $this->container->get(CronProcessor::class)->processQueue(); wp_die(); }; add_action('admin_post_oneclickformsync_process_queue_async', $asyncCallback); add_action('admin_post_nopriv_oneclickformsync_process_queue_async', $asyncCallback); // Hook administrator AJAX background processing fallback. add_action('wp_ajax_oneclickformsync_process_queue_ajax', function () { $nonce = isset($_POST['nonce']) ? sanitize_text_field($_POST['nonce']) : ''; if (!wp_verify_nonce($nonce, 'oneclickformsync_process_queue_ajax_nonce')) { wp_send_json_error('Invalid nonce', 403); } $count = $this->container->get(CronProcessor::class)->processQueue(); wp_send_json_success(['processed' => $count]); }); } }