: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
unset( $alert_items[ $internal_id ] );
* Remove alerts dynamically when showing them.
* only applies to stored alerts and not when they are loaded directly from AdSense
* @param array $alerts Alert options.
* @return array $alerts Modified alert options.
public static function filter_stored_account_alerts( array $alerts ) {
if ( empty( $alerts['items'] ) || ! is_array( $alerts['items'] ) ) {
* Asside from the basic filter, we also filter out some messages only from showing up while we still import them
* This allows us to show them only under related conditions
// Remove `ads.txt` related alerts if the file is displayed to visitors.
if ( Advanced_Ads_Ads_Txt_Admin::is_displayed() ) {
$disabled_alerts = [ 'ALERT_TYPE_ADS_TXT_UNAUTHORIZED', 'ADS_TXT_MISSING', 'ADS_TXT_ISSUES' ];
$alerts['items'] = self::filter_account_alerts( $alerts['items'], $disabled_alerts );
* Checks if there is any AdSense warning for the currently connected AdSense account.
* @param array $messages The array of messages.
* @return array The modified array.
public static function adsense_warnings_check( $messages ) {
$data = Advanced_Ads_AdSense_Data::get_instance();
$adsense_id = $data->get_adsense_id();
$alerts = self::get_stored_account_alerts( $adsense_id );
if ( ! is_array( $messages ) ) {
if ( ! empty( $alerts ) && ! empty( $alerts['items'] ) ) {
/* translators: %s admin setting page link */
__( 'There are one or more warnings about the currently linked AdSense account. You can view them <a href="%s">here</a>', 'advanced-ads' ),
[ 'a' => [ 'href' => true ] ]
esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) )
public static function get_option() {
$options = get_option( self::OPTNAME, [] );
if ( ! is_array( $options ) ) {
return $options + self::$default_options;
* Get the URL to the AdSense error page
* @param string $code Add the error code to the URL.
* @return string The entire text with the url.
public static function get_adsense_error_link( $code = '' ) {
if ( ! empty( $code ) ) {
// translators: %1$s is an anchor (link) opening tag, %2$s is the closing tag.
esc_attr__( 'Learn more about AdSense account issues %1$shere%2$s.', 'advanced-ads' ),
'<a href="https://wpadvancedads.com/adsense-errors/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-error' . $code . '" target="_blank">',
* Get custom account connection error message list.
public static function get_connect_error_messages() {
$health_class = Advanced_Ads_Ad_Health_Notices::get_instance();
foreach ( $health_class->default_notices as $key => $value ) {
if ( 0 === strpos( $key, 'adsense_connect_' ) ) {
$messages[ substr( $key, strlen( 'adsense_connect_' ) ) ] = $value['text'];
* Get custom messages for AdSense alerts.
public static function get_adsense_alert_messages() {
$health_class = Advanced_Ads_Ad_Health_Notices::get_instance();
foreach ( $health_class->default_notices as $key => $value ) {
if ( 0 === strpos( $key, 'adsense_alert_' ) ) {
$messages[ substr( $key, strlen( 'adsense_alert_' ) ) ] = $value['text'];
* @return Advanced_Ads_AdSense_MAPI
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
* Get a hint for an error object that was received from AdSense
* @param string $reason The reason from the response's error.
* @return string|bool if there is a hint for this reason, a string containing the hint will be returned.
final public static function get_adsense_error_hint( $reason ) {
if ( 'authError' === $reason ) {
/* translators: 1: A link to the settings page 2: The name of an ad network */
__( 'Please try to <a href="%1$s" target="_blank">reconnect to your %2$s account</a>.', 'advanced-ads' ),
admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ),