$location_args ) { $location_settings = adsensei_get_ad_location_settings( $location ); $html .= $adsensei->html->checkbox( array( 'name' => 'adsensei_settings[location_settings][' . $location . '][status]', 'current' => !empty( $location_settings['status'] ) ? $location_settings['status'] : null, 'class' => 'adsensei-checkbox adsensei-assign' ) ); $html .= ' ' . __( 'Assign', 'adsenseib30' ) . ' '; $html .= $adsensei->html->select( array( 'options' => adsensei_get_ads(), 'name' => 'adsensei_settings[location_settings][' . $location . '][ad]', 'selected' => !empty( $location_settings['ad'] ) ? $location_settings['ad'] : null, 'show_option_all' => false, 'show_option_none' => false ) ); $html .= ' ' . $location_args['description'] . ''; } } return $html; } /** * This hook should be removed and the hook function should replace entire "adsensei_ad_position_callback" function. */ add_filter( 'adsensei_ad_position_callback', 'adsensei_render_ad_locations' ); /** * Register an ad position. * * @param array $args Location settings */ function adsensei_register_ad( $args ) { global $_adsensei_registered_ad_locations; $defaults = array( 'location' => '', 'description' => '' ); $args = wp_parse_args( $args, $defaults ); if ( empty( $args['location'] ) ) { return; } if ( ! isset( $_adsensei_registered_ad_locations ) ) { $_adsensei_registered_ad_locations = array(); } $_adsensei_registered_ad_locations [ $args['location'] ] = $args; } /** * Whether a registered ad location has an ad assigned to it. * * @param string $location Location id * @return bool */ function adsensei_has_ad( $location ) { global $adsensei_options; $result = false; $location_settings = adsensei_get_ad_location_settings( $location ); if ( $location_settings ) { $result = true; } if ( ! adsensei_ad_is_allowed() || adsensei_ad_reach_max_count() ) { $result = false; } /** * Filter whether an ad is assigned to the specified location. */ return apply_filters( 'adsensei_has_ad', $result, $location ); } /** * Display a custom ad * * @param array $args Displaying options * @return string|void Ad code or none if echo set to true */ function adsensei_ad( $args ) { global $post; $defaults = array( 'location' => '', 'echo' => true, ); $args = wp_parse_args( $args, $defaults ); $code = ''; // All ads are deactivated via post meta settings if( adsensei_check_meta_setting( 'NoAds' ) === '1' ){ return false; } global $adsensei_options,$adsensei_mode; $wp_adsensei_custom_ad_id = array(); $loc = 'api-'.$args['location']; $loc_index = $loc; foreach ($adsensei_options['ads'] as $key => $value) { if(isset($value['position']) && strpos($value['position'],$loc_index) > -1){ $wp_adsensei_custom_ad_id[$loc_index] = $key ; } } if ( adsensei_has_ad( $args['location'] ) ) { adsensei_set_ad_count_custom(); // increase amount of Custom ads // $location_settings = adsensei_get_ad_location_settings( $args['location'] ); $location_settings['ad']=''; if(isset($wp_adsensei_custom_ad_id["api-".$args['location'].""])) { $location_settings['ad'] = $wp_adsensei_custom_ad_id["api-".$args['location'].""]; if($location_settings['ad']) { $modify = str_replace("ad","",$location_settings['ad']); $location_settings['ad'] = $modify; $code .= "\n".''."\n"; $code .= '