conditions = apply_filters( 'advanced-ads-visitor-conditions', array(
'mobile' => array( // type of the condition
'label' => __( 'device', 'advanced-ads' ),
'description' => __( 'Display ads only on mobile devices or hide them.', 'advanced-ads' ),
'metabox' => array( 'Advanced_Ads_Visitor_Conditions', 'mobile_is_or_not' ), // callback to generate the metabox
'check' => array( 'Advanced_Ads_Visitor_Conditions', 'check_mobile' ), // 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
),
'loggedin' => array(
'label' => __( 'logged in visitor', 'advanced-ads' ),
'description' => __( 'Whether the visitor has to be logged in or not in order to see the ads.', 'advanced-ads' ),
'metabox' => array( 'Advanced_Ads_Visitor_Conditions', 'metabox_is_or_not' ), // callback to generate the metabox
'check' => array( 'Advanced_Ads_Visitor_Conditions', 'check_logged_in' ) // callback for frontend check
),
));
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;
}
/**
* callback to render the mobile condition using the "is not" condition
*
* @param arr $options options of the condition
* @param int $index index of the condition
*/
static function mobile_is_or_not( $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
$operator = isset( $options['operator'] ) ? $options['operator'] : 'is';
?>
' . sprintf(__( 'Display ads by the available space on the device or target tablets with the Responsive add-on', 'advanced-ads' ), ADVADS_URL . 'add-ons/responsive-ads/#utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor-responsive') . '';
}
}
/**
* callback to display the "is not" condition
*
* @param arr $options options of the condition
* @param int $index index of the condition
*/
static function metabox_is_or_not( $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
$operator = isset( $options['operator'] ) ? $options['operator'] : 'is';
?>