array(// post types condition
'label' => __('post type', 'advanced-ads'),
'description' => __('Choose the public post types on which to display the ad.', 'advanced-ads'),
'metabox' => array('Advanced_Ads_Display_Conditions', 'metabox_post_type'), // callback to generate the metabox
'check' => array('Advanced_Ads_Display_Conditions', 'check_post_type'), // callback for frontend check
// 'helplink' => ADVADS_URL . 'manual/display-ads-either-on-mobile-or-desktop/#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor-mobile' // link to help section
),
'postids' => array(// post id condition
'label' => __('specific pages', 'advanced-ads'),
'description' => __('Choose on which individual posts, pages and public post type pages you want to display or hide ads.', 'advanced-ads'),
'metabox' => array('Advanced_Ads_Display_Conditions', 'metabox_post_ids'), // callback to generate the metabox
'check' => array('Advanced_Ads_Display_Conditions', 'check_post_ids'), // callback for frontend check
),
'general' => array(// general conditions
'label' => __('general conditions', 'advanced-ads'),
// 'description' => __( 'Choose on which individual posts, pages and public post type pages you want to display or hide ads.', 'advanced-ads' ),
'metabox' => array('Advanced_Ads_Display_Conditions', 'metabox_general'), // callback to generate the metabox
'check' => array('Advanced_Ads_Display_Conditions', 'check_general'), // callback for frontend check
),
'author' => array(// author conditions
'label' => __('author', 'advanced-ads'),
// 'description' => __( 'Choose on which individual posts, pages and public post type pages you want to display or hide ads.', 'advanced-ads' ),
'metabox' => array('Advanced_Ads_Display_Conditions', 'metabox_author'), // callback to generate the metabox
'check' => array('Advanced_Ads_Display_Conditions', 'check_author'), // callback for frontend check
),
);
// register a condition for each taxonomy for posts
$taxonomies = get_taxonomies(array('public' => true, 'publicly_queryable' => true), 'objects', 'or');
foreach ($taxonomies as $_tax) :
if ( in_array( $_tax->name, array( 'advanced_ads_groups', 'post_format' ) ) ) {
continue;
}
$conditions['taxonomy_' . $_tax->name] = array(
'label' => $_tax->label,
// 'description' => sprintf(__( 'Choose terms from the %s taxonomy a post must belong to for showing or hiding ads.', 'advanced-ads' ), $_tax->label ),
'metabox' => array('Advanced_Ads_Display_Conditions', 'metabox_taxonomy_terms'), // callback to generate the metabox
'check' => array('Advanced_Ads_Display_Conditions', 'check_taxonomies'), // callback for frontend check
'taxonomy' => $_tax->name, // unique for this type: the taxonomy name
);
$conditions['archive_' . $_tax->name] = array(
'label' => sprintf(__('archive: %s', 'advanced-ads'), $_tax->labels->singular_name),
// 'description' => sprintf(__( 'Choose on which %s archive page ads are hidden or displayeds.', 'advanced-ads' ), $_tax->label ),
'metabox' => array('Advanced_Ads_Display_Conditions', 'metabox_taxonomy_terms'), // callback to generate the metabox
'check' => array('Advanced_Ads_Display_Conditions', 'check_taxonomy_archive'), // callback for frontend check
'taxonomy' => $_tax->name, // unique for this type: the taxonomy name
);
endforeach;
$this->conditions = apply_filters('advanced-ads-display-conditions', $conditions);
ksort($this->conditions);
}
/**
*
* @return Advanced_Ads_Plugin
*/
public static function get_instance() {
// If the single instance hasn't been set, set it now.
if (null === self::$instance) {
self::$instance = new self;
}
return self::$instance;
}
/**
* controls frontend checks for conditions
*
* @param arr $options options of the condition
* @param ob $ad Advanced_Ads_Ad
* @return bool false, if ad can’t be delivered
*/
static function frontend_check($options = array(), $ad = false) {
$display_conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
if (is_array($options) && isset( $options['type'] ) && isset($display_conditions[$options['type']]['check'])) {
$check = $display_conditions[$options['type']]['check'];
} else {
return true;
}
// call frontend check callback
if (method_exists($check[0], $check[1])) {
return call_user_func(array($check[0], $check[1]), $options, $ad);
}
return true;
}
/**
* render connector option
*
* @since 1.7.0.4
* @param int $index
*/
static function render_connector_option( $index = 0, $value = 'or' ){
$label = ( $value === 'or' ) ? __( 'or', 'advanced-ads' ) : __( 'and', 'advanced-ads' );
return '';
}
/**
* callback to display the metabox for the post type condition
*
* @param arr $options options of the condition
* @param int $index index of the condition
*/
static function metabox_post_type($options, $index = 0) {
if (!isset($options['type']) || '' === $options['type']) {
return;
}
$type_options = self::get_instance()->conditions;
if (!isset($type_options[$options['type']])) {
return;
}
// form name basis
$name = self::FORM_NAME . '[' . $index . ']';
// options
?> true, 'publicly_queryable' => true), 'object', 'or');
?>
conditions;
// don’t use if this is not a taxonomy
if (!isset($type_options[$options['type']]) || !isset($type_options[$options['type']]['taxonomy'])) {
return;
}
$taxonomy = get_taxonomy($type_options[$options['type']]['taxonomy']);
if (false == $taxonomy) {
return;
}
// get values and select operator based on previous settings
$operator = ( isset($options['operator']) && $options['operator'] === 'is_not' ) ? 'is_not' : 'is';
$values = ( isset($options['value']) && is_array($options['value']) ) ? $options['value'] : array();
// 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));
// form name basis
$name = self::FORM_NAME . '[' . $index . ']';
?>
name, array('hide_empty' => false, 'number' => $max_terms));
if (!empty($terms) && !is_wp_error($terms)):
// display search field if the term limit is reached
if (count($terms) == $max_terms) :
// query active terms
if (is_array($checked) && count($checked)) {
$args = array('hide_empty' => false);
$args['include'] = $checked;
$checked_terms = get_terms($taxonomy->name, $args);
?>+