__('Shows one of your AdGhost ad units.', 'adghost-lite'), 'customize_selective_refresh' => true] ); } public function widget($args, $instance) { $code = (string) ($instance['unit'] ?? ''); $unit = null; foreach (AdGhost_Helper::units() as $candidate) { if (AdGhost_Helper::gam_code($candidate) === $code) { $unit = $candidate; break; } } if ($unit === null || !AdGhost_Helper::ads_live() || AdGhost_Targeting::page_exclusion_reason() !== null || AdGhost_Targeting::unit_exclusion_reason($unit) !== null) { return; } if (class_exists('AdGhost_IVT_Manager') && !AdGhost_IVT_Manager::ads_allowed()) { return; } $before = (string) $args['before_widget']; if (!empty($instance['sticky'])) { $offset = min(400, absint($instance['offset'] ?? 16)); $style = '--adghost-sticky-top:' . $offset . 'px;'; $before = preg_match('/^\s*<[a-z0-9]+[^>]*\bclass="/i', $before) ? preg_replace('/\bclass="/i', 'style="' . esc_attr($style) . '" class="adghost-sticky-widget ', $before, 1) : '
'); } echo wp_kses_post($before); if (!empty($instance['title'])) { echo wp_kses_post($args['before_title']) . esc_html($instance['title']) . wp_kses_post($args['after_title']); } echo wp_kses(AdGhost_Ad_Container::render($unit, 'widget', self::$count++), AdGhost_Helper::allowed_ads_html()); echo wp_kses_post($args['after_widget']); } public function form($instance) { $title = (string) ($instance['title'] ?? ''); $code = (string) ($instance['unit'] ?? ''); $sticky = !empty($instance['sticky']); $offset = absint($instance['offset'] ?? 16); $units = AdGhost_Helper::units(true); ?>
>