'POST', 'callback' => array( $this, 'i18n' ), 'permission_callback' => array( $this, 'verify' ), ) ); } /** * Shared-secret token in the webhook URL. */ public function verify( \WP_REST_Request $r ): bool { $token = (string) $r->get_param( 'token' ); return '' !== $token && hash_equals( FileJobs::token(), $token ); } public function i18n( \WP_REST_Request $r ): \WP_REST_Response { $body = (array) $r->get_json_params(); $job_id = (string) ( $body['job_id'] ?? $body['id'] ?? '' ); if ( $job_id && isset( FileJobs::jobs()[ $job_id ] ) ) { // Defer the download so the webhook responds immediately. as_enqueue_async_action( FileJobs::POLL_HOOK, array( $job_id ), 'translateplus' ); } return rest_ensure_response( array( 'ok' => true ) ); } }