settings = new Ads_Robots_Txt_Settings( $this->options ); add_action( 'init', [ $this, 'display_entries' ] ); add_filter( 'robots_txt', [ $this, 'output_robots_txt' ], 999999, 1 ); } /** * 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; } }