queue_manager = $queue_manager ?? new Admin_Queue_Manager(); } /** * Update performance settings based on profile * * @param string $profile Performance profile name. */ public function update_performance_settings( $profile ) { $profile_settings = $this->get_profile_settings(); $settings = $profile_settings[ $profile ] ?? $profile_settings['slow']; $this->save_performance_options( $profile, $settings ); $this->update_cron_schedule( $settings['interval'] ); $this->queue_manager->auto_discover_pending_posts(); } /** * Get predefined performance profile settings * slow: 6 per hour = 1 post every 10 minutes * medium: 18 per hour = 1 post every 3.33 minutes (rounded to 3) * fast: 60 per hour = 1 post every 1 minute */ private function get_profile_settings() { return array( 'slow' => array( 'posts_per_hour' => 6, 'posts' => 1, 'interval' => 10, ), 'medium' => array( 'posts_per_hour' => 18, 'posts' => 1, 'interval' => 3, ), 'fast' => array( 'posts_per_hour' => 60, 'posts' => 1, 'interval' => 1, ), ); } /** * Save performance options to database * * @param string $profile Performance profile name. * @param array $settings Profile settings array. */ private function save_performance_options( $profile, $settings ) { update_option( 'accessibility_audio_tts_performance_profile', $profile ); update_option( 'accessibility_audio_tts_posts_per_session', $settings['posts'] ); update_option( 'accessibility_audio_tts_processing_interval', $settings['interval'] ); update_option( 'accessibility_audio_tts_posts_per_hour', $settings['posts_per_hour'] ); accessibility_audio_tts_debug_log( "Performance Manager: Updated settings for profile '{$profile}' - {$settings['posts_per_hour']} posts/hour, {$settings['posts']} posts/session, {$settings['interval']} min interval" ); } /** * Update cron schedule and clear existing hooks * * @param int $interval_minutes Interval in minutes. */ private function update_cron_schedule( $interval_minutes ) { wp_clear_scheduled_hook( 'accessibility_audio_tts_process_queue' ); $this->update_auto_processing_schedule( $interval_minutes ); } /** * Update auto-processing schedule with custom interval * * @param int $interval_minutes Interval in minutes. */ private function update_auto_processing_schedule( $interval_minutes ) { add_filter( 'cron_schedules', // phpcs:ignore WordPress.WP.CronInterval.ChangeDetected -- Dynamic interval based on user settings. function ( $schedules ) use ( $interval_minutes ) { $schedules['accessibility_audio_tts_auto_interval'] = array( 'interval' => $interval_minutes * 60, /* translators: %d: number of minutes */ 'display' => sprintf( __( 'Co %1$d minut', 'accessibility-audio-tts-text-to-speech-for-articles' ), $interval_minutes ), ); return $schedules; } ); if ( ! wp_next_scheduled( 'accessibility_audio_tts_process_queue' ) ) { $next_run = time() + 60; wp_schedule_event( $next_run, 'accessibility_audio_tts_auto_interval', 'accessibility_audio_tts_process_queue' ); } } /** * Get current performance profile */ public function get_current_profile() { return get_option( 'accessibility_audio_tts_performance_profile', 'slow' ); } /** * Get current performance settings */ public function get_current_settings() { return array( 'profile' => $this->get_current_profile(), 'posts_per_session' => get_option( 'accessibility_audio_tts_posts_per_session', 1 ), 'processing_interval' => get_option( 'accessibility_audio_tts_processing_interval', 10 ), ); } }