PluginProbe ʕ •ᴥ•ʔ
Advanced Ads – Ad Manager & AdSense / 1.8.25
Advanced Ads – Ad Manager & AdSense v1.8.25
2.0.23 2.0.22 2.0.21 1.38.0 1.39.0 1.39.1 1.39.2 1.39.3 1.39.4 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.40.0 1.40.1 1.40.2 1.41.0 1.42.0 1.42.1 1.42.2 1.43.0 1.44.0 1.44.1 1.45.0 1.45.1 1.46.0 1.47.0 1.47.1 1.47.2 1.47.3 1.47.4 1.47.5 1.48.0 1.48.1 1.49.0 1.5.0 1.5.0.1 1.5.1 1.5.2 1.5.2.1 1.5.4 1.5.4.1 1.5.5 1.50.0 1.51.0 1.51.1 1.51.2 1.51.3 1.52.0 1.52.1 1.52.2 1.52.3 1.52.4 1.53.0 1.53.1 1.53.2 1.54.0 1.54.1 1.55.0 1.56.0 1.56.1 1.56.2 1.56.3 1.56.4 1.6 1.6.1 1.6.10 1.6.10.1 1.6.10.2 1.6.11 1.6.11.1 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.17.1 1.6.17.2 1.6.2 1.6.2.1 1.6.3 1.6.4 1.6.4.1 1.6.5 1.6.6 1.6.6.1 1.6.7 1.6.7.1 1.6.8 1.6.8.1 1.6.8.2 1.6.8.3 1.6.9 1.6.9.1 1.6.9.2 1.6.9.3 1.6.9.4 1.7 1.7.0.1 1.7.0.2 1.7.0.3 1.7.1 1.7.1.1 1.7.1.2 1.7.1.3 1.7.1.4 1.7.1.5 1.7.10 trunk 1.7.11 1.0.1 1.7.12 1.0.2 1.7.13 1.0.3 1.7.14 1.1.0 1.7.15 1.1.1 1.7.16 1.1.2 1.7.17 1.1.3 1.7.18 1.10 1.7.19 1.10.1 1.7.2 1.10.10 1.7.2.1 1.10.11 1.7.20 1.10.12 1.7.21 1.10.2 1.7.22 1.10.3 1.7.23 1.10.4 1.7.24 1.10.5 1.7.25 1.10.6 1.7.3 1.10.7 1.7.4 1.10.8 1.7.4.1 1.10.9 1.7.4.2 1.11 1.7.4.3 1.11.1 1.7.4.4 1.11.2 1.7.4.5 1.12 1.7.5 1.13 1.7.5.1 1.13.1 1.7.6 1.13.2 1.7.7 1.13.3 1.7.8 1.13.4 1.7.9 1.13.5 1.7.9.1 1.13.6 1.7.9.2 1.13.7 1.7.9.3 1.13.8 1.8 1.14 1.8.1 1.14.1 1.8.10 1.14.10 1.8.11 1.14.11 1.8.12 1.14.2 1.8.13 1.14.3 1.8.14 1.14.4 1.8.15 1.14.5 1.8.16 1.14.6 1.8.17 1.14.7 1.8.18 1.14.8 1.8.19 1.14.9 1.8.2 1.15 1.8.20 1.16 1.8.21 1.16.1 1.8.22 1.17 1.8.23 1.17.1 1.8.24 1.17.10 1.8.25 1.17.10-rc.1 1.8.26 1.17.11 1.8.27 1.17.12 1.8.28 1.17.12-rc.1 1.8.29 1.17.2 1.8.3 1.17.3 1.8.30 1.17.4 1.8.4 1.17.5 1.8.5 1.17.6 1.8.6 1.17.7 1.8.7 1.17.8 1.8.8 1.17.9 1.8.9 1.17.9-beta.1 1.9 1.18.0 2.0.0 1.19.0 2.0.1 1.19.1 2.0.10 1.2 2.0.11 1.2.1 2.0.12 1.2.2 2.0.13 1.2.3 2.0.14 1.2.4 2.0.15 1.2.5 2.0.16 1.2.6 2.0.17 1.2.7 2.0.18 1.20.0 2.0.19 1.20.0-rc.1 2.0.2 1.20.0-rc.2 2.0.20 1.20.1 2.0.3 1.20.2 2.0.4 1.20.3 2.0.5 1.21.0 2.0.6 1.21.1 2.0.7 1.22.0 2.0.8 1.22.1 2.0.9 1.22.2 1.23.0 1.23.1 1.23.2 1.24.0 1.24.1 1.24.2 1.25.0 1.25.1 1.26.0 1.27.0 1.28.0 1.29.0 1.29.1 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.14 1.3.15 1.3.16 1.3.17 1.3.18 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.30.0 1.30.1 1.30.2 1.30.2-rc.1 1.30.3 1.30.4 1.30.4-rc.1 1.30.5 1.31.0 1.31.1 1.32.0 1.32.0-rc.1 1.33.0 1.33.1 1.33.2 1.34.0 1.35.0 1.35.1 1.36.0 1.36.1 1.36.2 1.36.3 1.37.0 1.37.1 1.37.2
advanced-ads / classes / frontend_checks.php
advanced-ads / classes Last commit date
EDD_SL_Plugin_Updater.php 8 years ago ad-ajax.php 9 years ago ad-debug.php 8 years ago ad-model.php 9 years ago ad-select.php 9 years ago ad.php 8 years ago ad_ajax_callbacks.php 8 years ago ad_group.php 8 years ago ad_placements.php 8 years ago ad_type_abstract.php 8 years ago ad_type_content.php 8 years ago ad_type_dummy.php 8 years ago ad_type_group.php 8 years ago ad_type_image.php 8 years ago ad_type_plain.php 8 years ago checks.php 8 years ago display-conditions.php 8 years ago filesystem.php 8 years ago frontend_checks.php 8 years ago plugin.php 8 years ago upgrades.php 9 years ago utils.php 8 years ago visitor-conditions.php 8 years ago widget.php 8 years ago
frontend_checks.php
536 lines
1 <?php
2
3 class Advanced_Ads_Frontend_Checks {
4 /**
5 * True if 'the_content' was invoked, false otherwise.
6 *
7 * @var bool
8 */
9 private $did_the_content = false;
10
11 public function __construct() {
12 add_action( 'init', array( $this, 'init' ) );
13 }
14
15 public function init() {
16 $enabled = false;
17
18 if ( ! is_admin()
19 && is_admin_bar_showing()
20 && current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ) )
21 ) {
22 add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu' ), 1000 );
23 add_filter( 'the_content', array( $this, 'set_did_the_content' ) );
24 add_filter( 'wp_footer', array( $this, 'footer_checks' ), -101 );
25 add_filter( 'advanced-ads-ad-select-args', array( $this, 'ad_select_args_callback' ) );
26 $enabled = true;
27 }
28
29 if ( $enabled || ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
30 add_filter( 'advanced-ads-ad-output', array( $this, 'after_ad_output' ), 10, 2 );
31 }
32 }
33
34 /**
35 * Notify ads loaded with AJAX.
36 *
37 * @param array $args
38 * @return array $args
39 */
40 public function ad_select_args_callback( $args ) {
41 $args['frontend-check'] = true;
42 return $args;
43 }
44
45 /**
46 * List current ad situation on the page in the admin-bar.
47 *
48 * @param obj $wp_admin_bar WP_Admin_Bar
49 */
50 public function add_admin_bar_menu( $wp_admin_bar ) {
51 global $wp_the_query, $post, $wp_scripts;
52
53 $options = Advanced_Ads_Plugin::get_instance()->options();
54
55 // load AdSense related options
56 $adsense_options = Advanced_Ads_AdSense_Data::get_instance()->get_options();
57
58 // check if jQuery is loaded in the header
59 // Hidden, will be shown using js.
60 // message removed after we fixed all issues we know of
61 /*$wp_admin_bar->add_node( array(
62 'parent' => 'advanced_ads_ad_health',
63 'id' => 'advanced_ads_ad_health_jquery',
64 'title' => __( 'jQuery not in header', 'advanced-ads' ),
65 'href' => ADVADS_URL . 'manual/common-issues#frontend-issues-javascript',
66 'meta' => array(
67 'class' => 'hidden advanced_ads_ad_health_warning',
68 'target' => '_blank'
69 )
70 ) );*/
71
72 // check if AdSense loads Auto Ads ads
73 // Hidden, will be shown using js.
74 if( ! isset( $adsense_options['violation-warnings-disable'] ) ) {
75 $nodes[] = array( 'type' => 2, 'data' => array(
76 'parent' => 'advanced_ads_ad_health',
77 'id' => 'advanced_ads_autoads_displayed',
78 'title' => __( 'Random AdSense ads', 'advanced-ads' ),
79 'href' => ADVADS_URL . 'adsense-in-random-positions-auto-ads/#utm_source=advancedads&utm_medium=link&utm_campaign=frontend-autoads-ads',
80 'meta' => array(
81 'class' => 'hidden advanced_ads_ad_health_warning',
82 'target' => '_blank'
83 )
84 ) );
85 }
86
87 // check if current user was identified as a bot
88 if( Advanced_Ads::get_instance()->is_bot() ) {
89 $nodes[] = array( 'type' => 1, 'data' => array(
90 'parent' => 'advanced_ads_ad_health',
91 'id' => 'advanced_ads_user_is_bot',
92 'title' => __( 'You look like a bot', 'advanced-ads' ),
93 'href' => ADVADS_URL . 'manual/ad-health/#look-like-bot',
94 'meta' => array(
95 'class' => 'advanced_ads_ad_health_warning',
96 'target' => '_blank'
97 )
98 ) );
99 }
100
101 // check if an ad blocker is enabled
102 // Hidden, will be shown using js.
103 $nodes[] = array( 'type' => 2, 'data' => array(
104 'parent' => 'advanced_ads_ad_health',
105 'id' => 'advanced_ads_ad_health_adblocker_enabled',
106 'title' => __( 'Ad blocker enabled', 'advanced-ads' ),
107 // 'href' => 'https://wpadvancedads.com/support',
108 'meta' => array(
109 'class' => 'hidden advanced_ads_ad_health_warning',
110 'target' => '_blank'
111 )
112 ) );
113
114 if ( $wp_the_query->is_singular() ) {
115 if ( ! $this->did_the_content ) {
116 $placements = Advanced_Ads::get_ad_placements_array();
117 $placement_types = Advanced_Ads_Placements::get_placement_types();
118 // Find a placement that depends on 'the_content' filter.
119 foreach ( $placements as $placement ) {
120 if ( isset ( $placement['type'] )
121 && ! empty( $placement_types[ $placement['type'] ]['options']['uses_the_content'] ) ) {
122 $nodes[] = array( 'type' => 1, 'data' => array(
123 'parent' => 'advanced_ads_ad_health',
124 'id' => 'advanced_ads_ad_health_the_content_not_invoked',
125 'title' => sprintf( __( '<em>%s</em> filter does not exist', 'advanced-ads' ), 'the_content' ),
126 'href' => 'https://wpadvancedads.com/manual/ads-not-showing-up/#frontend-issues-the-content-filter',
127 'meta' => array(
128 'class' => 'advanced_ads_ad_health_warning',
129 'target' => '_blank'
130 )
131 ) );
132 break;
133 }
134 }
135 }
136
137 if ( ! empty( $post->ID ) ) {
138 $ad_settings = get_post_meta( $post->ID, '_advads_ad_settings', true );
139
140 if ( ! empty( $ad_settings['disable_ads'] ) ) {
141 $nodes[] = array( 'type' => 1, 'data' => array(
142 'parent' => 'advanced_ads_ad_health',
143 'id' => 'advanced_ads_ad_health_disabled_on_page',
144 'title' => __( 'Ads are disabled on this page', 'advanced-ads' ),
145 'href' => get_edit_post_link( $post->ID ) . '#advads-ad-settings',
146 'meta' => array(
147 'class' => 'advanced_ads_ad_health_warning',
148 'target' => '_blank'
149 )
150 ) );
151 }
152
153 if ( ! empty( $ad_settings['disable_the_content'] ) ) {
154 $nodes[] = array( 'type' => 1, 'data' => array(
155 'parent' => 'advanced_ads_ad_health',
156 'id' => 'advanced_ads_ad_health_disabled_in_content',
157 'title' => __( 'Ads are disabled in the content of this page', 'advanced-ads' ),
158 'href' => get_edit_post_link( $post->ID ) . '#advads-ad-settings',
159 'meta' => array(
160 'class' => 'advanced_ads_ad_health_warning',
161 'target' => '_blank'
162 )
163 ) );
164 }
165 } else {
166 $nodes[] = array( 'type' => 1, 'data' => array(
167 'parent' => 'advanced_ads_ad_health',
168 'id' => 'advanced_ads_ad_health_post_zero',
169 'title' => __( 'the current post ID is 0 ', 'advanced-ads' ),
170 'href' => ADVADS_URL . 'manual/ad-health/#post-id-0',
171 'meta' => array(
172 'class' => 'advanced_ads_ad_health_warning',
173 'target' => '_blank'
174 )
175 ) );
176 }
177 }
178
179 if ( ! empty( $options['disabled-ads']['all'] ) ) {
180 $nodes[] = array( 'type' => 1, 'data' => array(
181 'parent' => 'advanced_ads_ad_health',
182 'id' => 'advanced_ads_ad_health_no_all',
183 'title' => __( 'Ads are disabled on all pages', 'advanced-ads' ),
184 'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
185 'meta' => array(
186 'class' => 'advanced_ads_ad_health_warning',
187 'target' => '_blank'
188 )
189 ) );
190 }
191
192 if ( $wp_the_query->is_404() && ! empty( $options['disabled-ads']['404'] ) ) {
193 $nodes[] = array( 1, array(
194 'parent' => 'advanced_ads_ad_health',
195 'id' => 'advanced_ads_ad_health_no_404',
196 'title' => __( 'Ads are disabled on 404 pages', 'advanced-ads' ),
197 'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
198 'meta' => array(
199 'class' => 'advanced_ads_ad_health_warning',
200 'target' => '_blank'
201 )
202 ) );
203 }
204
205 if ( ! $wp_the_query->is_singular() && ! empty( $options['disabled-ads']['archives'] ) ){
206 $nodes[] = array( 'type' => 1, 'data' => array(
207 'parent' => 'advanced_ads_ad_health',
208 'id' => 'advanced_ads_ad_health_no_archive',
209 'title' => __( 'Ads are disabled on non singular pages', 'advanced-ads' ),
210 'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
211 'meta' => array(
212 'class' => 'advanced_ads_ad_health_warning',
213 'target' => '_blank'
214 )
215 ) );
216 }
217
218 if ( ! extension_loaded( 'dom' ) ) {
219 $nodes[] = array( 'type' => 1, 'data' => array(
220 'parent' => 'advanced_ads_ad_health',
221 'id' => 'advanced_ads_ad_health_no_dom_document',
222 'title' => sprintf( __( 'The %s extension(s) is not loaded', 'advanced-ads' ), 'dom' ),
223 'href' => 'http://php.net/manual/en/book.dom.php',
224 'meta' => array(
225 'class' => 'advanced_ads_ad_health_warning',
226 'target' => '_blank'
227 )
228 ) );
229 }
230
231 $nodes[] = array( 'type' => 2, 'data' => array(
232 'parent' => 'advanced_ads_ad_health',
233 'id' => 'advanced_ads_ad_health_has_http',
234 'title' => sprintf( '%s %s',
235 __( 'Your website is using HTTPS, but the ad code contains HTTP and might not work.', 'advanced-ads' ),
236 sprintf( __( 'Ad IDs: %s', 'advanced-ads' ), '<i></i>' )
237 ),
238 'href' => 'https://wpadvancedads.com/manual/ad-health/#https-ads',
239 'meta' => array(
240 'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_has_http',
241 'target' => '_blank'
242 )
243 ) );
244
245 // warn if an AdSense ad seems to be hidden
246 if( ! isset( $adsense_options['violation-warnings-disable'] ) ) {
247 $nodes[] = array( 'type' => 2, 'data' => array(
248 'parent' => 'advanced_ads_ad_health',
249 'id' => 'advanced_ads_ad_health_hidden_adsense',
250 'title' => sprintf( '%s: %s. %s',
251 __( 'AdSense violation', 'advanced-ads' ),
252 __( 'Ad is hidden', 'advanced-ads' ),
253 sprintf( __( 'IDs: %s', 'advanced-ads' ), '<i></i>' )
254 ),
255 'href' => 'https://wpadvancedads.com/manual/ad-health/#adsense-hidden&utm_source=advanced-ads&utm_medium=link&utm_campaign=frontend-adsense-hidden',
256 'meta' => array(
257 'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_hidden_adsense',
258 'target' => '_blank'
259 )
260 ) );
261 }
262
263 $nodes[] = array( 'type' => 3, 'data' => array(
264 'parent' => 'advanced_ads_ad_health',
265 'id' => 'advanced_ads_ad_health_debug_dfp',
266 'title' => __( 'debug DFP ads', 'advanced-ads' ),
267 'href' => esc_url( add_query_arg( 'googfc', '' ) ),
268 'meta' => array(
269 'class' => 'hidden advanced_ads_ad_health_debug_dfp_link',
270 'target' => '_blank',
271 )
272 ) );
273
274 $nodes[] = array( 'type' => 3, 'data' => array(
275 'parent' => 'advanced_ads_ad_health',
276 'id' => 'advanced_ads_ad_health_highlight_ads',
277 'title' => sprintf( '<label style="color: inherit;"><input id="advanced_ads_highlight_ads_checkbox" type="checkbox"> %s</label>', __( 'highlight ads', 'advanced-ads' ) )
278 ) );
279
280 /**
281 * Add new node.
282 *
283 * @param array $node An array that contains:
284 * 'type' => 1 - warning, 2 - hidden warning that will be shown using JS, 3 - info message
285 * 'data': @see WP_Admin_Bar->add_node
286 * @param obj $wp_admin_bar
287 */
288 $nodes = apply_filters( 'advanced-ads-ad-health-nodes', $nodes );
289 usort( $nodes, array( $this, 'sort_nodes' ) );
290
291 $wp_admin_bar->add_node( array(
292 'id' => 'advanced_ads_ad_health',
293 'title' => __( 'Ad Health', 'advanced-ads' ),
294 ) );
295
296 $display_fine = true;
297
298 foreach ( $nodes as $node ) {
299 if ( ! isset( $node['type'] ) || ! isset( $node['data'] ) ) { continue; }
300 if ( $node['type'] === 1 ) { $display_fine = false; }
301 $wp_admin_bar->add_node( $node['data'] );
302 }
303
304 if ( $display_fine ) {
305 $wp_admin_bar->add_node( array(
306 'parent' => 'advanced_ads_ad_health',
307 'id' => 'advanced_ads_ad_health_fine',
308 'title' => __( 'Everything is fine', 'advanced-ads' ),
309 'href' => false,
310 'meta' => array(
311 'target' => '_blank',
312 )
313 ) );
314 }
315
316 }
317
318 /**
319 * Sort nodes.
320 */
321 function sort_nodes( $a, $b ) {
322 if ( ! isset( $a['type'] ) || ! isset( $b['type'] ) ) {
323 return 0;
324 }
325 if ( $a['type'] == $b['type'] ) {
326 return 0;
327 }
328 return ( $a['type'] < $b['type'] ) ? -1 : 1;
329 }
330
331 /**
332 * Set variable to 'true' when 'the_content' filter is invoked.
333 *
334 * @param string $content
335 * @return string $content
336 */
337 public function set_did_the_content( $content ) {
338 if ( ! $this->did_the_content ) {
339 $this->did_the_content = true;
340 }
341 return $content;
342 }
343
344 /**
345 * Check conditions and display warning.
346 * Conditions:
347 * AdBlocker enabled,
348 * jQuery is included in header
349 * AdSense Quick Start ads are running
350 */
351 public function footer_checks() {
352 $adsense_options = Advanced_Ads_AdSense_Data::get_instance()->get_options();
353 ob_start();
354 ?><!-- Advanced Ads: <?php _e( 'the following code is used for automatic error detection and only visible to admins', 'advanced-ads' ); ?>-->
355 <style>.hidden { display: none; } .advads-adminbar-is-warnings { background: #a54811 ! important; color: #fff !important; }
356 #wp-admin-bar-advanced_ads_ad_health-default a:after { content: "\25BA"; margin-left: .5em; font-size: smaller; }
357 .advanced-ads-highlight-ads { outline:4px solid blue !important; }</style>
358 <script type="text/javascript" src="<?php echo ADVADS_BASE_URL . 'admin/assets/js/advertisement.js' ?>"></script>
359 <script>
360 var advanced_ads_frontend_checks = {
361 showCount: function() {
362 try {
363 // Count only warnings that have the 'advanced_ads_ad_health_warning' class.
364 var warning_count = document.querySelectorAll( '.advanced_ads_ad_health_warning:not(.hidden)' ).length;
365 var fine_item = document.getElementById( 'wp-admin-bar-advanced_ads_ad_health_fine' );
366 } catch ( e ) { return; }
367
368 if ( warning_count ) {
369 var header = document.querySelector( '#wp-admin-bar-advanced_ads_ad_health > div' );
370
371 if ( fine_item ) {
372 // Hide 'fine' item.
373 fine_item.className += ' hidden';
374 }
375
376 if ( header ) {
377 header.innerHTML = header.innerHTML.replace(/ <i>(.*?)<\/i>/, '') + ' <i>(' + warning_count + ')</i>';
378 header.className += ' advads-adminbar-is-warnings';
379 }
380 }
381 }
382 };
383
384 (function(d, w) {
385 // var not_head_jQuery = typeof jQuery === 'undefined';
386
387 var addEvent = function( obj, type, fn ) {
388 if ( obj.addEventListener )
389 obj.addEventListener( type, fn, false );
390 else if ( obj.attachEvent )
391 obj.attachEvent( 'on' + type, function() { return fn.call( obj, window.event ); } );
392 };
393
394 function highlight_ads() {
395 try {
396 var ad_wrappers = document.querySelectorAll('div[id^="<?php echo Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();?>"]')
397 } catch ( e ) { return; }
398 for ( i = 0; i < ad_wrappers.length; i++ ) {
399 if ( this.checked ) {
400 ad_wrappers[i].className += ' advanced-ads-highlight-ads';
401 } else {
402 ad_wrappers[i].className = ad_wrappers[i].className.replace( 'advanced-ads-highlight-ads', '' );
403 }
404 }
405 }
406
407 advanced_ads_ready( function() {
408 var adblock_item = d.getElementById( 'wp-admin-bar-advanced_ads_ad_health_adblocker_enabled' );
409 // jQuery_item = d.getElementById( 'wp-admin-bar-advanced_ads_ad_health_jquery' ),
410
411 var highlight_checkbox = d.getElementById( 'advanced_ads_highlight_ads_checkbox' );
412 if ( highlight_checkbox ) {
413 addEvent( highlight_checkbox, 'change', highlight_ads );
414 }
415
416 if ( adblock_item && typeof advanced_ads_adblocker_test === 'undefined' ) {
417 // show hidden item
418 adblock_item.className = adblock_item.className.replace( /hidden/, '' );
419 }
420
421 /* if ( jQuery_item && not_head_jQuery ) {
422 // show hidden item
423 jQuery_item.className = jQuery_item.className.replace( /hidden/, '' );
424 }*/
425
426 advanced_ads_frontend_checks.showCount();
427 });
428
429 <?php if( ! isset( $adsense_options['violation-warnings-disable'] ) ) : ?>
430 // show warning if AdSense ad is hidden
431 setTimeout( function(){
432 advanced_ads_ready( advads_highlight_hidden_adsense );
433 }, 2000 );
434 function advads_highlight_hidden_adsense(){
435 if ( window.jQuery ) {
436 var advads_ad_health_check_adsense_hidden_ids = [];
437 jQuery('ins.adsbygoogle').each( function(){
438 if( ! jQuery( this ).parent().is(':visible') ){
439 advads_ad_health_check_adsense_hidden_ids.push( this.dataset.adSlot );
440 }
441 });
442 if( advads_ad_health_check_adsense_hidden_ids.length ){
443 var advads_has_hidden_adsense_link = document.querySelector( '.advanced_ads_ad_health_hidden_adsense' );
444 if ( advads_has_hidden_adsense_link ) {
445 advads_has_hidden_adsense_link.className = advads_has_hidden_adsense_link.className.replace( 'hidden', '' );
446 advads_has_hidden_adsense_link.innerHTML = advads_has_hidden_adsense_link.innerHTML.replace( /(<i>)(.*?)(<\/i>)/, function( match, p1, p2, p3 ) {
447 var ad_id = advads_ad_health_check_adsense_hidden_ids.join( ', ');
448 p2 = ( p2 ) ? p2.split( ', ' ) : [];
449 if ( p2.indexOf( ad_id ) === -1 ) p2.push( ad_id );
450 return p1 + p2.join( ', ' ) + p3;
451 } );
452 advanced_ads_frontend_checks.showCount();
453 }
454 }
455 }
456 };
457
458 // highlight AdSense Auto Ads ads 3 seconds after site loaded
459 setTimeout( function(){
460 advanced_ads_ready( advads_highlight_adsense_autoads )
461 }, 3000 );
462 function advads_highlight_adsense_autoads(){
463 if ( ! window.jQuery ) {
464 window.console && window.console.log( 'Advanced Ads: jQuery not found. Some Ad Health warnings will not be shown' );
465 return;
466 }
467 var autoads_ads = jQuery(document).find('.google-auto-placed');
468 jQuery( '<p class="advads-autoads-hint" style="background-color:#0085ba;color:#fff;font-size:0.8em;padding:5px;"><?php
469 printf(__( 'This ad was automatically placed here by AdSense. <a href="%s" target="_blank" style="color:#fff;border-color:#fff;">Click here to learn more</a>.', 'advanced-ads' ), ADVADS_URL . 'adsense-in-random-positions-auto-ads/#utm_source=advanced-ads&utm_medium=link&utm_campaign=frontend-autoads-ads' );
470 ?></p>' ).prependTo( autoads_ads );
471 // show Auto Ads warning in Adhealth Bar if relevant
472 if( autoads_ads.length ){
473 var advads_autoads_link = document.querySelector( '#wp-admin-bar-advanced_ads_autoads_displayed.hidden' );
474 console.log( advads_autoads_link );
475 if ( advads_autoads_link ) {
476 advads_autoads_link.className = advads_autoads_link.className.replace( 'hidden', '' );
477 }
478 advanced_ads_frontend_checks.showCount();
479 }
480
481 }
482 <?php endif; ?>
483 })(document, window);
484 </script>
485 <?php echo Advanced_Ads_Utils::get_inline_asset( ob_get_clean() );
486 }
487
488 /**
489 * Inject JS after ad content.
490 *
491 * @param str $content ad content
492 * @param obj $ad Advanced_Ads_Ad
493 * @return str $content ad content
494 */
495 public function after_ad_output( $content = '', Advanced_Ads_Ad $ad ) {
496 if ( ! isset( $ad->args['frontend-check'] ) ) { return $content; }
497
498 // Allow DFP debugging by showing a link that points to the current URL with the 'googfc' parameter.
499 if ( $ad->type === 'plain' && preg_match( '/gpt\.js/', $content ) ) {
500 ob_start(); ?>
501 <!--noptimize--><script>advanced_ads_ready( function() {
502 var advads_dfp_link = document.querySelector( '.advanced_ads_ad_health_debug_dfp_link.hidden' );
503 if ( advads_dfp_link ) {
504 advads_dfp_link.className = advads_dfp_link.className.replace( 'hidden', '' );
505 advanced_ads_frontend_checks.showCount();
506 }
507 });</script><!--/noptimize-->
508 <?php
509 $content .= Advanced_Ads_Utils::get_inline_asset( ob_get_clean() );
510 }
511
512
513 if ( Advanced_Ads_Ad_Debug::is_https_and_http( $ad ) ) {
514 ob_start(); ?>
515 <!--noptimize--><script>advanced_ads_ready( function() {
516 var advads_has_http_link = document.querySelector( '.advanced_ads_ad_health_has_http' );
517 if ( advads_has_http_link ) {
518 advads_has_http_link.className = advads_has_http_link.className.replace( 'hidden', '' );
519 advads_has_http_link.innerHTML = advads_has_http_link.innerHTML.replace( /(<i>)(.*?)(<\/i>)/, function( match, p1, p2, p3 ) {
520 var ad_id = '<?php echo $ad->id; ?>';
521 p2 = ( p2 ) ? p2.split( ', ' ) : [];
522 if ( p2.indexOf( ad_id ) === -1 ) p2.push( ad_id );
523 return p1 + p2.join( ', ' ) + p3;
524 } );
525 advanced_ads_frontend_checks.showCount();
526 }
527 });</script><!--/noptimize-->
528 <?php
529 $content .= Advanced_Ads_Utils::get_inline_asset( ob_get_clean() );
530 }
531
532 return $content;
533 }
534
535 }
536