status_provider = $status_provider ?? new Cron_Status_Provider(); $this->execution_manager = $execution_manager ?? new Cron_Execution_Manager(); $this->posts_manager = $posts_manager ?? new Cron_Posts_Manager(); } /** * Register WP AJAX actions. * * Only prefixed actions are registered to comply with naming rules. */ public function register_actions() { add_action( 'wp_ajax_accessibility_audio_tts_get_cron_status', array( $this, 'handle_get_cron_status' ) ); add_action( 'wp_ajax_accessibility_audio_tts_trigger_cron_manually', array( $this, 'handle_trigger_cron_manually' ) ); add_action( 'wp_ajax_accessibility_audio_tts_get_generated_posts', array( $this, 'handle_get_generated_posts' ) ); } /** * Return cron status payload. * * @return void */ public function handle_get_cron_status() { accessibility_audio_tts_debug_log( '=== AAT_GET_CRON_STATUS START ===' ); try { if ( ! $this->validate_ajax_request() ) { return; } accessibility_audio_tts_debug_log( 'Security checks passed, processing cron status...' ); $response_data = $this->status_provider->get_complete_status(); accessibility_audio_tts_debug_log( 'Sending success response with ' . count( $response_data ) . ' fields' ); wp_send_json_success( $response_data ); } catch ( \Exception $e ) { $this->handle_ajax_exception( $e, 'AAT cron status' ); } } /** * Trigger cron manually and return result. * * @return void */ public function handle_trigger_cron_manually() { accessibility_audio_tts_debug_log( '=== TRIGGER_CRON_MANUALLY START ===' ); try { if ( ! $this->validate_ajax_request() ) { return; } accessibility_audio_tts_debug_log( 'Security checks passed for trigger_cron_manually, spawning cron...' ); $result = $this->execution_manager->trigger_cron_manually(); if ( $result['success'] ) { wp_send_json_success( $result ); } else { wp_send_json_error( $result ); } } catch ( \Exception $e ) { $this->handle_ajax_exception( $e, 'Manual cron trigger' ); } } /** * Get posts list for display. * * @return void */ public function handle_get_generated_posts() { try { if ( ! $this->validate_ajax_request() ) { return; } $response = $this->posts_manager->get_generated_posts(); wp_send_json_success( $response ); } catch ( \Exception $e ) { $this->handle_ajax_exception( $e, 'Get generated posts' ); } } /** * Get status provider instance. * * @return Cron_Status_Provider Status provider. */ public function get_status_provider() { return $this->status_provider; } /** * Get execution manager instance. * * @return Cron_Execution_Manager Execution manager. */ public function get_execution_manager() { return $this->execution_manager; } /** * Get posts manager instance. * * @return Cron_Posts_Manager Posts manager. */ public function get_posts_manager() { return $this->posts_manager; } }