: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* The class is responsible to redirect ads.txt to centralized location.
* @author Advanced Ads <info@wpadvancedads.com>
namespace AdvancedAds\Modules\OneClick\AdsTxt;
use AdvancedAds\Utilities\WordPress;
use AdvancedAds\Framework\Interfaces\Integration_Interface;
defined( 'ABSPATH' ) || exit;
class AdsTxt implements Integration_Interface {
public function hooks(): void {
remove_action( 'advanced-ads-plugin-loaded', 'advanced_ads_ads_txt_init' );
add_action( 'init', [ $this, 'add_rewrite_rules' ] );
add_filter( 'query_vars', [ $this, 'add_query_vars' ] );
add_action( 'template_redirect', [ $this, 'handle_redirect' ] );
add_filter( 'allowed_redirect_hosts', [ $this, 'allowed_redirect_hosts' ] );
( new Detector() )->hooks();
public function add_rewrite_rules(): void {
if ( ! $wp_rewrite->using_permalinks() ) {
add_rewrite_rule( 'ads\.txt$', $wp_rewrite->index . '?adstxt=1', 'top' );
* @param array $vars Array to hold query variables.
public function add_query_vars( $vars ): array {
public function handle_redirect(): void {
if ( empty( get_query_var( 'adstxt' ) ) ) {
$redirect = sprintf( 'https://adstxt.pubguru.net/%s/ads.txt', WordPress::get_site_domain() );
wp_safe_redirect( $redirect, 301 );
* @param array $hosts Array to hold allowed hosts.
public function allowed_redirect_hosts( $hosts ): array {
$hosts[] = 'adstxt.pubguru.net';