AdSense Plugin WP QUADS - Version 2.0.8.3

Version Description

(18th June 2020)= * Fix: Fixed Lazy loading issue. #188

Download this release

Release Info

Developer wpquads
Plugin Icon 128x128 AdSense Plugin WP QUADS
Version 2.0.8.3
Comparing to
See all releases

Code changes from version 2.0.8.1 to 2.0.8.3

includes/render-ad-functions.php CHANGED
@@ -319,9 +319,8 @@ function quads_render_google_async_new( $id ) {
319
  * @param int $id
320
  * @return html
321
  */
322
- $loaded_lazy_load = '';
323
  function quads_render_google_async( $id ) {
324
- global $quads_options,$loaded_lazy_load;
325
  // Default ad sizes - Option: Auto
326
  $default_ad_sizes[$id] = array(
327
  'desktop_width' => '300',
@@ -366,52 +365,24 @@ function quads_render_google_async( $id ) {
366
  $default_ad_sizes[$id]['phone_height'] = $ad_size_parts[1];
367
  }
368
 
369
- $id_name = "quads-".esc_attr($id)."-place";
370
  $html = "\n <!-- " . QUADS_NAME . " v." . QUADS_VERSION . " Content AdSense async --> \n\n";
371
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
372
- $html .= '<div id="'.esc_attr($id_name).'"></div>';
373
- }
374
  //google async script
375
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
376
- if($loaded_lazy_load==''){
377
- $loaded_lazy_load = 'yes';
378
- $html .= quads_load_loading_script();
379
- }
380
- }
381
  $html .= "\n".'<script type="text/javascript" >' . "\n";
382
  $html .= 'var quads_screen_width = document.body.clientWidth;' . "\n";
383
 
384
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
385
- $html .= quads_render_desktop_js( $id, $default_ad_sizes,$id_name );
386
- $html .= quads_render_tablet_landscape_js( $id, $default_ad_sizes,$id_name );
387
- $html .= quads_render_tablet_portrait_js( $id, $default_ad_sizes,$id_name );
388
- $html .= quads_render_phone_js( $id, $default_ad_sizes,$id_name );
389
-
390
- $html = str_replace( '<div id="'.esc_attr($id_name).'">', '<div id="'.esc_attr($id_name).'" class="quads-ll">', $html );
391
- $html = str_replace( 'class="adsbygoogle"', '', $html );
392
- $html = str_replace( '></ins>', '><span>Loading...</span></ins>', $html );
393
- $code = 'instant= new adsenseLoader( \'#quads-' . esc_attr($id) . '-place\', {
394
- onLoad: function( ad ){
395
- if (ad.classList.contains("quads-ll")) {
396
- ad.classList.remove("quads-ll");
397
- }
398
- }
399
- });';
400
 
401
- $html = str_replace( '(adsbygoogle = window.adsbygoogle || []).push({});', $code, $html );
 
 
 
402
 
403
- }else{
404
- $html .= quads_render_desktop_js( $id, $default_ad_sizes );
405
- $html .= quads_render_tablet_landscape_js( $id, $default_ad_sizes );
406
- $html .= quads_render_tablet_portrait_js( $id, $default_ad_sizes );
407
- $html .= quads_render_phone_js( $id, $default_ad_sizes );
408
- }
409
- $html .= "\n".'</script>' . "\n";
410
 
411
- $html .= "\n <!-- end WP QUADS --> \n\n";
412
 
413
 
414
- return apply_filters( 'quads_render_adsense_async', $html );
415
  }
416
  function quads_load_loading_script(){
417
  global $quads_options;
@@ -470,28 +441,17 @@ function quads_render_desktop_js( $id, $default_ad_sizes,$id_name='' ) {
470
 
471
  if (!quads_is_extra() && !empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'])){
472
  $js = 'if ( quads_screen_width >= 1140 ) {';
473
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
474
-
475
- $js.='document.getElementById("'.$id_name.'").innerHTML='."'".$html."'".';
476
- (adsbygoogle = window.adsbygoogle || []).push({}); }';
477
- }else{
478
  $js.= 'document.write(\'' . $html . '\');
479
  (adsbygoogle = window.adsbygoogle || []).push({});
480
  }';
481
- }
482
  return $js;
483
  }
484
 
485
  if( !isset( $quads_options['ads'][$id][$adtype] ) and !empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
486
  $js = 'if ( quads_screen_width >= 1140 ) {';
487
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
488
- $js.='document.getElementById("'.$id_name.'").innerHTML='."'".$html."'".';
489
- (adsbygoogle = window.adsbygoogle || []).push({});}';
490
- }else{
491
  $js.= 'document.write(\'' . $html . '\');
492
  (adsbygoogle = window.adsbygoogle || []).push({});
493
  }';
494
- }
495
  return $js;
