settings = new Ads_Robots_Txt_Settings( $this->options ); add_action( 'init', [ $this, 'display_entries' ] ); add_filter( 'robots_txt', [ $this, 'output_robots_txt' ], 999999, 1 ); add_filter( 'adminoptim_notification_message_' . self::MODULE_SLUG, static function ( string $message, string $display ): string { if ( 'banner' === $display ) { return sprintf( /* translators: 1: Opening strong tag, 2: Closing strong tag. */ __( '%1$sManaging your site\'s crawl settings?%2$s Leave a ★★★★★ review on WordPress.org and help more users discover Admin Optimizer.', 'admin-optimizer' ), '', '' ); } return $message; }, 10, 2 ); } /** * Return the module's submenu definition. * * @return array */ protected function get_submenu_config(): array { return [ 'page_title' => __( 'Manage ads.txt and robots.txt', 'admin-optimizer' ), 'menu_title' => __( 'Robots & Ads Manager', 'admin-optimizer' ), 'menu_slug' => self::MENU_SLUG, 'callback' => [ $this->settings, 'render_settings_page' ], ]; } /** * Display ads.txt and app-ads.txt content * * @return void */ public function display_entries() { $request = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : false; if ( '/ads.txt' === $request && ! empty( $this->options['adstxt_content'] ) ) { header( 'Content-Type: text/plain' ); echo esc_textarea( stripslashes( $this->options['adstxt_content'] ) ); die(); } if ( '/app-ads.txt' === $request && ! empty( $this->options['app_adstxt_content'] ) ) { header( 'Content-Type: text/plain' ); echo esc_textarea( stripslashes( $this->options['app_adstxt_content'] ) ); die(); } } /** * Output robots.txt content * * @param string $output robots.txt content. * @return string robots.txt content */ public function output_robots_txt( $output ) { if ( ! empty( $this->options['robotstxt_content'] ) ) { $output = esc_textarea( stripslashes( $this->options['robotstxt_content'] ) ); } return $output; } }