scheduler = $scheduler; $this->remove_file_command_handler = $remove_file_command_handler; $this->populate_file_command_handler = $populate_file_command_handler; $this->options_helper = $options_helper; } /** * Initializes the integration. * * This is the place to register hooks and filters. * * @return void */ public function register_hooks() { \add_action( 'update_option_wpseo', [ $this, 'check_toggle_llms_txt' ], 10, 2 ); \add_action( 'update_option_wpseo_llmstxt', [ $this, 'check_llms_txt_selection' ], 10, 2 ); } /** * Checks if the LLMS.txt feature is toggled. * * @param array> $old_value The old value of the option. * @param array> $new_value The new value of the option. * * @return void */ public function check_toggle_llms_txt( $old_value, $new_value ): void { $option_name = 'enable_llms_txt'; if ( \array_key_exists( $option_name, $old_value ) && \array_key_exists( $option_name, $new_value ) && $old_value[ $option_name ] !== $new_value[ $option_name ] ) { if ( $new_value[ $option_name ] === true ) { $this->scheduler->schedule_weekly_llms_txt_population(); $this->populate_file_command_handler->handle(); } else { $this->scheduler->unschedule_llms_txt_population(); $this->remove_file_command_handler->handle(); } } } /** * Checks if any of the llms.txt settings were changed. * * @param array> $old_value The old value of the option. * @param array> $new_value The new value of the option. * * @return void */ public function check_llms_txt_selection( $old_value, $new_value ): void { if ( $this->options_helper->get( 'enable_llms_txt', false ) !== true ) { return; } foreach ( $this->option_names as $option_name ) { if ( ! \array_key_exists( $option_name, $old_value ) || ! \array_key_exists( $option_name, $new_value ) ) { continue; } if ( $old_value[ $option_name ] !== $new_value[ $option_name ] ) { $this->populate_file_command_handler->handle(); return; } } } }