496
  }
497
  }
@@ -542,28 +502,17 @@ function quads_render_tablet_landscape_js( $id, $default_ad_sizes,$id_name='' )
542
 
543
  if( !quads_is_extra() && ! empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
544
  $js = 'if ( quads_screen_width >= 1024 && quads_screen_width < 1140 ) {';
545
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
546
- $js.='document.getElementById("'.$id_name.'").innerHTML='."'".$html."'".';
547
- (adsbygoogle = window.adsbygoogle || []).push({});}';
548
- }else{
549
  $js.= 'document.write(\'' . $html . '\');
550
  (adsbygoogle = window.adsbygoogle || []).push({});
551
  }';
552
- }
553
  return $js;
554
  }
555
 
556
  if( !isset( $quads_options['ads'][$id]['tablet_landscape'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
557
  $js = 'if ( quads_screen_width >= 1024 && quads_screen_width < 1140 ) {';
558
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
559
-
560
- $js.='document.getElementById("'.$id_name.'").innerHTML='."'".$html."'".';
561
- (adsbygoogle = window.adsbygoogle || []).push({}); }';
562
- }else{
563
  $js.= 'document.write(\'' . $html . '\');
564
  (adsbygoogle = window.adsbygoogle || []).push({});
565
  }';
566
- }
567
  return $js;
568
  }
569
  }
@@ -613,28 +562,17 @@ function quads_render_tablet_portrait_js( $id, $default_ad_sizes,$id_name='' ) {
613
 
614
  if( !quads_is_extra() and !empty( $default_ad_sizes[$id]['tbl_portrait_width'] ) and !empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
615
  $js = 'if ( quads_screen_width >= 768 && quads_screen_width < 1024 ) {';
616
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
617
-
618
- $js.='document.getElementById("'.$id_name.'").innerHTML='."'".$html."'".';
619
- (adsbygoogle = window.adsbygoogle || []).push({}); }';
620
- }else{
621
  $js.= 'document.write(\'' . $html . '\');
622
  (adsbygoogle = window.adsbygoogle || []).push({});
623
  }';
624
- }
625
  return $js;
626
  }
627
 
628
  if( !isset( $quads_options['ads'][$id]['tablet_portrait'] ) and !empty( $default_ad_sizes[$id]['tbl_portrait_width'] ) and !empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
629
  $js = 'if ( quads_screen_width >= 768 && quads_screen_width < 1024 ) {';
630
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
631
- $js.='document.getElementById("'.$id_name.'").innerHTML='."'".$html."'".';
632
- (adsbygoogle = window.adsbygoogle || []).push({}); }';
633
- }else{
634
  $js.= 'document.write(\'' . $html . '\');
635
  (adsbygoogle = window.adsbygoogle || []).push({});
636
  }';
637
- }
638
  return $js;
639
  }
640
  }
@@ -682,28 +620,18 @@ function quads_render_phone_js( $id, $default_ad_sizes,$id_name='' ) {
682
 
683
  if( !quads_is_extra() and ! empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
684
  $js = 'if ( quads_screen_width < 768 ) {';
685
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
686
- $js.='document.getElementById("'.$id_name.'").innerHTML='."'".$html."'".';
687
- (adsbygoogle = window.adsbygoogle || []).push({}); }';
688
- }else{
689
  $js.= 'document.write(\'' . $html . '\');
690
  (adsbygoogle = window.adsbygoogle || []).push({});
691
  }';
692
- }
693
  return $js;
694
  }
695
 
696
 
697
  if( !isset( $quads_options['ads'][$id][$adtype] ) and ! empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
698
  $js = 'if ( quads_screen_width < 768 ) {';
699
- if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true) {
700
- $js.='document.getElementById("'.$id_name.'").innerHTML='."'".$html."'".';
701
- (adsbygoogle = window.adsbygoogle || []).push({}); }';
702
- }else{
703
  $js.= 'document.write(\'' . $html . '\');
704
  (adsbygoogle = window.adsbygoogle || []).push({});
705
  }';
706
- }
707
  return $js;
708
  }
709
  }
