_x( 'AJAX', 'setting label', 'advanced-ads-pro' ),
Advanced_Ads_Pro_Module_Cache_Busting::OPTION_OFF => _x( 'off', 'setting label', 'advanced-ads-pro' ),
Advanced_Ads_Pro_Module_Cache_Busting::OPTION_AUTO => _x( 'auto', 'setting label', 'advanced-ads-pro' ),
);
// options
$value = isset( $placement['options']['cache-busting'] ) ? $placement['options']['cache-busting'] : null;
$value = $value === Advanced_Ads_Pro_Module_Cache_Busting::OPTION_ON ? Advanced_Ads_Pro_Module_Cache_Busting::OPTION_ON : ( $value === Advanced_Ads_Pro_Module_Cache_Busting::OPTION_OFF ? Advanced_Ads_Pro_Module_Cache_Busting::OPTION_OFF : Advanced_Ads_Pro_Module_Cache_Busting::OPTION_AUTO );
ob_start();
foreach ( $values as $k => $l ) {
$selected = checked( $value, $k, false );
echo '';
}
$option_content = ob_get_clean();
if( class_exists( 'Advanced_Ads_Admin_Options' ) ){
Advanced_Ads_Admin_Options::render_option(
'placement-cache-busting',
_x( 'Cache-busting', 'placement admin label', 'advanced-ads-pro' ),
$option_content );
}
}
/**
* enqueue scripts for validation the ad
*/
public function enqueue_admin_scripts() {
$screen = get_current_screen();
$uriRelPath = plugin_dir_url( __FILE__ );
if ( isset( $screen->id ) && $screen->id === 'advanced_ads' ) { //ad edit page
wp_register_script( 'krux/prescribe', $uriRelPath . 'inc/prescribe.js', array( 'jquery' ), '1.1.3' );
wp_enqueue_script( 'advanced-ads-pro/cache-busting-admin', $uriRelPath . 'inc/admin.js', array( 'krux/prescribe' ), AAP_VERSION );
// advads.get_cookie and similar functions may be used inside ad content
Advanced_Ads_Plugin::get_instance()->enqueue_scripts();
} elseif( Advanced_Ads_Admin::screen_belongs_to_advanced_ads() ) {
wp_enqueue_script( 'advanced-ads-pro/cache-busting-admin', $uriRelPath . 'inc/admin.js', array(), AAP_VERSION );
}
}
/**
* add validation for cache-busting
*
* @param obj $ad ad object
* @param arr $types ad types
*/
public function check_ad( $ad, $types = array() ) {
$options = $ad->options();
include dirname( __FILE__ ) . '/views/settings_check_ad.php';
}
// public function save_options( $options = array(), $ad = 0 ) {
// if ( isset( $_POST['advanced_ad']['cache-busting']['possible'] ) ) {
// $options['cache-busting']['possible'] = ('true' === $_POST['advanced_ad']['cache-busting']['possible'] ) ? true : false;
// }
// return $options;
// }
/**
* show cache-busting specific ad notices
*
* @since 1.13.1
*/
public function ad_notices( $notices, $box, $post ){
$ad = new Advanced_Ads_Ad( $post->ID );
// $content = json_decode( stripslashes( $ad->content ) );
switch ($box['id']){
case 'ad-parameters-box' :
// show hint that for ad-group ad type, cache-busting method will only be AJAX or off
if( 'group' === $ad->type ){
$notices[] = array(
'text' => __( 'The Ad Group ad type can only use AJAX or no cache-busting, but not passive cache-busting.', 'advanced-ads-pro' ),
// 'class' => 'advads-ad-notice-pro-ad-group-cache-busting',
);
}
break;
}
return $notices;
}
}