__('Watch a short ad to unlock', 'adghost-lite'), 'message' => __('This content is free — unlock it by watching a short ad.', 'adghost-lite'), ], $atts, 'adghost_rewarded'); $inner = do_shortcode((string) $content); $has_reward = false; foreach (AdGhost_Helper::units() as $unit) { if (($unit['type'] ?? '') === 'reward') { $has_reward = true; break; } } if (!$has_reward || !get_option('adghost_is_active', false) || is_feed() || (class_exists('AdGhost_AMP') && AdGhost_AMP::is_amp()) || (class_exists('AdGhost_Targeting') && AdGhost_Targeting::page_exclusion_reason() !== null) || (class_exists('AdGhost_IVT_Manager') && !AdGhost_IVT_Manager::ads_allowed())) { return $inner; } $id = 'adghost-reward-' . (++self::$reward_counter); $fallback = wp_get_inline_script_tag('(function(){function o(){var g=document.querySelector(\'[data-adghost-reward="#' . esc_js($id) . '"]\');' . 'if(!g||g.getAttribute("data-agh-rg"))return;var c=document.getElementById(' . wp_json_encode($id) . ');' . 'if(c){c.hidden=false;}g.style.display="none";}' . 'function w(){setTimeout(o,6000);}document.readyState==="complete"?w():window.addEventListener("load",w);})();'); return $fallback . sprintf( '

%2$s

' . '
' . '', esc_attr($id), esc_html($atts['message']), esc_html($atts['button']), $inner ); } public function render_shortcode($atts) { $atts = shortcode_atts([ 'id' => '', 'slot' => '', 'sizes' => '', 'position' => 'manual', 'class' => '', ], $atts, 'adghost'); if ($atts['slot'] === '' && $atts['id'] !== '') { $atts['slot'] = $atts['id']; } $unit = null; foreach (AdGhost_Helper::units(true) as $candidate) { if (is_array($candidate) && $atts['slot'] !== '' && (($candidate['id'] ?? '') === $atts['slot'] || AdGhost_Helper::gam_code($candidate) === AdGhost_Helper::sanitize_gam_code($atts['slot']))) { $unit = $candidate; break; } } if ($unit && empty($unit['enabled'])) { return ''; } if ($atts['sizes'] === '') { $atts['sizes'] = $unit ? str_replace(';', ',', (string) ($unit['sizes'] ?? '300x250')) : '300x250'; } if (empty($atts['slot'])) { if (current_user_can('manage_options')) { return '

[AdGhost] Missing required "id" attribute

'; } return ''; } $network_code = get_option('adghost_network_code', ''); if (empty($network_code)) { if (current_user_can('manage_options')) { return '

[AdGhost] Network Code not configured

'; } return ''; } if (!AdGhost_Helper::ads_live() || is_feed()) { return ''; } if (class_exists('AdGhost_Targeting') && AdGhost_Targeting::page_exclusion_reason() !== null) { return ''; } if (class_exists('AdGhost_IVT_Manager') && !AdGhost_IVT_Manager::ads_allowed()) { return ''; } if ($unit) { if (class_exists('AdGhost_Targeting') && AdGhost_Targeting::unit_exclusion_reason($unit) !== null) { return ''; } if ($atts['class'] === '' && $atts['sizes'] === str_replace(';', ',', (string) ($unit['sizes'] ?? '300x250'))) { return AdGhost_Ad_Container::render($unit, 'shortcode', self::$slot_counter++); } } if (class_exists('AdGhost_AMP') && AdGhost_AMP::is_amp()) { $amp_unit = $unit ?: ['id' => $atts['slot'], 'name' => $atts['slot']]; $amp_unit['sizes'] = $atts['sizes']; return AdGhost_AMP::ad(AdGhost_Helper::normalize_unit($amp_unit), 'shortcode', $atts['sizes']); } self::$slot_counter++; $slot_id = 'adghost-manual-' . self::$slot_counter . '-' . sanitize_title($atts['slot']); $gam_code = $unit ? AdGhost_Helper::gam_code($unit) : AdGhost_Helper::sanitize_gam_code($atts['slot']); if (class_exists('AdGhost_Placement_State')) { if (AdGhost_Placement_State::is_block_inserted($slot_id, 'shortcode')) { return ''; } AdGhost_Placement_State::mark_block_inserted($slot_id, 'shortcode', [ 'slot' => $atts['slot'], 'sizes' => $atts['sizes'], ]); } $sizes_array = array_map('trim', explode(',', $atts['sizes'])); $data_sizes = esc_attr(implode(',', $sizes_array)); $classes = ['adghost-ad-container', 'adghost-shortcode', 'adghost-' . sanitize_html_class($atts['position'])]; if (!empty($atts['class'])) { $classes[] = $atts['class']; } $min_height = AdGhost_Ad_Container::reserved_height($atts['sizes']); $output = sprintf( '
', esc_attr(implode(' ', $classes)), esc_attr($slot_id), esc_attr($slot_id), esc_attr($gam_code), $data_sizes, $min_height > 0 ? ' style="min-height:' . (int) $min_height . 'px;"' : '' ); return $output; } public static function get_usage_instructions() { return '

Shortcode Usage

\n' . '

Use the [adghost] shortcode to manually place ads anywhere in your content.

\n' . '
Basic Usage
\n' . '
[adghost id="your_gam_ad_unit_code"]
\n' . '
With Custom Sizes
\n' . '
[adghost id="sidebar_1" sizes="300x250,336x280"]
\n' . '
With CSS Class
\n' . '
[adghost id="header_1" sizes="728x90" class="my-custom-class"]
\n' . '
Attributes
\n' . '\n'; } }