@@ -787,13 +715,20 @@ function quads_render_amp($id,$ampsupport=''){
787
  if ( !quads_is_extra() ){
788
  return '';
789
  }
790
- if(isset($quads_options['ads'][$id]['amp']) && isset($quads_options['ads'][$id]['code']) && !empty($quads_options['ads'][$id]['code'])){
791
- return $quads_options['ads'][$id]['code'];
792
- }
793
  // if amp is not activated return empty
794
  if (!isset($quads_options['ads'][$id]['amp']) || quads_is_disabled_post_amp() ){
795
  return '';
796
  }
 
 
 
 
 
 
 
 
 
 
797
  }else{
798
 
799
  if((isset($quads_options['ads'][$id]['enabled_on_amp']) && isset($quads_options['ads'][$id]['code']) && !empty($quads_options['ads'][$id]['code']))|| (!empty($ampsupport) && $ampsupport)){
@@ -810,13 +745,10 @@ function quads_render_amp($id,$ampsupport=''){
810
  }
811
  }
812
  // if amp is not activated return empty
813
- if (!isset($quads_options['ads'][$id]['enabled_on_amp']) || quads_is_disabled_post_amp() ){
814
  return '';
815
  }
816
- }
817
- if (!empty($quads_options['ads'][$id]['amp_code'])){
818
- $html = $quads_options['ads'][$id]['amp_code'];
819
- } else {
820
  if($quads_options['ads'][$id]['ad_type'] == 'double_click'){
821
  $width = (isset($quads_options['ads'][$id]['g_data_ad_width']) && !empty($quads_options['ads'][$id]['g_data_ad_width'])) ? $quads_options['ads'][$id]['g_data_ad_width'] : '300';
822
  $height = (isset($quads_options['ads'][$id]['g_data_ad_height']) && !empty($quads_options['ads'][$id]['g_data_ad_height'])) ? $quads_options['ads'][$id]['g_data_ad_height'] : '250';
319
  * @param int $id
320
  * @return html
321
  */
 
322
  function quads_render_google_async( $id ) {
323
+ global $quads_options;
324
  // Default ad sizes - Option: Auto
325
  $default_ad_sizes[$id] = array(
326
  'desktop_width' => '300',
365
  $default_ad_sizes[$id]['phone_height'] = $ad_size_parts[1];
366
  }
367
 
368
+
369
  $html = "\n <!-- " . QUADS_NAME . " v." . QUADS_VERSION . " Content AdSense async --> \n\n";
 
 
 
370
  //google async script
 
 
 
 
 
 
371
  $html .= "\n".'<script type="text/javascript" >' . "\n";
372
  $html .= 'var quads_screen_width = document.body.clientWidth;' . "\n";
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
 
375
+ $html .= quads_render_desktop_js( $id, $default_ad_sizes );
376
+ $html .= quads_render_tablet_landscape_js( $id, $default_ad_sizes );
377
+ $html .= quads_render_tablet_portrait_js( $id, $default_ad_sizes );
378
+ $html .= quads_render_phone_js( $id, $default_ad_sizes );
379
 
380
+ $html .= "\n".'</script>' . "\n";
 
 
 
 
 
 
381
 
382
+ $html .= "\n <!-- end WP QUADS --> \n\n";
383
 
384
 
385
+ return apply_filters( 'quads_render_adsense_async', $html );
386
  }
387
  function quads_load_loading_script(){
388
  global $quads_options;
441
 
442
  if (!quads_is_extra() && !empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'])){
443
  $js = 'if ( quads_screen_width >= 1140 ) {';
 
 
 
 
 
444
  $js.= 'document.write(\'' . $html . '\');
445
  (adsbygoogle = window.adsbygoogle || []).push({});
446
  }';
 
447
  return $js;
448
  }
449
 
450
  if( !isset( $quads_options['ads'][$id][$adtype] ) and !empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
451
  $js = 'if ( quads_screen_width >= 1140 ) {';
 
 
 
 
452
  $js.= 'document.write(\'' . $html . '\');
453
  (adsbygoogle = window.adsbygoogle || []).push({});
454
  }';
 
455
  return $js;
456
  }
457
  }
502
 
503
  if( !quads_is_extra() && ! empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
504
  $js = 'if ( quads_screen_width >= 1024 && quads_screen_width < 1140 ) {';
 
 
 
 
505
  $js.= 'document.write(\'' . $html . '\');
506
  (adsbygoogle = window.adsbygoogle || []).push({});
507
  }';
 
508
  return $js;
509
  }
510
 
511
  if( !isset( $quads_options['ads'][$id]['tablet_landscape'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
512
  $js = 'if ( quads_screen_width >= 1024 && quads_screen_width < 1140 ) {';
 
 
 
 
 
513
  $js.= 'document.write(\'' . $html . '\');
514
  (adsbygoogle = window.adsbygoogle || []).push({});
515
  }';
 
516
  return $js;
517
  }
518
  }
562
 
563
  if( !quads_is_extra() and !empty( $default_ad_sizes[$id]['tbl_portrait_width'] ) and !empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
564
  $js = 'if ( quads_screen_width >= 768 && quads_screen_width < 1024 ) {';
 
 
 
 
 
565
  $js.= 'document.write(\'' . $html . '\');
566
  (adsbygoogle = window.adsbygoogle || []).push({});
567
  }';
 
568
  return $js;
569
  }
570
 
