: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public function get_ad_weights( $ad_ids = [] ) {
if ( is_array( $this->ad_weights ) ) {
return $this->ad_weights;
$weights = get_option( 'advads-ad-weights', [] );
if ( array_key_exists( $this->id, $weights ) ) {
$this->ad_weights = $weights[ $this->id ];
asort( $this->ad_weights );
// add ads whose weight has not yet been saved with the default value.
foreach ( $ad_ids as $ad_id ) {
if ( ! array_key_exists( $ad_id, $this->ad_weights ) ) {
$this->ad_weights[ $ad_id ] = self::MAX_AD_GROUP_DEFAULT_WEIGHT;
return $this->ad_weights;
* Save ad group information that are not included in terms or ad weight
* @param arr $args group arguments
public function save($args = []) {
$defaults = [ 'type' => 'default', 'ad_count' => 1, 'options' => [] ];
$args = wp_parse_args($args, $defaults);
// get global ad group option
$groups = get_option( 'advads-ad-groups', [] );
$groups[$this->id] = $args;
update_option( 'advads-ad-groups', $groups );
* Delete all the ad weights for a group by id
public static function delete_ad_weights($group_id){
$all_weights = get_option( 'advads-ad-weights', [] );
if ($all_weights && isset($all_weights[$group_id])){
unset($all_weights[$group_id]);
update_option( 'advads-ad-weights', $all_weights );
* Create a wrapper to place around the group.
private function create_wrapper() {
if ( $this->ad_args['is_top_level'] ) {
$placement_state = isset( $this->ad_args['ad_label'] ) ? $this->ad_args['ad_label'] : 'default';
$this->label = Advanced_Ads::get_instance()->get_label( $placement_state );
if ( ! empty( $this->ad_args['output']['class'] ) && is_array( $this->ad_args['output']['class'] ) ) {
$this->wrapper['class'] = $this->ad_args['output']['class'];
// ad Health Tool add class wrapper
if ( WordPress::user_can('advanced_ads_edit_ads') ) {
$frontend_prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
$this->wrapper['class'][] = $frontend_prefix . 'highlight-wrapper';
if ( isset( $this->ad_args['output']['wrapper_attrs'] ) && is_array( $this->ad_args['output']['wrapper_attrs'] ) ) {
foreach ( $this->ad_args['output']['wrapper_attrs'] as $key => $value ) {
$this->wrapper[$key] = $value;
if ( ! empty( $this->ad_args['placement_position'] ) ) {
switch ( $this->ad_args['placement_position'] ) {
$this->wrapper['style']['float'] = 'left';
$this->wrapper['style']['float'] = 'right';
// We don't know whether the 'add_wrapper_sizes' option exists and width is set.
$this->wrapper['style']['text-align'] = 'center';
$this->wrapper = (array) apply_filters( 'advanced-ads-output-wrapper-options-group', $this->wrapper, $this );
if ( ( $this->wrapper !== [] || $this->label ) && ! isset( $this->wrapper['id'] ) ) {
$prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
$this->wrapper['id'] = $prefix . mt_rand();
* Calculate the number of available weights for a group depending on
* number of ads and default value.
* @param int $num_ads Number of ads in the group.
* @return max weight used in group settings
public static function get_max_ad_weight( $num_ads = 1 ){
// use default if lower than default.
$num_ads = absint( $num_ads );
// use number of ads or max ad weight value, whatever is higher
$max_weight = $num_ads < self::MAX_AD_GROUP_DEFAULT_WEIGHT ? self::MAX_AD_GROUP_DEFAULT_WEIGHT : $num_ads;
// allow users to manipulate max ad weight
return apply_filters( 'advanced-ads-max-ad-weight', $max_weight, $num_ads );
* @param Advanced_Ads_Group $group The group object.
* @return string[] Group hints (escaped strings).
public static function get_hints( Advanced_Ads_Group $group ) {
! Advanced_Ads_Checks::cache()
|| count( $group->get_all_ads() ) < 2
if ( ! class_exists( 'Advanced_Ads_Pro' ) ) {
$installed_plugins = get_plugins();
if ( isset( $installed_plugins['advanced-ads-pro/advanced-ads-pro.php'] ) ) {
$link = wp_nonce_url( 'plugins.php?action=activate&plugin=advanced-ads-pro/advanced-ads-pro.php', 'activate-plugin_advanced-ads-pro/advanced-ads-pro.php' );
$link_title = __( 'Activate now', 'advanced-ads' );
$link = 'https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=groups-CB';
$link_title = __( 'Get this add-on', 'advanced-ads' );
// translators: %1$s is an URL, %2$s is a URL text
__( 'It seems that a caching plugin is activated. Your ads might not rotate properly. The cache busting in Advanced Ads Pro will solve that. <a href="%1$s" target="_blank">%2$s.</a>', 'advanced-ads' ),
* Allows to add new hints.
* @param string[] $hints Existing hints (escaped strings).
* @param Advanced_Ads_Group $group The group object.
return apply_filters( 'advanced-ads-group-hints', $hints, $group );