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 |