571
  if( !isset( $quads_options['ads'][$id]['tablet_portrait'] ) and !empty( $default_ad_sizes[$id]['tbl_portrait_width'] ) and !empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
572
  $js = 'if ( quads_screen_width >= 768 && quads_screen_width < 1024 ) {';
 
 
 
 
573
  $js.= 'document.write(\'' . $html . '\');
574
  (adsbygoogle = window.adsbygoogle || []).push({});
575
  }';
 
576
  return $js;
577
  }
578
  }
620
 
621
  if( !quads_is_extra() and ! empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
622
  $js = 'if ( quads_screen_width < 768 ) {';
 
 
 
 
623
  $js.= 'document.write(\'' . $html . '\');
624
  (adsbygoogle = window.adsbygoogle || []).push({});
625
  }';
 
626
  return $js;
627
  }
628
 
629
 
630
  if( !isset( $quads_options['ads'][$id][$adtype] ) and ! empty( $default_ad_sizes[$id][$adtype.'_width'] ) and ! empty( $default_ad_sizes[$id][$adtype.'_height'] ) ) {
631
  $js = 'if ( quads_screen_width < 768 ) {';
 
 
 
 
632
  $js.= 'document.write(\'' . $html . '\');
633
  (adsbygoogle = window.adsbygoogle || []).push({});
634
  }';
 
635
  return $js;
636
  }
637
  }
715
  if ( !quads_is_extra() ){
716
  return '';
717
  }
 
 
 
718
  // if amp is not activated return empty
719
  if (!isset($quads_options['ads'][$id]['amp']) || quads_is_disabled_post_amp() ){
720
  return '';
721
  }
722
+ // if having amp code
723
+ if(!empty($quads_options['ads'][$id]['amp_code'])){
724
+ return $quads_options['ads'][$id]['amp_code'];
725
+ }
726
+ if($quads_options['ads'][$id]['ad_type']=='plain_text'){
727
+ return $quads_options['ads'][$id]['code'];
728
+ }else{
729
+ return '<amp-ad layout="responsive" width=300 height=250 type="adsense" data-ad-client="'. $quads_options['ads'][$id]['g_data_ad_client'] . '" data-ad-slot="'.$quads_options['ads'][$id]['g_data_ad_slot'].'"></amp-ad>';
730
+ }
731
+
732
  }else{
733
 
734
  if((isset($quads_options['ads'][$id]['enabled_on_amp']) && isset($quads_options['ads'][$id]['code']) && !empty($quads_options['ads'][$id]['code']))|| (!empty($ampsupport) && $ampsupport)){
745
  }
746
  }
747
  // if amp is not activated return empty
748
+ if (!isset($quads_options['ads'][$id]['enabled_on_amp']) ){
749
  return '';
750
  }
751
+
 
 
 
752
  if($quads_options['ads'][$id]['ad_type'] == 'double_click'){
753
  $width = (isset($quads_options['ads'][$id]['g_data_ad_width']) && !empty($quads_options['ads'][$id]['g_data_ad_width'])) ? $quads_options['ads'][$id]['g_data_ad_width'] : '300';
754
  $height = (isset($quads_options['ads'][$id]['g_data_ad_height']) && !empty($quads_options['ads'][$id]['g_data_ad_height'])) ? $quads_options['ads'][$id]['g_data_ad_height'] : '250';
includes/template-functions.php CHANGED
@@ -1183,6 +1183,10 @@ function quads_replace_ads_new($content, $quicktag, $id,$ampsupport='') {
1183
  }
1184
  $code .= $ad_meta['code'][0];
1185
  if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true && strpos($ad_meta['code'][0], 'class="adsbygoogle"') !== false) {
 
 
 
 
1186
  $code = str_replace( 'class="adsbygoogle"', '', $code );
1187
  $code = str_replace( '></ins>', '><span>Loading...</span></ins></div>', $code );
1188
  $code1 = 'instant= new adsenseLoader( \'#quads-' . esc_attr($id) . '-place\', {
1183
  }
1184
  $code .= $ad_meta['code'][0];
1185
  if ( isset($quads_options['lazy_load_global']) && $quads_options['lazy_load_global']===true && strpos($ad_meta['code'][0], 'class="adsbygoogle"') !== false) {
1186
+ $check_script_tag = preg_match('#<script(.*?)src=(.*?)>(.*?)</script>#is', $code);
1187
+ if($check_script_tag){
1188
+ $code = preg_replace('#<script(.*?)src=(.*?)>(.*?)</script>#is', '', $code);
1189
+ }
1190
  $code = str_replace( 'class="adsbygoogle"', '', $code );
1191
  $code = str_replace( '></ins>', '><span>Loading...</span></ins></div>', $code );
1192
  $code1 = 'instant= new adsenseLoader( \'#quads-' . esc_attr($id) . '-place\', {
package-lock.json ADDED
@@ -0,0 +1,5432 @@