options_helper = $options_helper; $this->notification_center = $notification_center; $this->presenter = $presenter; } /** * Initializes the integration. * * This is the place to register hooks and filters. * * @return void */ public function register_hooks() { \add_action( 'admin_init', [ $this, 'maybe_show_notification' ], 10, 2 ); } /** * Manage the search engines discouraged notification. * * Shows the notification if needed and deletes it if needed. * * @return void */ public function maybe_show_notification() { if ( ! $this->should_show_file_failure_notification() ) { $this->remove_file_failure_notification_if_exists(); } else { $this->maybe_add_file_failure_notification(); } } /** * Whether the file failure notification should be shown. * * @return bool */ private function should_show_file_failure_notification(): bool { return $this->options_helper->get( 'enable_llms_txt', false ) && \get_option( Populate_File_Command_Handler::GENERATION_FAILURE_OPTION, false ) !== false; } /** * Remove the search engines discouraged notification if it exists. * * @return void */ private function remove_file_failure_notification_if_exists() { $this->notification_center->remove_notification_by_id( self::NOTIFICATION_ID ); } /** * Add the search engines discouraged notification if it does not exist yet. * * @return void */ private function maybe_add_file_failure_notification() { if ( ! $this->notification_center->get_notification_by_id( self::NOTIFICATION_ID ) ) { $notification = new Yoast_Notification( $this->presenter->present(), [ 'type' => Yoast_Notification::ERROR, 'id' => self::NOTIFICATION_ID, 'capabilities' => 'wpseo_manage_options', 'priority' => 1, ], ); $this->notification_center->restore_notification( $notification ); $this->notification_center->add_notification( $notification ); } } }