: 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;
* Container class for callbacks for overview widgets
* @subpackage Advanced Ads Plugin
class Advanced_Ads_Overview_Widgets_Callbacks {
* In case one wants to inject several dashboards into a page, we will prevent executing redundant javascript
* with the help of this little bool
private static $processed_adsense_stats_js = false;
* When doing ajax request (refreshing the dashboard), we need to have a nonce.
* one is enough, that's why we need to remember it.
private static $gadsense_dashboard_nonce = false;
* Register the plugin overview widgets
public static function setup_overview_widgets() {
$promo = new Translation_Promo(
'textdomain' => 'advanced-ads',
'plugin_name' => 'Advanced Ads',
'hook' => 'advanced-ads-overview-below-support',
'glotpress_logo' => false, // disables the plugin icon so we don’t need to keep up with potential changes.
if ( Advanced_Ads_Ad_Health_Notices::notices_enabled()
&& count( Advanced_Ads_Ad_Health_Notices::get_instance()->displayed_notices ) ) {
self::add_meta_box( 'advads_overview_notices', false, 'full', 'render_notices' );
__( 'Next steps', 'advanced-ads' ),
'advads_overview_support',
__( 'Manual and Support', 'advanced-ads' ),
if ( Advanced_Ads_AdSense_Data::get_instance()->is_setup()
&& ! Advanced_Ads_AdSense_Data::get_instance()->is_hide_stats() ) {
$disable_link_markup = '<span class="advads-hndlelinks hndle"><a href="' . esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) ) . '" target="_blank">' . esc_attr__( 'Disable', 'advanced-ads' ) . '</a></span>';
'advads_overview_adsense_stats',
__( 'AdSense Earnings', 'advanced-ads' ) . $disable_link_markup,
// add widgets for pro add ons.
self::add_meta_box( 'advads_overview_addons', __( 'Add-Ons', 'advanced-ads' ), 'full', 'render_addons' );
do_action( 'advanced-ads-overview-widgets-after' );
* Loads a meta box into output
* @param string $id meta box ID.
* @param string $title title of the meta box.
* @param string $position context in which to show the box.
* @param callable $callback function that fills the box with the desired content.
public static function add_meta_box( $id, $title, $position, $callback ) {
call_user_func( [ 'Advanced_Ads_Overview_Widgets_Callbacks', $callback ] );
do_action( 'advanced-ads-overview-widget-content-' . $id, $id );
$content = ob_get_clean();
include ADVADS_ABSPATH . 'admin/views/overview-widget.php';
* Render Ad Health notices widget
public static function render_notices() {
Advanced_Ads_Ad_Health_Notices::get_instance()->render_widget();
?><script>jQuery( document ).ready( function(){ advads_ad_health_maybe_remove_list(); });</script>
* Render next steps widget
public static function render_next_steps() {
$model = Advanced_Ads::get_instance()->get_model();
$recent_ads = $model->get_ads();
if ( count( $recent_ads ) === 0 ) :
echo '<p><a class="button button-primary" href="' . esc_url( admin_url( 'post-new.php?post_type=' . Entities::POST_TYPE_AD ) ) .
'">' . esc_html( __( 'Create your first ad', 'advanced-ads' ) ) . '</a></p>';
echo '<p><a class="button button-primary" href="' . esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) ) .
'">' . esc_attr__( 'Connect to AdSense', 'advanced-ads' ) . '</a></p>';
$is_subscribed = Advanced_Ads_Admin_Notices::get_instance()->is_subscribed();
$can_subscribe = Advanced_Ads_Admin_Notices::get_instance()->user_can_subscribe();
$options = Advanced_Ads_Admin_Notices::get_instance()->options();
$_notice = 'nl_free_addons';
<h3><?php esc_html_e( 'Join the newsletter for more benefits', 'advanced-ads' ); ?></h3>
<li><?php esc_html_e( 'Get 2 free add-ons', 'advanced-ads' ); ?></li>
<li><?php esc_html_e( 'Get the first steps and more tutorials to your inbox', 'advanced-ads' ); ?></li>
<li><?php esc_html_e( 'How to earn more with AdSense', 'advanced-ads' ); ?></li>
<div class="advads-admin-notice">
<button type="button" class="button-<?php echo ( $primary_taken ) ? 'secondary' : 'primary'; ?> advads-notices-button-subscribe" data-notice="<?php echo esc_attr( $_notice ); ?>">
<?php esc_html_e( 'Join now', 'advanced-ads' ); ?>
} elseif ( count( $recent_ads ) > 3
&& ! isset( $options['closed']['review'] ) ) {
* Ask for a review if the review message was not closed before
<div class="advads-admin-notice" data-notice="review">
<p><?php esc_html_e( 'Do you find Advanced Ads useful and would like to keep us motivated? Please help us with a review.', 'advanced-ads' ); ?>
<p><span class="dashicons dashicons-external"></span> <strong><a href="https://wordpress.org/support/plugin/advanced-ads/reviews/?rate=5#new-post" target=_"blank">
<?php esc_html_e( 'Sure, I’ll rate the plugin', 'advanced-ads' ); ?></a></strong>
<span class="dashicons dashicons-smiley"></span> <a href="javascript:void(0)" target=_"blank" class="advads-notice-dismiss">
<?php esc_html_e( 'I already did', 'advanced-ads' ); ?></a>
} elseif ( count( $recent_ads ) > 0 ) {
echo '<p><a class="button button-secondary" href="' . esc_url( admin_url( 'edit.php?post_type=' . Entities::POST_TYPE_AD ) ) .
'">' . esc_html__( 'Manage your ads', 'advanced-ads' ) . '</a></p>';
$all_access = Advanced_Ads_Admin_Licenses::get_instance()->get_probably_all_access();
if ( $is_subscribed && ! $all_access ) {
<a class="button button-primary" href="https://wpadvancedads.com/add-ons/all-access/?utm_source=advanced-ads&utm_medium=link&utm_campaign=pitch-bundle" target="_blank"><?php esc_html_e( 'Get the All Access pass', 'advanced-ads' ); ?></a>
public static function render_support() {
<li><a href="https://wpadvancedads.com/manual/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-manual" target="_blank">
<?php esc_html_e( 'Manual', 'advanced-ads' ); ?>
<li><a href="https://wpadvancedads.com/support/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-support" target="_blank">
<?php esc_html_e( 'FAQ and Support', 'advanced-ads' ); ?>
// translators: %s is a URL.
__( 'Thank the developer with a ★★★★★ review on <a href="%s" target="_blank">wordpress.org</a>', 'advanced-ads' ),
'https://wordpress.org/support/plugin/advanced-ads/reviews/#new-post'
$ignored_count = count( Advanced_Ads_Ad_Health_Notices::get_instance()->ignore );
$displayed_count = count( Advanced_Ads_Ad_Health_Notices::get_instance()->displayed_notices );
if ( ! $displayed_count && $ignored_count ) {
<p><span class="dashicons dashicons-warning"></span> <a href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin.php?page=advanced-ads&advads-show-hidden-notices=true' ), 'advanced-ads-show-hidden-notices', 'advads_nonce' ) ); ?>">
// translators: %s is the number of hidden notices.
esc_html__( 'Show %s hidden notices', 'advanced-ads' ),
do_action( 'advanced-ads-overview-below-support' );
public static function render_adsense_stats() {
$filter_value = get_option( 'advanced-ads-adsense-dashboard-filter', '' );
$filter_value = self::get_site_domain();
if ( '*' === $filter_value ) {
$report_filter = $filter_value;
$pub_id = Advanced_Ads_AdSense_Data::get_instance()->get_adsense_id();
include ADVADS_ABSPATH . 'admin/views/gadsense-dashboard.php';
* JavaScript loaded in AdSense stats widget.
* @param string $pub_id AdSense publisher ID.
final public static function adsense_stats_js( $pub_id ) {
if ( self::$processed_adsense_stats_js ) {
self::$processed_adsense_stats_js = true;
$nonce = self::get_adsense_dashboard_nonce();
window.gadsenseData = window.gadsenseData || {};
window.Advanced_Ads_Adsense_Report_Helper = window.Advanced_Ads_Adsense_Report_Helper || {};
window.Advanced_Ads_Adsense_Report_Helper.nonce = '<?php echo esc_html( $nonce ); ?>';
gadsenseData['pubId'] = '<?php echo esc_html( $pub_id ); ?>';
* Return a nonce used in the AdSense stats widget.
* @return false|mixed|string
final public static function get_adsense_dashboard_nonce() {
if ( ! self::$gadsense_dashboard_nonce ) {
self::$gadsense_dashboard_nonce = wp_create_nonce( 'advads-gadsense-dashboard' );
return self::$gadsense_dashboard_nonce;
* Extracts the domain from the site url
* @return string the domain, that was extracted from get_site_url()
public static function get_site_domain() {
preg_match( '|^([\d\w]+://)?([^/]+)|', $site, $matches );
$domain = count( $matches ) > 1 ? $matches[2] : null;
* This method is called when the dashboard data is requested via ajax
* it prints the relevant data as json, then dies.
public static function ajax_gadsense_dashboard() {
$post_data = wp_unslash( $_POST );
if ( wp_verify_nonce( $post_data['nonce'], 'advads-gadsense-dashboard' ) === false ) {
wp_send_json_error( 'Unauthorized request', 401 );
$report_type = in_array( $post_data['type'], [ 'domain', 'unit' ], true ) ? $post_data['type'] : false;
wp_send_json_error( 'Invalid arguments', 400 );
$report_filter = wp_strip_all_tags( $post_data['filter'] );
$report = new Advanced_Ads_AdSense_Report( $report_type, $report_filter );
if ( $report->get_data()->is_valid() ) {
wp_send_json_success( [ 'html' => $report->get_markup() ] );
if ( $report->refresh_report() ) {
wp_send_json_success( [ 'html' => $report->get_markup() ] );
$error_message = $report->get_last_api_error();
// Send markup with error info.
wp_send_json_success( [ 'html' => '<div class="error"><p>' . wp_kses_post( $error_message ) . '</p></div>' ] );
* @param string $title title of the box.
* @param string $main main content.
* @param string $footer footer content.
final public static function render_stats_box( $title, $main, $footer ) {
<div class="advanced-ads-stats-box flex1">
<?php echo $title; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<div class="advanced-ads-stats-box-main">
<?php echo $footer; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
* @param bool $hide_activated if true, hide activated add-ons.
public static function render_addons( $hide_activated = false ) {
if ( ! $hide_activated ) :
<p><a href="https://wpadvancedads.com/manual/how-to-install-an-add-on/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-install-add-ons" target="_blank"><?php echo esc_attr__( 'How to download, install and activate an add-on.', 'advanced-ads' ); ?></a></p>
$caching_used = Advanced_Ads_Checks::cache();
<p><?php esc_html_e( 'The solution for professional websites.', 'advanced-ads' ); ?></p><ul class='list'>
esc_html_e( 'support for cached sites', 'advanced-ads' );
if ( class_exists( 'bbPress', false ) ) :
// translators: %s is the name of another plugin.
wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), [ 'strong' => [] ] ),
</li><?php endif; /* bbPress */ ?>
if ( class_exists( 'BuddyPress', false ) ) : // BuddyPress or BuddyBoss.
// translators: %s is the name of another plugin.
wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), [ 'strong' => [] ] ),
defined( 'BP_PLATFORM_VERSION' ) ? 'BuddyBoss' : 'BuddyPress'
</li><?php endif; /* BuddyPress */ ?>
if ( defined( 'PMPRO_VERSION' ) ) :
// translators: %s is the name of another plugin.
wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), [ 'strong' => [] ] ),
</li><?php endif; /* Paid Memberships Pro */ ?>
if ( defined( 'ICL_SITEPRESS_VERSION' ) ) :
// translators: %s is the name of another plugin.
wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), [ 'strong' => [] ] ),
</li><?php endif; /* WPML */ ?>
<li><?php esc_html_e( 'click fraud protection, lazy load, ad-block ads', 'advanced-ads' ); ?></li>
<li><?php esc_html_e( '11 more display and visitor conditions', 'advanced-ads' ); ?></li>
<li><?php esc_html_e( '6 more placements', 'advanced-ads' ); ?></li>
<li><?php esc_html_e( 'placement tests for ad optimization', 'advanced-ads' ); ?></li>
<li><?php esc_html_e( 'Geo Targeting', 'advanced-ads' ); ?></li>
<li><?php esc_html_e( 'ad grids and many more advanced features', 'advanced-ads' ); ?></li>
$pro_content = ob_get_clean();
'title' => 'Advanced Ads Pro',
'link' => 'https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
'class' => 'recommended',
'desc' => __( 'Analyze clicks and impressions of your ads locally or in Google Analytics, share reports, and limit ads to a specific number of impressions or clicks.', 'advanced-ads' ),
'link' => 'https://wpadvancedads.com/add-ons/tracking/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
'desc' => __( 'Effortlessly integrate your ads on AMP (Accelerated Mobile Pages) and auto-convert your Google AdSense ad units.', 'advanced-ads' ),
'link' => 'https://wpadvancedads.com/add-ons/responsive-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
'title' => 'Google Ad Manager Integration',
'desc' => __( 'A quick and error-free way of implementing ad units from your Google Ad Manager account.', 'advanced-ads' ),
'link' => 'https://wpadvancedads.com/add-ons/google-ad-manager/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
'desc' => __( 'Increase click rates on your ads by placing them in sticky positions above, next or below your site.', 'advanced-ads' ),
'link' => 'https://wpadvancedads.com/add-ons/sticky-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
'title' => 'PopUps and Layers',
'desc' => __( 'Users will never miss an ad or other information in a PopUp. Choose when it shows up and for how long a user can close it.', 'advanced-ads' ),
'link' => 'https://wpadvancedads.com/add-ons/popup-and-layer-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
'title' => 'Selling Ads',
'desc' => __( 'Earn more money and let advertisers pay for ad space directly on the frontend of your site.', 'advanced-ads' ),
'link' => 'https://wpadvancedads.com/add-ons/selling-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
'desc' => __( 'Create a beautiful and simple slider from your ads to show more information on less space.', 'advanced-ads' ),
'link' => 'https://wpadvancedads.com/add-ons/slider/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
'title' => 'AdSense In-feed',
'desc' => __( 'Place AdSense In-feed ads between posts on homepage, category, and archive pages.', 'advanced-ads' ),
'link' => wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=advanced-ads-adsense-in-feed' ), 'install-plugin_advanced-ads-adsense-in-feed' ),
'link_title' => __( 'Install now', 'advanced-ads' ),
// get all installed plugins; installed is not activated.
$installed_plugins = get_plugins();