: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$taxonomy = get_taxonomy( $type_options[ $options['type'] ]['taxonomy'] );
if ( false === $taxonomy ) {
// get values and select operator based on previous settings.
$operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
$values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : [];
// limit the number of terms so many terms don’t break the admin page.
$max_terms = absint( apply_filters( 'advanced-ads-admin-max-terms', 50 ) );
$name = self::get_form_name_with_index( $form_name, $index );
self::render_type_field( $options['type'], $name );
// load operator template.
include ADVADS_ABSPATH . 'admin/views/conditions/condition-operator.php';
<div class="advads-conditions-single advads-buttonset">
$terms = self::display_term_list( $taxonomy, $values, $name . '[value][]', $max_terms, $index );
include ADVADS_ABSPATH . 'admin/views/conditions/no-option.php';
* Callback to display the metabox for the taxonomies
* @param array $options options of the condition.
* @param int $index index of the condition.
* @param string $form_name name of the form, falls back to class constant.
public static function metabox_taxonomies( $options, $index = 0, $form_name = '' ) {
if ( ! isset( $options['type'] ) || '' === $options['type'] ) {
$taxonomies = get_taxonomies( [ 'public' => 1 ], 'objects' );
$name = self::get_form_name_with_index( $form_name, $index );
// get values and select operator based on previous settings.
$operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
$values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : [];
self::render_type_field( $options['type'], $name );
<div class="advads-conditions-single advads-buttonset">
$tax_label_counts = array_count_values( wp_list_pluck( $taxonomies, 'label' ) );
foreach ( $taxonomies as $_taxonomy_id => $_taxonomy ) :
if ( in_array( $_taxonomy_id, $values ) ) {
if ( $tax_label_counts[ $_taxonomy->label ] < 2 ) {
$_label = $_taxonomy->label;
$_label = sprintf( '%s (%s)', $_taxonomy->label, $_taxonomy_id );
$field_id = "advads-conditions-$_taxonomy_id-$rand";
"<label class='button' for='%s'>%s</label><input type ='checkbox' id='%s' name='%s' %s value='%s'>",
esc_attr( "{$name}[value][]" ),
checked( $_val, 1, false ),
esc_attr( $_taxonomy_id )
include ADVADS_ABSPATH . 'admin/views/conditions/not-selected.php';
* Display terms of a taxonomy for choice
* @param object $taxonomy taxonomy object.
* @param array $checked ids of checked terms.
* @param string $inputname name of the input field.
* @param int $max_terms maximum number of terms to show.
* @param int $index index of the conditions group.
* @return array|int|WP_Error
public static function display_term_list( $taxonomy, $checked = [], $inputname = '', $max_terms = 50, $index = 0 ) {
$rand = md5( $inputname );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) :
// display search field if the term limit is reached.
if ( count( $terms ) == $max_terms ) :
if ( is_array( $checked ) && count( $checked ) ) {
$args = [ 'hide_empty' => false ];
$args['include'] = $checked;
$checked_terms = get_terms( $taxonomy->name, $args );
// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen, Squiz.PHP.EmbeddedPhp.ContentAfterOpen, Squiz.PHP.EmbeddedPhp.ContentBeforeEnd, Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- Prevent whitespaces between labels
<div class="advads-conditions-terms-buttons dynamic-search"><?php
foreach ( $checked_terms as $_checked_term ) :
?><label class="button advads-button advads-ui-state-active"><span class="advads-button-text"><?php
echo esc_html( $_checked_term->name ); ?><input type="hidden" name="<?php echo esc_attr( $inputname ); ?>"
value="<?php echo esc_attr( $_checked_term->term_id ); ?>"></span></label><?php
<div class="advads-conditions-terms-buttons dynamic-search"></div>
"<span class='advads-conditions-terms-show-search button' title='%s'>+</span><br>",
esc_attr_x( 'add more terms', 'display the terms search field on ad edit page', 'advanced-ads' )
"<input type='text' class='advads-conditions-terms-search' data-tag-name='%s' data-input-name='%s' placeholder='%s'>",
esc_attr( $taxonomy->name ),
esc_attr__( 'term name or id', 'advanced-ads' )
foreach ( $terms as $_term ) {
$field_id = "advads-conditions-$_term->term_id-$rand";
"<input type='checkbox' id='%s' name='%s' value='%s' %s><label for='%s'>%s</label>",
esc_attr( $_term->term_id ),
checked( in_array( $_term->term_id, $checked ), true, false ),
include ADVADS_ABSPATH . 'admin/views/conditions/not-selected.php';
* Callback to display the metabox for the taxonomy archive pages
* @param array $options options of the condition.
* @param int $index index of the condition.
* @param string $form_name name of the form, falls back to class constant.
public static function metabox_post_ids( $options, $index = 0, $form_name = '' ) {
if ( ! isset( $options['type'] ) || '' === $options['type'] ) {
// get values and select operator based on previous settings.
$operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
$values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : [];
$name = self::get_form_name_with_index( $form_name, $index );
self::render_type_field( $options['type'], $name );
// load operator template.
include ADVADS_ABSPATH . 'admin/views/conditions/condition-operator.php';
<div class="advads-conditions-single advads-buttonset advads-conditions-postid-buttons">
// Query active post ids.
// phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen, Squiz.PHP.EmbeddedPhp.ContentAfterOpen, Squiz.PHP.EmbeddedPhp.ContentBeforeEnd, Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- Prevent whitespaces between labels
$the_query = new WP_Query( $args );
while ( $the_query->have_posts() ) {
?><label class="button advads-button advads-ui-state-active"><span class="advads-button-text"><?php
sprintf( '%s (%s)', get_the_title( $the_query->post->ID ), $the_query->post->post_type )
); ?></span><input type="hidden" name="<?php echo esc_attr( $name ); ?>[value][]"
value="<?php echo esc_attr( $the_query->post->ID ); ?>"></label><?php
"<span class='advads-conditions-postids-show-search button' style='%s'>+</span>",
empty( $values ) ? 'display:none;' : ''
"<p class='advads-conditions-postids-search-line'><input type='text' class='advads-display-conditions-individual-post' style='%s' placeholder='%s' data-field-name='%s' />%s</p></div>",
! empty( $values ) ? 'display:none;' : '',
esc_attr__( 'title or id', 'advanced-ads' ),
wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false, false ),
* Callback to display the metabox for the general display conditions
* @param array $options options of the condition.
* @param int $index index of the condition.
* @param string $form_name name of the form, falls back to class constant.
public static function metabox_general( $options, $index = 0, $form_name = '' ) {
// general conditions array.
$conditions = self::get_instance()->general_conditions();
if ( ! isset( $options['type'] ) || '' === $options['type'] ) {
$name = self::get_form_name_with_index( $form_name, $index );
$values = isset( $options['value'] ) ? $options['value'] : [];
<div class="advads-conditions-single advads-buttonset">
self::render_type_field( $options['type'], $name );
$rand = md5( $form_name );
foreach ( $conditions as $_key => $_condition ) {
$value = ( [] === $values || in_array( $_key, $values, true ) ) ? 1 : 0;
$field_id = "advads-conditions-$_key-$rand";
"<input type='checkbox' id='%s' name='%s' %s value='%s'>",
esc_attr( "{$name}[value][]" ),
checked( 1, $value, false ),
"<label for='%s'>%s</label>",
esc_html( $_condition['label'] )
include ADVADS_ABSPATH . 'admin/views/conditions/not-selected.php';
* Retrieve the array with general conditions
* @return array $conditions
public static function general_conditions() {
'advanced-ads-display-conditions-general',
'label' => __( 'Home Page', 'advanced-ads' ),
'description' => __( 'show on Home page', 'advanced-ads' ),
'label' => __( 'Singular Pages', 'advanced-ads' ),
'description' => __( 'show on singular pages/posts', 'advanced-ads' ),
'label' => __( 'Archive Pages', 'advanced-ads' ),
'description' => __( 'show on any type of archive page (category, tag, author and date)', 'advanced-ads' ),
'label' => __( 'Search Results', 'advanced-ads' ),
'description' => __( 'show on search result pages', 'advanced-ads' ),
'label' => __( '404 Page', 'advanced-ads' ),
'description' => __( 'show on 404 error page', 'advanced-ads' ),
'label' => __( 'Attachment Pages', 'advanced-ads' ),
'description' => __( 'show on attachment pages', 'advanced-ads' ),
'label' => __( 'Secondary Queries', 'advanced-ads' ),
'description' => __( 'allow ads in secondary queries', 'advanced-ads' ),
'label' => __( 'RSS Feed', 'advanced-ads' ),
'description' => __( 'allow ads in RSS Feed', 'advanced-ads' ),
'label' => __( 'REST API', 'advanced-ads' ),
'description' => __( 'allow ads in REST API', 'advanced-ads' ),
* Callback to display the 'content age' condition
* @param array $options options of the condition.
* @param int $index index of the condition.
* @param string $form_name name of the form, falls back to class constant.
public static function metabox_content_age( $options, $index = 0, $form_name = '' ) {
if ( ! isset( $options['type'] ) || '' === $options['type'] ) {
$type_options = self::get_instance()->conditions;
if ( ! isset( $type_options[ $options['type'] ] ) ) {
$name = self::get_form_name_with_index( $form_name, $index );
$operator = isset( $options['operator'] ) ? $options['operator'] : 'older_than';
$value = ( isset( $options['value'] ) && is_numeric( $options['value'] ) ) ? (float) $options['value'] : 0;
self::render_type_field( $options['type'], $name );
<select name="<?php echo esc_attr( $name ); ?>[operator]">
<option value="older_than" <?php selected( 'older_than', $operator ); ?>><?php esc_html_e( 'older than', 'advanced-ads' ); ?></option>
<option value="younger_than" <?php selected( 'younger_than', $operator ); ?>><?php esc_html_e( 'younger than', 'advanced-ads' ); ?></option>
<input type="text" name="<?php echo esc_attr( $name ); ?>[value]" value="<?php echo esc_attr( $value ); ?>"/>
<?php esc_html_e( 'days', 'advanced-ads' ); ?>
<?php esc_html_e( 'Display ads based on the age of a page or post.', 'advanced-ads' ); ?>
<a href="https://wpadvancedads.com/manual/display-ads-by-content-age/?utm_source=advanced-ads&utm_medium=link&utm_campaign=condition-content-age" class="advads-manual-link" target="_blank">
<?php esc_html_e( 'Manual', 'advanced-ads' ); ?>
* Check post type display condition in frontend
* @param array $options options of the condition.
* @param Advanced_Ads_Ad $ad Advanced_Ads_Ad.
* @return bool true if can be displayed
public static function check_post_type( $options, Advanced_Ads_Ad $ad ) {
if ( ! isset( $options['value'] ) || ! is_array( $options['value'] ) ) {
if ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) {
$ad_options = $ad->options();
$query = $ad_options['wp_the_query'];
$post = isset( $ad_options['post'] ) ? $ad_options['post'] : null;
$post_type = isset( $post['post_type'] ) ? $post['post_type'] : false;
if ( ! self::can_display_ids( $post_type, $options['value'], $operator ) ) {
* Check author display condition in frontend
* @param array $options options of the condition.
* @param Advanced_Ads_Ad $ad Advanced_Ads_Ad.
* @return bool true if can be displayed
public static function check_author( $options, Advanced_Ads_Ad $ad ) {
if ( ! isset( $options['value'] ) || ! is_array( $options['value'] ) ) {
if ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) {
$ad_options = $ad->options();
$post = isset( $ad_options['post'] ) ? $ad_options['post'] : null;
$post_author = isset( $post['author'] ) ? $post['author'] : false;
if ( ! self::can_display_ids( $post_author, $options['value'], $operator ) ) {
* Check taxonomies display condition in frontend
* @param array $options options of the condition.
* @param Advanced_Ads_Ad $ad ad.
* @return bool true if can be displayed
public static function check_taxonomies( $options, Advanced_Ads_Ad $ad ) {
if ( ! isset( $options['value'] ) ) {
if ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) {
$ad_options = $ad->options();
$query = $ad_options['wp_the_query'];
$post_id = isset( $ad_options['post']['id'] ) ? $ad_options['post']['id'] : null;
// get terms of the current taxonomy.
$type_options = self::get_instance()->conditions;
if ( ! isset( $options['type'] ) || ! isset( $type_options[ $options['type'] ]['taxonomy'] ) ) {
$taxonomy = $type_options[ $options['type'] ]['taxonomy'];
$terms = get_the_terms( $post_id, $taxonomy );
if ( is_array( $terms ) ) {
foreach ( $terms as $term ) {
$term_ids[] = $term->term_id;
} elseif ( false === $terms && 'is' === $operator ) {
// don’t show if should show only for a specific tag.
if ( 'is' === $operator && ( ! isset( $query['is_singular'] ) || ! $query['is_singular'] ) ) {