: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
use AdvancedAds\Entities;
class Advanced_Ads_AdSense_Data {
* @var Advanced_Ads_AdSense_Data
private static $instance;
private function __construct() {
$options = get_option( GADSENSE_OPT_NAME, [] );
if ( ! isset( $options['adsense-id'] ) ) {
$options['adsense-id'] = '';
update_option( GADSENSE_OPT_NAME, $options );
$this->options = wp_parse_args(
'page-level-enabled' => false,
// Resizing method for responsive ads.
'auto' => __( 'Auto', 'advanced-ads' ),
public function get_options() {
* @param mixed $ad Ad instance.
public function get_adsense_id( $ad = null ) {
if ( ! empty( $ad ) && isset( $ad->is_ad ) && true === $ad->is_ad && 'adsense' === $ad->type ) {
$ad_content = json_decode( $ad->content );
// phpcs:disable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
if ( $ad_content && isset( $ad_content->pubId ) && ! empty( $ad_content->pubId ) ) {
return $ad_content->pubId;
// phpcs:enable WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
return trim( $this->options['adsense-id'] );
* @deprecated The feature is deprecated by AdSense since 2019
public function get_limit_per_page() {
_deprecated_function( __METHOD__, '1.47.0' );
public function get_responsive_sizing() {
$this->resizing = apply_filters( 'advanced-ads-gadsense-responsive-sizing', $this->resizing );
* @return Advanced_Ads_AdSense_Data
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new Advanced_Ads_AdSense_Data();
public function is_page_level_enabled() {
return $this->options['page-level-enabled'];
public function is_setup() {
if ( isset( $this->options ) && is_array( $this->options ) && isset( $this->options['adsense-id'] ) && $this->options['adsense-id'] ) {
$adsense_id = $this->get_adsense_id();
return Advanced_Ads_AdSense_MAPI::has_token( $adsense_id );
* Whether to hide the AdSense stats metabox.
public function is_hide_stats() {
if ( $post instanceof WP_Post && Entities::POST_TYPE_AD === $post->post_type ) {
$the_ad = \Advanced_Ads\Ad_Repository::get( $post->ID );
if ( 'adsense' !== $the_ad->type ) {
return isset( $this->options['hide-stats'] );