Advanced Ads - Version 1.38.0

Version Description

(November 22, 2022) =

  • Improvement: add support for multibyte cookies in "advads.get/set_cookie" functions
  • Improvement: update routine to remove all data on uninstall
  • Improvement: unify the behavior and look of the group and placement lists
  • Fix: serialize post meta in conditions to do string comparisons
  • Fix: ensure the filters for placements work
Download this release

Release Info

Developer advancedads
Plugin Icon 128x128 Advanced Ads
Version 1.38.0
Comparing to
See all releases

Code changes from version 1.37.2 to 1.38.0

Files changed (135) hide show
  1. admin/assets/css/admin.css +38 -27
  2. admin/assets/img/groups/grid.svg +1 -0
  3. admin/assets/img/groups/ordered.svg +1 -0
  4. admin/assets/img/groups/random.svg +1 -0
  5. admin/assets/img/groups/slider.svg +1 -0
  6. admin/assets/js/admin.js +34 -75
  7. admin/class-advanced-ads-admin.php +54 -53
  8. admin/includes/ad-authors.php +6 -6
  9. admin/includes/ad-health-notices.php +52 -52
  10. admin/includes/class-ad-groups-list.php +87 -66
  11. admin/includes/class-ad-network.php +16 -16
  12. admin/includes/class-ad-type.php +50 -50
  13. admin/includes/class-admin-upgrades.php +9 -9
  14. admin/includes/class-licenses.php +35 -35
  15. admin/includes/class-list-filters.php +61 -61
  16. admin/includes/class-menu.php +35 -16
  17. admin/includes/class-meta-box.php +60 -60
  18. admin/includes/class-notices.php +21 -21
  19. admin/includes/class-overview-widgets.php +46 -46
  20. admin/includes/class-settings.php +40 -40
  21. admin/includes/class-shortcode-creator.php +15 -15
  22. admin/includes/notices.php +16 -16
  23. admin/includes/shortcode-creator-l10n.php +2 -2
  24. admin/views/ad-group-list-form-row.php +69 -74
  25. admin/views/ad-group-list-header.php +2 -2
  26. admin/views/ad-group-list-row.php +41 -12
  27. admin/views/ad-group.php +41 -35
  28. admin/views/ad-info-after-textarea.php +5 -5
  29. admin/views/ad-list/timing.php +3 -3
  30. admin/views/ad-list/view-list.php +4 -4
  31. admin/views/ad-parameters-metabox.php +3 -3
  32. admin/views/ad-parameters-size.php +1 -1
  33. admin/views/checks.php +1 -1
  34. admin/views/conditions/ad-display-metabox.php +1 -1
  35. admin/views/conditions/ad-visitor-metabox.php +1 -1
  36. admin/views/conditions/condition-author.php +7 -7
  37. admin/views/conditions/condition-number.php +8 -1
  38. admin/views/conditions/condition-string.php +10 -5
  39. admin/views/conditions/display-conditions-list.php +1 -1
  40. admin/views/conditions/visitor-conditions-form-top.php +6 -6
  41. admin/views/conditions/visitor-conditions-list.php +1 -1
  42. admin/views/gadsense-dashboard.php +2 -2
  43. admin/views/group-form.php +51 -0
  44. admin/views/notices/info.php +2 -2
  45. admin/views/notices/promo.php +12 -12
  46. admin/views/overview-notices.php +4 -4
  47. admin/views/placement-form.php +10 -10
  48. admin/views/placement-injection-top.php +11 -11
  49. admin/views/placement-types.php +6 -6
  50. admin/views/placements.php +33 -33
  51. admin/views/settings.php +4 -4
  52. admin/views/settings/general/advanced-js.php +6 -6
  53. admin/views/settings/general/editors-manage-ads.php +6 -6
  54. admin/views/settings/general/link-target.php +1 -1
  55. admin/views/settings/license/section.php +6 -6
  56. admin/views/support.php +13 -13
  57. admin/views/upgrades/pro-placements.php +23 -23
  58. advanced-ads.php +2 -2
  59. changelog.txt +8 -0
  60. classes/ad-ajax.php +20 -20
  61. classes/ad-debug.php +4 -4
  62. classes/ad-expiration.php +6 -6
  63. classes/ad-health-notices.php +27 -27
  64. classes/ad-model.php +5 -5
  65. classes/ad-select.php +7 -7
  66. classes/ad.php +34 -34
  67. classes/ad_ajax_callbacks.php +42 -42
  68. classes/ad_group.php +38 -38
  69. classes/ad_placements.php +64 -64
  70. classes/ad_type_abstract.php +2 -2
  71. classes/ad_type_content.php +4 -4
  72. classes/ad_type_group.php +4 -4
  73. classes/ad_type_image.php +2 -2
  74. classes/ad_type_plain.php +6 -6
  75. classes/checks.php +10 -10
  76. classes/compatibility.php +20 -20
  77. classes/display-conditions.php +96 -96
  78. classes/filesystem.php +2 -2
  79. classes/frontend-notices.php +7 -7
  80. classes/frontend_checks.php +110 -110
  81. classes/in-content-injector.php +45 -45
  82. classes/inline-css.php +1 -1
  83. classes/plugin.php +60 -53
  84. classes/utils.php +4 -4
  85. classes/visitor-conditions.php +27 -26
  86. classes/widget.php +12 -12
  87. includes/array_ad_conditions.php +30 -30
  88. includes/cap_map.php +2 -2
  89. includes/functions.php +12 -12
  90. includes/load_modules.php +4 -4
  91. languages/advanced-ads.pot +99 -70
  92. modules/ad-blocker/admin/admin.php +19 -19
  93. modules/ad-blocker/classes/plugin.php +5 -5
  94. modules/ad-blocker/config.php +4 -4
  95. modules/ad-positioning/classes/ad-positioning.php +38 -38
  96. modules/ad-positioning/views/ad-spacing.php +1 -1
  97. modules/adblock-finder/admin/admin.php +3 -3
  98. modules/adblock-finder/config.php +4 -4
  99. modules/adblock-finder/public/public.php +1 -1
  100. modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php +26 -26
  101. modules/ads-txt/admin/views/setting-additional-content.php +4 -4
  102. modules/ads-txt/config.php +4 -4
  103. modules/ads-txt/includes/class-advanced-ads-ads-txt-real-file.php +6 -6
  104. modules/ads-txt/includes/class-advanced-ads-ads-txt-strategy.php +5 -5
  105. modules/ads-txt/includes/class-advanced-ads-ads-txt-utils.php +13 -13
  106. modules/ads-txt/public/class-advanced-ads-ads-txt-public.php +8 -8
  107. modules/gadsense/admin/admin.php +17 -17
  108. modules/gadsense/admin/dummy.php +5 -5
  109. modules/gadsense/admin/views/adsense-account.php +40 -40
  110. modules/gadsense/admin/views/adsense-ad-parameters.php +1 -1
  111. modules/gadsense/admin/views/adsense-report.php +1 -1
  112. modules/gadsense/admin/views/borlabs-cookie-auto-ads-warning.php +3 -3
  113. modules/gadsense/admin/views/external-ads-list.php +5 -5
  114. modules/gadsense/config.php +4 -4
  115. modules/gadsense/includes/adsense-report-api.php +17 -17
  116. modules/gadsense/includes/adsense-report-data.php +9 -9
  117. modules/gadsense/includes/class-ad-type-adsense.php +10 -10
  118. modules/gadsense/includes/class-adsense-report.php +3 -3
  119. modules/gadsense/includes/class-gadsense-data.php +3 -3
  120. modules/gadsense/includes/class-mapi.php +178 -178
  121. modules/gadsense/includes/class-network-adsense.php +21 -21
  122. modules/gadsense/public/public.php +10 -10
  123. modules/gutenberg/config.php +4 -4
  124. modules/gutenberg/includes/class-gutenberg.php +25 -25
  125. modules/import-export/classes/XmlEncoder.php +5 -5
  126. modules/import-export/classes/export.php +17 -17
  127. modules/import-export/classes/import.php +59 -59
  128. modules/import-export/config.php +4 -4
  129. modules/privacy/admin/admin.php +22 -22
  130. modules/privacy/classes/class-privacy.php +6 -6
  131. modules/privacy/config.php +4 -4
  132. public/assets/js/advanced.js +8 -8
  133. public/assets/js/advanced.min.js +1 -1
  134. public/class-advanced-ads.php +47 -47
  135. readme.txt +10 -40
admin/assets/css/admin.css CHANGED
@@ -357,10 +357,12 @@ body.rtl .aa-select-list .aa-select-list-update { left: 47px; right: auto;}
357
  /**
358
  AD GROUP LIST
359
  */
 
360
  #advads-ad-group-list .row-actions span + span::before { content: '|'; padding: 0 3px; }
361
  #advads-ad-group-list ul, #advads-ad-group-list ol { margin: 0; list-style-position: inside; }
362
- #advads-ad-group-list tbody tr:nth-child(4n+1) { background: #f9f9f9; }
363
  #advads-ad-group-list .advads-group-ads tr:nth-child(odd) { background: #f9f9f9; }
 
 
364
  .advads-ad-group-list-ads li { margin: 0; padding: 3px 0; }
365
  .advads-ad-group-list-ads li:hover { background: #eee; }
366
  .advads-ad-group-list-ads i { margin-left: 1em; font-style: italic; }
@@ -374,34 +376,12 @@ body.rtl .aa-select-list .aa-select-list-update { left: 47px; right: auto;}
374
  .advads-ad-group-form label { display: inline-block; margin-bottom: 1em; }
375
  .advads-ad-group-form strong { float: left; width: 180px; }
376
  .advads-ad-group-form ul { float: left; }
377
- .advads-ad-group-list-ads li { padding-bottom: 10px; }
378
  fieldset.advads-group-add-ad { margin-top: 1em; }
 
379
 
380
  /**
381
  AD PLACEMENTS
382
  */
383
- .advads-placement-description { display: none; }
384
- .advads-placements-new-form .advads-placement-type { position: relative; top: 0; left: 0; float: left; width: 80px; margin: 15px 0 0 15px; }
385
- .advads-placements-new-form .advads-placement-type .advads-button { background: none; border-radius: 0; height: auto; }
386
- .advads-placements-new-form .advads-placement-type .advads-button-text { padding: 0; width: 80px; height: 60px; border: solid 1px #0085ba; border-radius: 3px; box-shadow: 0 0 2px #0085ba; overflow: hidden; box-sizing: border-box; }
387
- .advads-placements-new-form .advads-placement-type .advads-button-text img { max-width: 100%; pointer-events: none; }
388
- .advads-placements-new-form .advads-placement-type label { display: inline-block; width: 80px; text-align: center; border: 0; padding: 0; }
389
- .advads-placements-new-form .advads-buttonset .advads-button.advads-ui-state-active { outline: 5px solid #2ea2cc; border: 0; }
390
- .advads-placements-new-form .advads-placement-type label .description { padding: 10px; }
391
- .advads-placements-new-form .advads-notice-inline.advads-error { display: none; }
392
- .advads-placements-table { min-width: 80%; border-collapse: collapse; background: #fff; }
393
- .advads-placements-table > tbody > tr { border-top: 1px solid #ddd; }
394
- .advads-placements-table tbody tr td:first-child { width: 200px; }
395
- .advads-placements-table .advads-placement-name { font-size: 1.2em; }
396
- .advads-placements-table tbody tr td:last-child { width: 70px; }
397
- .advads-placements-table th { margin: 0; padding: 10px; text-align: left; vertical-align: top; }
398
- .advads-placements-table.widefat tbody th { font-weight: bold; }
399
- .advads-placements-table th span { font-weight: normal; }
400
- .advads-placements-table td { margin: 0; padding: 20px 10px; text-align: left; vertical-align: top; }
401
- .advads-placements-table img { height: 70px; margin-bottom: 5px; }
402
- .advads-placements-table .usage-modal-link { cursor: pointer; }
403
- .advads-placements-table .advads-usage, .adgroups .advads-usage { margin-bottom: 20px; }
404
- .advads-placements-table .advads-usage input, .adgroups .advads-usage input { width: 100%; }
405
  .advads-placements-table-options { text-align: right; }
406
  .advads-placements-table-options input[type="number"] { width: 4.5em; }
407
  .advads-placements-table ol { margin: 0.5em 0; list-style-position: inside; }
@@ -526,6 +506,19 @@ tr:hover .on-hover { display: block; }
526
  }
527
  }
528
 
 
 
 
 
 
 
 
 
 
 
 
 
 
529
  /**
530
  * Custom Boxes, similar to WP Metaboxes
531
  */
@@ -856,6 +849,8 @@ li:hover > .advads-help:before {
856
  /* WP Admin notifications branded for Advanced Ads */
857
  .advads-notice,
858
  .post-type-advanced_ads .notice,
 
 
859
  .advanced-ads_page_advanced-ads-placements .notice {
860
  border-left-color: #1B183A;
861
  }
@@ -1116,6 +1111,23 @@ tr.advads-clickable-row:hover{
1116
  width: 32%;
1117
  }
1118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1119
  /**
1120
  * RESPONSIVE BEHAVIOR
1121
  * mobile is default
@@ -1144,19 +1156,18 @@ tr.advads-clickable-row:hover{
1144
  .advads-option-table-responsive tbody td:before, .advads-option-table-responsive tfoot th:before { display: none; }
1145
  }
1146
  @media (min-width: 1200px) {
1147
- .advads-placements-table .advads-placement-name {
1148
  font-size: 1.2em;
1149
  width: calc(97% - 70px);
1150
  display: inline-block;
1151
  vertical-align: top;
1152
  }
1153
- .advads-placements-table img {
1154
  height: auto;
1155
  width: 65px;
1156
  margin-right: 3%;
1157
  display: inline-block;
1158
  }
1159
- .advads-placements-table .advads-placement-type {text-align: left;}
1160
  }
1161
  @media (min-width: 60em) {
1162
  .advads-modal-content {
357
  /**
358
  AD GROUP LIST
359
  */
360
+ .advanced-ads_page_advanced-ads-groups .tablenav.top { margin: 15px 0 0; }
361
  #advads-ad-group-list .row-actions span + span::before { content: '|'; padding: 0 3px; }
362
  #advads-ad-group-list ul, #advads-ad-group-list ol { margin: 0; list-style-position: inside; }
 
363
  #advads-ad-group-list .advads-group-ads tr:nth-child(odd) { background: #f9f9f9; }
364
+ #advads-ad-group-list .column-group-type { width: 50px; }
365
+ #advads-ad-group-list .column-group-type img { width: 50px; height: 50px; }
366
  .advads-ad-group-list-ads li { margin: 0; padding: 3px 0; }
367
  .advads-ad-group-list-ads li:hover { background: #eee; }
368
  .advads-ad-group-list-ads i { margin-left: 1em; font-style: italic; }
376
  .advads-ad-group-form label { display: inline-block; margin-bottom: 1em; }
377
  .advads-ad-group-form strong { float: left; width: 180px; }
378
  .advads-ad-group-form ul { float: left; }
 
379
  fieldset.advads-group-add-ad { margin-top: 1em; }
380
+ .advanced-ads_page_advanced-ads-groups .advads-form .advads-form-type .advads-button-text { height: 80px; border: none; box-shadow: none; }
381
 
382
  /**
383
  AD PLACEMENTS
384
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  .advads-placements-table-options { text-align: right; }
386
  .advads-placements-table-options input[type="number"] { width: 4.5em; }
387
  .advads-placements-table ol { margin: 0.5em 0; list-style-position: inside; }
506
  }
507
  }
508
 
509
+ /**
510
+ * Forms to add a new ad, group, or placement
511
+ */
512
+ .advads-form-description { display: none; }
513
+ .advads-form .advads-form-type { position: relative; top: 0; left: 0; float: left; width: 80px; margin: 15px 0 0 15px; }
514
+ .advads-form .advads-form-type .advads-button { background: none; border-radius: 0; height: auto; }
515
+ .advads-form .advads-form-type .advads-button-text { padding: 0; width: 80px; height: 60px; border: solid 1px #0085ba; border-radius: 3px; box-shadow: 0 0 2px #0085ba; overflow: hidden; box-sizing: border-box; user-select: none; }
516
+ .advads-form .advads-form-type .advads-button-text img { max-width: 100%; pointer-events: none; }
517
+ .advads-form .advads-form-type label { display: inline-block; width: 80px; text-align: center; border: 0; padding: 0; }
518
+ .advads-form .advads-buttonset .advads-button.advads-ui-state-active { outline: 5px solid #2ea2cc; border: 0; }
519
+ .advads-form .advads-form-type label .description { padding: 10px; }
520
+ .advads-form .advads-notice-inline.advads-error { display: none; }
521
+
522
  /**
523
  * Custom Boxes, similar to WP Metaboxes
524
  */
849
  /* WP Admin notifications branded for Advanced Ads */
850
  .advads-notice,
851
  .post-type-advanced_ads .notice,
852
+ .advanced-ads_page_advanced-ads-groups .notice,
853
+ .advanced-ads_page_advanced-ads-groups #message,
854
  .advanced-ads_page_advanced-ads-placements .notice {
855
  border-left-color: #1B183A;
856
  }
1111
  width: 32%;
1112
  }
1113
 
1114
+ /**
1115
+ * Tables
1116
+ */
1117
+ .advads-table { min-width: 80%; border-collapse: collapse; background: #fff; }
1118
+ .advads-table tbody tr:nth-child(odd) { background-color: #f9f9f9; }
1119
+ .advads-table tbody tr td:first-child { width: 200px; }
1120
+ .advads-table .advads-table-name { font-size: 1.2em; }
1121
+ .advads-table tbody tr td:last-child { width: 70px; }
1122
+ .advads-table th { margin: 0; text-align: left; vertical-align: top; }
1123
+ .advads-table.widefat tbody th { font-weight: bold; }
1124
+ .advads-table th span { font-weight: normal; }
1125
+ .advads-table td { margin: 0; padding: 10px 8px; text-align: left; vertical-align: top; }
1126
+ .advads-table img { height: 70px; margin-bottom: 5px; }
1127
+ .advads-table .usage-modal-link { cursor: pointer; }
1128
+ .advads-table .advads-usage { margin-bottom: 20px; }
1129
+ .advads-table .advads-usage input { width: 100%; }
1130
+
1131
  /**
1132
  * RESPONSIVE BEHAVIOR
1133
  * mobile is default
1156
  .advads-option-table-responsive tbody td:before, .advads-option-table-responsive tfoot th:before { display: none; }
1157
  }
1158
  @media (min-width: 1200px) {
1159
+ .advads-table .advads-table-name {
1160
  font-size: 1.2em;
1161
  width: calc(97% - 70px);
1162
  display: inline-block;
1163
  vertical-align: top;
1164
  }
1165
+ .advads-table img {
1166
  height: auto;
1167
  width: 65px;
1168
  margin-right: 3%;
1169
  display: inline-block;
1170
  }
 
1171
  }
1172
  @media (min-width: 60em) {
1173
  .advads-modal-content {
admin/assets/img/groups/grid.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" overflow="visible"><path fill="#fff" d="M19.878 99C9.469 99 1 90.532 1 80.123V2a1 1 0 0 1 1-1h78.122C90.531 1 99 9.469 99 19.878V98a1 1 0 0 1-1 1H19.878z"/><path d="M80.122 2C89.98 2 98 10.02 98 19.878V98H19.878C10.019 98 2 89.98 2 80.123V2h78.122m0-2H2a2 2 0 0 0-2 2v78.123C0 91.083 8.917 100 19.878 100H98a2 2 0 0 0 2-2V19.878C100 8.917 91.083 0 80.122 0h0zM34.065 47.149H19.381c-.811 0-1.467-.657-1.467-1.467V31c0-.81.656-1.467 1.467-1.467h14.685c.811 0 1.467.657 1.467 1.467v14.683a1.47 1.47 0 0 1-1.468 1.466zm46.637 0H66.019c-.811 0-1.467-.657-1.467-1.467V31c0-.81.656-1.467 1.467-1.467h14.684c.811 0 1.467.657 1.467 1.467v14.683a1.47 1.47 0 0 1-1.468 1.466zm-23.318 0H42.699c-.811 0-1.467-.657-1.467-1.467V31c0-.81.656-1.467 1.467-1.467h14.685c.811 0 1.467.657 1.467 1.467v14.683c0 .81-.657 1.466-1.467 1.466zM34.065 70.467H19.381c-.811 0-1.467-.656-1.467-1.467V54.317c0-.811.656-1.467 1.467-1.467h14.685c.811 0 1.467.656 1.467 1.467V69a1.47 1.47 0 0 1-1.468 1.467zm46.637 0H66.019c-.811 0-1.467-.656-1.467-1.467V54.317c0-.811.656-1.467 1.467-1.467h14.684c.811 0 1.467.656 1.467 1.467V69a1.47 1.47 0 0 1-1.468 1.467zm-23.318 0H42.699c-.811 0-1.467-.656-1.467-1.467V54.317c0-.811.656-1.467 1.467-1.467h14.685c.811 0 1.467.656 1.467 1.467V69c0 .811-.657 1.467-1.467 1.467z" fill="#0074a2"/></svg>
admin/assets/img/groups/ordered.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" overflow="visible"><path fill="#fff" d="M19.878 99C9.469 99 1 90.532 1 80.123V2a1 1 0 0 1 1-1h78.122C90.531 1 99 9.469 99 19.878V98a1 1 0 0 1-1 1H19.878z"/><path d="M80.122 2C89.98 2 98 10.02 98 19.878V98H19.878C10.019 98 2 89.98 2 80.123V2h78.122m0-2H2a2 2 0 0 0-2 2v78.123C0 91.083 8.917 100 19.878 100H98a2 2 0 0 0 2-2V19.878C100 8.917 91.083 0 80.122 0h0zM34.064 45.483H19.38c-.811 0-1.467-.657-1.467-1.467V29.333c0-.81.656-1.467 1.467-1.467h14.685c.811 0 1.467.657 1.467 1.467v14.683a1.47 1.47 0 0 1-1.468 1.467zm46.638 0H66.017c-.811 0-1.467-.657-1.467-1.467V29.333c0-.81.656-1.467 1.467-1.467h14.686c.811 0 1.467.657 1.467 1.467v14.683a1.47 1.47 0 0 1-1.468 1.467zM67.483 42.55h11.752V30.8H67.483v11.75zm-10.1 2.933H42.698c-.811 0-1.467-.657-1.467-1.467V29.333c0-.81.656-1.467 1.467-1.467h14.685c.811 0 1.467.657 1.467 1.467v14.683c0 .811-.657 1.467-1.467 1.467zM44.165 42.55h11.751V30.8H44.165v11.75zm-1.901 11.877c-.23 0-.461.06-.667.179-.412.238-.667.679-.667 1.155v14.682c0 .477.255.917.667 1.155.206.119.437.179.667.179s.46-.06.667-.179l12.718-7.34c.412-.238.667-.679.667-1.155s-.255-.917-.667-1.155l-12.718-7.342c-.206-.12-.437-.179-.667-.179h0zm15.553 17.482c-.811 0-1.467-.656-1.467-1.467V55.761c0-.811.656-1.467 1.467-1.467s1.467.656 1.467 1.467v14.682c0 .81-.656 1.466-1.467 1.466z" fill="#0074a2"/></svg>
admin/assets/img/groups/random.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" overflow="visible"><path fill="#fff" d="M19.878 99C9.469 99 1 90.532 1 80.123V2a1 1 0 0 1 1-1h78.122C90.531 1 99 9.469 99 19.878V98a1 1 0 0 1-1 1H19.878z"/><path d="M80.122 2C89.98 2 98 10.02 98 19.878V98H19.878C10.019 98 2 89.98 2 80.123V2h78.122m0-2H2a2 2 0 0 0-2 2v78.123C0 91.083 8.917 100 19.878 100H98a2 2 0 0 0 2-2V19.878C100 8.917 91.083 0 80.122 0h0zM34.064 45.483H19.38a1.47 1.47 0 0 1-1.467-1.467V29.333a1.47 1.47 0 0 1 1.467-1.467h14.684a1.47 1.47 0 0 1 1.467 1.467v14.683c0 .811-.657 1.467-1.467 1.467zM20.847 42.55h11.75V30.8h-11.75v11.75zm59.854 2.933H66.018c-.811 0-1.467-.657-1.467-1.467V29.333c0-.81.656-1.467 1.467-1.467h14.684c.811 0 1.467.657 1.467 1.467v14.683a1.47 1.47 0 0 1-1.468 1.467zm-23.318 0H42.699a1.47 1.47 0 0 1-1.467-1.467V29.333a1.47 1.47 0 0 1 1.467-1.467h14.684c.811 0 1.467.657 1.467 1.467v14.683c0 .811-.657 1.467-1.467 1.467zM44.166 42.55h11.75V30.8h-11.75v11.75zm22.896 27.259l-8.193-4.729c-.227-.133-.505-.133-.733 0a.73.73 0 0 0-.366.635v3.263h-1.016c-1.571-.002-3.046-.613-4.154-1.721l-4.154-4.154 4.154-4.154c1.109-1.109 2.584-1.72 4.152-1.72h1.018v3.263c0 .262.14.504.366.635a.73.73 0 0 0 .367.099c.127 0 .253-.032.366-.099l8.193-4.729a.73.73 0 0 0 .367-.635c0-.262-.14-.504-.367-.635l-8.193-4.73c-.227-.131-.505-.131-.733 0a.73.73 0 0 0-.366.635v3.263h-1.018a8.75 8.75 0 0 0-6.227 2.578l-4.154 4.154-4.155-4.155a8.75 8.75 0 0 0-6.225-2.577h-1.688c-.81 0-1.467.656-1.467 1.467s.657 1.467 1.467 1.467h1.688a5.83 5.83 0 0 1 4.15 1.719l4.155 4.155-4.154 4.154c-1.108 1.107-2.583 1.719-4.15 1.721h-1.688c-.81 0-1.467.656-1.467 1.467s.657 1.467 1.467 1.467h1.689c2.352-.002 4.562-.919 6.223-2.58l4.154-4.154 4.154 4.154c1.661 1.661 3.872 2.578 6.227 2.58h1.018v3.263c0 .262.14.504.366.635a.73.73 0 0 0 .367.099c.127 0 .253-.032.366-.099l8.193-4.729a.73.73 0 0 0 .367-.635c0-.262-.139-.508-.366-.638z" fill="#0074a2"/></svg>
admin/assets/img/groups/slider.svg ADDED
@@ -0,0 +1 @@
 
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" overflow="visible"><path fill="#fff" d="M19.878 99C9.469 99 1 90.532 1 80.123V2a1 1 0 0 1 1-1h78.122C90.531 1 99 9.469 99 19.878V98a1 1 0 0 1-1 1H19.878z"/><path d="M80.122 2C89.98 2 98 10.02 98 19.878V98H19.878C10.019 98 2 89.98 2 80.123V2h78.122m0-2H2a2 2 0 0 0-2 2v78.123C0 91.083 8.917 100 19.878 100H98a2 2 0 0 0 2-2V19.878C100 8.917 91.083 0 80.122 0h0zm.579 31.367H67.484V24.2c0-.81-.656-1.467-1.467-1.467H34.064c-.811 0-1.467.657-1.467 1.467v7.167H19.38c-.811 0-1.467.657-1.467 1.467v14.683c0 .81.656 1.467 1.467 1.467h13.218v7.167c0 .811.656 1.467 1.467 1.467h31.953c.811 0 1.467-.656 1.467-1.467v-7.167h13.217c.811 0 1.467-.657 1.467-1.467V32.834a1.47 1.47 0 0 0-1.468-1.467zM20.847 46.05V34.3h11.751v11.75H20.847zm58.387 0h-11.75V34.3h11.75v11.75zM50 65.25c-3.235 0-5.867 2.632-5.867 5.867s2.632 5.868 5.867 5.868 5.866-2.632 5.866-5.868S53.234 65.25 50 65.25h0zm17.603 2.934c1.621 0 2.934 1.313 2.934 2.934s-1.312 2.935-2.934 2.935-2.933-1.313-2.933-2.935a2.93 2.93 0 0 1 2.933-2.934m0-2.934c-3.234 0-5.866 2.632-5.866 5.867s2.632 5.868 5.866 5.868 5.867-2.632 5.867-5.868-2.632-5.867-5.867-5.867h0zm-35.207 2.934c1.62 0 2.933 1.313 2.933 2.934s-1.312 2.935-2.933 2.935-2.934-1.313-2.934-2.935 1.313-2.934 2.934-2.934m0-2.934c-3.235 0-5.867 2.632-5.867 5.867s2.632 5.868 5.867 5.868 5.866-2.632 5.866-5.868-2.631-5.867-5.866-5.867h0z" fill="#0074a2"/></svg>
admin/assets/js/admin.js CHANGED
@@ -113,62 +113,6 @@ jQuery( document ).ready( function ( $ ) {
113
  $( '#show-settings-link' ).trigger( 'click' );
114
  } );
115
 
116
- /**
117
- * Logic for ad groups
118
- */
119
-
120
- // display new ad group form
121
- $( '#advads-new-ad-group-link' ).on( 'click', function ( e ) {
122
- e.preventDefault()
123
- $( '#advads-new-group-form' ).show().find( 'input[type="text"]' ).focus()
124
- } )
125
-
126
- // display ad groups form
127
- $( '#advads-ad-group-list a.edit, #advads-ad-group-list a.row-title' ).on( 'click', function ( e ) {
128
- e.preventDefault();
129
- var advadsgroupformrow = $( this ).parents( '.advads-group-row' ).next( '.advads-ad-group-form' );
130
- if ( advadsgroupformrow.is( ':visible' ) ) {
131
- advadsgroupformrow.addClass( 'hidden' );
132
- advadsgroupformrow.prev( '.advads-group-row' ).find( '.advads-ad-group-list-ads a.edit' ).show();
133
- // clear last edited id
134
- $( '#advads-last-edited-group' ).val( '' );
135
- } else {
136
- advadsgroupformrow.removeClass( 'hidden' );
137
- advadsgroupformrow.prev( '.advads-group-row' ).find( '.advads-ad-group-list-ads a.edit' ).hide();
138
- var selectField = advadsgroupformrow.find( 'select.advads-group-add-ad-list-ads' );
139
- if ( jQuery( this ).hasClass( 'advads-add-ads' ) ) {
140
- selectField.focus();
141
- jQuery( 'html, body' ).animate( {
142
- scrollTop: selectField.offset().top
143
- }, 1000 );
144
- }
145
-
146
- var group_id = advadsgroupformrow.find( '.advads-group-id' ).val();
147
- $( '#advads-last-edited-group' ).val( group_id );
148
- // remember that we opened that one
149
- advadsgroupformrow.data( 'touched', true );
150
- }
151
- } );
152
- // display ad groups usage
153
- $( '#advads-ad-group-list a.usage' ).on( 'click', function ( e ) {
154
- e.preventDefault();
155
- var usagediv = $(this).parents('.advads-group-row').find('.advads-usage');
156
- if (usagediv.is(':visible')) {
157
- usagediv.addClass('hidden');
158
- } else {
159
- usagediv.removeClass('hidden');
160
- }
161
- });
162
- // handle the submission of the groups form
163
- $( 'form#advads-form-groups' ).on( 'submit', function () {
164
- jQuery( 'tr.advads-ad-group-form' ).each( function ( k, v ) {
165
- v = jQuery( v )
166
- if ( ! v.data( 'touched' ) ) {
167
- v.remove()
168
- }
169
- } )
170
- } )
171
-
172
  /**
173
  * Logic for placement list
174
  */
@@ -179,7 +123,7 @@ jQuery( document ).ready( function ( $ ) {
179
  jQuery( '.advads-placements-table tbody > tr' ).show();
180
  } else {
181
  jQuery( '.advads-placements-table tbody > tr' ).each( function () {
182
- if ( jQuery( this ).data( 'type' ) !== selectedValue ) {
183
  jQuery( this ).hide();
184
  } else {
185
  jQuery( this ).show();
@@ -196,13 +140,14 @@ jQuery( document ).ready( function ( $ ) {
196
  if ( ! index ) {
197
  return;
198
  }
199
- var name = jQuery( this ).data( 'name' );
200
  if ( typeof name !== 'undefined' ) {
201
  jQuery( this ).toggle( name.toLowerCase().indexOf( value.toLowerCase() ) !== - 1 );
202
  }
203
  } );
204
  } );
205
 
 
206
  jQuery( '.advanced-ads-placement-row .advads-modal-close-action' ).on( 'click', function () {
207
  // Change url hash, so that the modal doesn't load after refresh again.
208
  window.location.hash = '#close';
@@ -513,13 +458,6 @@ jQuery( document ).ready( function ( $ ) {
513
  /**
514
  * PLACEMENTS
515
  */
516
- // show image tooltips
517
- $( '.advanced-ads_page_advanced-ads-placements .advads-placement-type' ).advads_tooltip( {
518
- content: function () {
519
- return jQuery( this ).find( '.advads-placement-description' ).html()
520
- }
521
- } )
522
-
523
  var set_touched_placement = function() {
524
  var tr = $( this ).closest( 'tr.advanced-ads-placement-row' )
525
  if ( tr ) {
@@ -575,6 +513,13 @@ jQuery( document ).ready( function ( $ ) {
575
  }
576
  }
577
 
 
 
 
 
 
 
 
578
  /**
579
  * Image ad uploader
580
  */
@@ -817,26 +762,40 @@ function advads_toggle_box_enable ( e, selector ) {
817
  }
818
 
819
  /**
820
- * Validate placement form on submit.
821
  */
822
- function advads_validate_placement_form (modalID) {
823
- // check if placement type was selected
824
- if ( ! jQuery( '.advads-placement-type input:checked' ).length ) {
825
- jQuery( '.advads-placement-type-error' ).show()
826
  return false
827
  } else {
828
- jQuery( '.advads-placement-type-error' ).hide()
829
  }
830
- // check if placement name was entered
831
- if ( jQuery( '.advads-new-placement-name' ).val() == '' ) {
832
- jQuery( '.advads-placement-name-error' ).show()
833
  return false
834
  } else {
835
- jQuery( '.advads-placement-name-error' ).hide()
836
  }
837
  return true
838
  }
839
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
840
  /**
841
  * replace textarea with TinyMCE editor for Rich Content ad type
842
  */
113
  $( '#show-settings-link' ).trigger( 'click' );
114
  } );
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  /**
117
  * Logic for placement list
118
  */
123
  jQuery( '.advads-placements-table tbody > tr' ).show();
124
  } else {
125
  jQuery( '.advads-placements-table tbody > tr' ).each( function () {
126
+ if ( jQuery( this ).data( 'order' )['type'] !== selectedValue ) {
127
  jQuery( this ).hide();
128
  } else {
129
  jQuery( this ).show();
140
  if ( ! index ) {
141
  return;
142
  }
143
+ var name = jQuery( this ).data( 'order' )['name'];
144
  if ( typeof name !== 'undefined' ) {
145
  jQuery( this ).toggle( name.toLowerCase().indexOf( value.toLowerCase() ) !== - 1 );
146
  }
147
  } );
148
  } );
149
 
150
+ // save placement edit modal
151
  jQuery( '.advanced-ads-placement-row .advads-modal-close-action' ).on( 'click', function () {
152
  // Change url hash, so that the modal doesn't load after refresh again.
153
  window.location.hash = '#close';
458
  /**
459
  * PLACEMENTS
460
  */
 
 
 
 
 
 
 
461
  var set_touched_placement = function() {
462
  var tr = $( this ).closest( 'tr.advanced-ads-placement-row' )
463
  if ( tr ) {
513
  }
514
  }
515
 
516
+ // show tooltips for group type or placement type in forms
517
+ $( '.advads-form-type' ).advads_tooltip( {
518
+ content: function () {
519
+ return jQuery( this ).find( '.advads-form-description' ).html()
520
+ }
521
+ } )
522
+
523
  /**
524
  * Image ad uploader
525
  */
762
  }
763
 
764
  /**
765
+ * Validate the form that creates a new group or placement.
766
  */
767
+ function advads_validate_new_form (modalID) {
768
+ // Check if type was selected
769
+ if ( ! jQuery( '.advads-form-type input:checked' ).length ) {
770
+ jQuery( '.advads-form-type-error' ).show()
771
  return false
772
  } else {
773
+ jQuery( '.advads-form-type-error' ).hide()
774
  }
775
+ // Check if name was entered
776
+ if ( jQuery( '.advads-form-name' ).val() == '' ) {
777
+ jQuery( '.advads-form-name-error' ).show()
778
  return false
779
  } else {
780
+ jQuery( '.advads-form-name-error' ).hide()
781
  }
782
  return true
783
  }
784
 
785
+ /**
786
+ * Submit only the current group. Submitting the form with all groups could otherwise cause a server timeout or PHP limit error.
787
+ *
788
+ * @param {string} modalID
789
+ * @return {boolean}
790
+ */
791
+ function advads_group_edit_submit( modalID ) {
792
+ jQuery( '.advads-ad-group-form' )
793
+ .filter( ( i, element ) => ! jQuery( element ).parents( modalID ).length )
794
+ .remove();
795
+
796
+ return true;
797
+ }
798
+
799
  /**
800
  * replace textarea with TinyMCE editor for Rich Content ad type
801
  */
admin/class-advanced-ads-admin.php CHANGED
@@ -55,10 +55,10 @@ class Advanced_Ads_Admin {
55
  private function __construct() {
56
  if ( wp_doing_ajax() ) {
57
  new Advanced_Ads_Ad_Ajax_Callbacks();
58
- add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded_ajax' ) );
59
  } else {
60
- add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
61
- add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ), 100 );
62
  Advanced_Ads_Ad_List_Filters::get_instance();
63
  }
64
  // add shortcode creator to TinyMCE.
@@ -99,33 +99,33 @@ class Advanced_Ads_Admin {
99
  $plugin = Advanced_Ads::get_instance();
100
  $this->plugin_slug = $plugin->get_plugin_slug();
101
 
102
- add_action( 'current_screen', array( $this, 'current_screen' ) );
103
 
104
  // Load admin style sheet and JavaScript.
105
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_styles' ) );
106
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ), 9 );
107
 
108
  // update placements.
109
- add_action( 'admin_init', array( 'Advanced_Ads_Placements', 'update_placements' ) );
110
 
111
  // add Advanced Ads admin notices
112
  // removes admin notices from other plugins
113
  // `in_admin_header` is the last hook to run before àdmin_notices` according to https://codex.wordpress.org/Plugin_API/Action_Reference.
114
- add_action( 'in_admin_header', array( $this, 'register_admin_notices' ) );
115
 
116
  // add links to plugin page.
117
- add_filter( 'plugin_action_links_' . ADVADS_BASE, array( $this, 'add_plugin_links' ) );
118
 
119
  // display information when user is going to disable the plugin.
120
- add_filter( 'admin_footer', array( $this, 'add_deactivation_logic' ) );
121
  // add_filter( 'after_plugin_row_' . ADVADS_BASE, array( $this, 'display_deactivation_message' ) );
122
  // disable adding rel="noopener noreferrer" to link added through TinyMCE for rich content ads.
123
- add_filter( 'tiny_mce_before_init', array( $this, 'tinymce_allow_unsafe_link_target' ) );
124
 
125
- add_action( 'plugins_api_result', array( $this, 'recommend_suitable_add_ons' ), 11, 3 );
126
 
127
  // register dynamic action to load a starter setup.
128
- add_action( 'admin_action_advanced_ads_starter_setup', array( $this, 'import_starter_setup' ) );
129
 
130
  Advanced_Ads_Admin_Meta_Boxes::get_instance();
131
  Advanced_Ads_Admin_Menu::get_instance();
@@ -142,8 +142,8 @@ class Advanced_Ads_Admin {
142
  // needed here in order to work with Quick Edit option on ad list page.
143
  Advanced_Ads_Admin_Ad_Type::get_instance();
144
 
145
- add_action( 'wp_ajax_advads_send_feedback', array( $this, 'send_feedback' ) );
146
- add_action( 'wp_ajax_advads_load_rss_widget_content', array( 'Advanced_Ads_Admin_Meta_Boxes', 'dashboard_widget_function_output' ) );
147
  }
148
 
149
  /**
@@ -182,8 +182,8 @@ class Advanced_Ads_Admin {
182
  * Register and enqueue admin-specific style sheet.
183
  */
184
  public function enqueue_admin_styles() {
185
- wp_enqueue_style( $this->plugin_slug . '-ui-styles', plugins_url( 'assets/css/ui.css', __FILE__ ), array(), ADVADS_VERSION );
186
- wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), array(), ADVADS_VERSION );
187
 
188
  $screen = get_current_screen();
189
  if ( ! $screen instanceof \WP_Screen ) {
@@ -191,7 +191,7 @@ class Advanced_Ads_Admin {
191
  }
192
 
193
  if ( $screen->post_type === Advanced_Ads::POST_TYPE_SLUG && $screen->base === 'post' ) {
194
- wp_enqueue_style( $this->plugin_slug . '-ad-positioning-styles', ADVADS_BASE_URL . '/modules/ad-positioning/assets/css/ad-positioning.css', array( $this->plugin_slug . '-admin-styles' ), ADVADS_VERSION );
195
  }
196
  }
197
 
@@ -201,26 +201,26 @@ class Advanced_Ads_Admin {
201
  public function enqueue_admin_scripts() {
202
 
203
  // global js script.
204
- wp_enqueue_script( $this->plugin_slug . '-admin-global-script', plugins_url( 'assets/js/admin-global.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
205
- wp_enqueue_script( $this->plugin_slug . '-admin-find-adblocker', plugins_url( 'assets/js/advertisement.js', __FILE__ ), array(), ADVADS_VERSION, false );
206
 
207
  // register ajax nonce.
208
- $params = array(
209
  'ajax_nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
210
- );
211
  wp_localize_script( $this->plugin_slug . '-admin-global-script', 'advadsglobal', $params );
212
 
213
  if ( self::screen_belongs_to_advanced_ads() ) {
214
- wp_register_script( $this->plugin_slug . '-ui-scripts', plugins_url( 'assets/js/ui.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
215
- wp_register_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array( 'jquery', $this->plugin_slug . '-ui-scripts', 'jquery-ui-autocomplete' ), ADVADS_VERSION, false );
216
- wp_register_script( $this->plugin_slug . '-conditions-script', plugins_url( 'assets/js/conditions.js', __FILE__ ), array( 'jquery', $this->plugin_slug . '-ui-scripts' ), ADVADS_VERSION, false );
217
- wp_register_script( $this->plugin_slug . '-wizard-script', plugins_url( 'assets/js/wizard.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
218
 
219
  // just register this script for later inclusion on ad group list page.
220
- wp_register_script( 'inline-edit-group-ads', plugins_url( 'assets/js/inline-edit-group-ads.js', __FILE__ ), array( 'jquery' ), ADVADS_VERSION, false );
221
 
222
  // register admin.js translations.
223
- $translation_array = array(
224
  'condition_or' => __( 'or', 'advanced-ads' ),
225
  'condition_and' => __( 'and', 'advanced-ads' ),
226
  'after_paragraph_promt' => __( 'After which paragraph?', 'advanced-ads' ),
@@ -239,7 +239,7 @@ class Advanced_Ads_Admin {
239
  'display_conditions_form_name' => Advanced_Ads_Display_Conditions::FORM_NAME, // not meant for translation.
240
  'delete_placement_confirmation' => __( 'Permanently delete this placement?', 'advanced-ads' ),
241
  'close' => __( 'Close', 'advanced-ads' ),
242
- );
243
 
244
  wp_localize_script( $this->plugin_slug . '-admin-script', 'advadstxt', $translation_array );
245
 
@@ -260,7 +260,7 @@ class Advanced_Ads_Admin {
260
  // in this case, the '_wpMediaViewsL10n' js object inside html will contain id of the post, that is necessary to view oEmbed priview inside tinyMCE editor.
261
  // since other plugins can call the 'wp_enqueue_media' function without the 'post' parameter, Advanced Ads should call it earlier.
262
  global $post;
263
- wp_enqueue_media( array( 'post' => $post ) );
264
  }
265
 
266
  // single ad edit screen.
@@ -268,7 +268,7 @@ class Advanced_Ads_Admin {
268
  wp_enqueue_script(
269
  $this->plugin_slug . '-ad-positioning-script',
270
  ADVADS_BASE_URL . '/modules/ad-positioning/assets/js/ad-positioning.js',
271
- array(),
272
  ADVADS_VERSION,
273
  true
274
  );
@@ -292,7 +292,7 @@ class Advanced_Ads_Admin {
292
 
293
  $advads_pages = apply_filters(
294
  'advanced-ads-dashboard-screens',
295
- array(
296
  'advanced-ads_page_advanced-ads-groups', // ad groups.
297
  'edit-advanced_ads', // ads overview.
298
  'advanced_ads', // ad edit page.
@@ -302,7 +302,7 @@ class Advanced_Ads_Admin {
302
  'admin_page_advanced-ads-debug', // debug.
303
  // 'advanced-ads_page_advanced-ads-support', // support.
304
  'admin_page_advanced-ads-import-export', // import & export.
305
- )
306
  );
307
 
308
  if ( in_array( $screen->id, $advads_pages, true ) ) {
@@ -365,7 +365,7 @@ class Advanced_Ads_Admin {
365
  }
366
 
367
  // register our own notices.
368
- add_action( 'admin_notices', array( $this, 'admin_notices' ) );
369
  }
370
 
371
  /**
@@ -385,7 +385,7 @@ class Advanced_Ads_Admin {
385
 
386
  // Show success notice after starter setup was imported. Registered here because it will be visible only once.
387
  if ( isset( $_GET['message'] ) && 'advanced-ads-starter-setup-success' === $_GET['message'] ) {
388
- add_action( 'advanced-ads-admin-notices', array( $this, 'starter_setup_success_message' ) );
389
  }
390
 
391
  // register our own notices on Advanced Ads pages, except from the overview page where they should appear in the notices section.
@@ -438,7 +438,7 @@ class Advanced_Ads_Admin {
438
  */
439
  public function add_deactivation_logic() {
440
  $screen = get_current_screen();
441
- if ( ! isset( $screen->id ) || ! in_array( $screen->id, array( 'plugins', 'plugins-network' ), true ) ) {
442
  return;
443
  }
444
 
@@ -483,7 +483,7 @@ class Advanced_Ads_Admin {
483
 
484
  $text .= "\n\n" . home_url() . " ($installed)";
485
 
486
- $headers = array();
487
 
488
  $from = isset( $form['advanced_ads_disable_from'] ) ? $form['advanced_ads_disable_from'] : '';
489
  // the user clicked on the "don’t disable" button or if an address is given in the form then use that one.
@@ -600,15 +600,15 @@ class Advanced_Ads_Admin {
600
  return $result;
601
  }
602
 
603
- $query_args = array(
604
  'slug' => 'advanced-ads-adsense-in-feed',
605
- 'fields' => array(
606
  'icons' => true,
607
  'active_installs' => true,
608
  'short_description' => true,
609
  'group' => true,
610
- ),
611
- );
612
  $plugin_data = plugins_api( 'plugin_information', $query_args );
613
 
614
  if ( ! is_wp_error( $plugin_data ) ) {
@@ -632,15 +632,15 @@ class Advanced_Ads_Admin {
632
  return $result;
633
  }
634
 
635
- $query_args = array(
636
  'slug' => 'advanced-ads-genesis',
637
- 'fields' => array(
638
  'icons' => true,
639
  'active_installs' => true,
640
  'short_description' => true,
641
  'group' => true,
642
- ),
643
- );
644
  $plugin_data = plugins_api( 'plugin_information', $query_args );
645
 
646
  if ( ! is_wp_error( $plugin_data ) ) {
@@ -664,15 +664,15 @@ class Advanced_Ads_Admin {
664
  return $result;
665
  }
666
 
667
- $query_args = array(
668
  'slug' => 'ads-for-visual-composer',
669
- 'fields' => array(
670
  'icons' => true,
671
  'active_installs' => true,
672
  'short_description' => true,
673
  'group' => true,
674
- ),
675
- );
676
  $plugin_data = plugins_api( 'plugin_information', $query_args );
677
 
678
  if ( ! is_wp_error( $plugin_data ) ) {
@@ -734,9 +734,9 @@ class Advanced_Ads_Admin {
734
 
735
  // load link to latest post.
736
 
737
- $args = array(
738
  'numberposts' => 1,
739
- );
740
  $last_post = get_posts( $args );
741
  $last_post_link = isset( $last_post[0]->ID ) ? get_permalink( $last_post[0]->ID ) : false;
742
 
@@ -753,7 +753,7 @@ class Advanced_Ads_Admin {
753
  self::$admin_settings = get_user_meta( get_current_user_id(), 'advanced-ads-admin-settings', true );
754
 
755
  if ( ! is_array( self::$admin_settings ) ) {
756
- self::$admin_settings = array();
757
  }
758
  }
759
  return self::$admin_settings;
@@ -783,6 +783,7 @@ class Advanced_Ads_Admin {
783
  $manual_url = 'manual/';
784
  $new_button_id = '';
785
  $new_button_label = '';
 
786
  $show_filter_button = false;
787
  $reset_href = '';
788
  $filter_disabled = '';
@@ -809,7 +810,7 @@ class Advanced_Ads_Admin {
809
  case 'advanced-ads_page_advanced-ads-groups': // ad groups
810
  $title = __( 'Your Groups', 'advanced-ads' );
811
  $new_button_label = __( 'New Ad Group', 'advanced-ads' );
812
- $new_button_href = '#';
813
  $new_button_id = 'advads-new-ad-group-link';
814
  $manual_url = 'manual/rotate-ad/';
815
  $show_filter_button = empty( $_GET['s'] );
55
  private function __construct() {
56
  if ( wp_doing_ajax() ) {
57
  new Advanced_Ads_Ad_Ajax_Callbacks();
58
+ add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded_ajax' ] );
59
  } else {
60
+ add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ] );
61
+ add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ], 100 );
62
  Advanced_Ads_Ad_List_Filters::get_instance();
63
  }
64
  // add shortcode creator to TinyMCE.
99
  $plugin = Advanced_Ads::get_instance();
100
  $this->plugin_slug = $plugin->get_plugin_slug();
101
 
102
+ add_action( 'current_screen', [ $this, 'current_screen' ] );
103
 
104
  // Load admin style sheet and JavaScript.
105
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_styles' ] );
106
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_admin_scripts' ], 9 );
107
 
108
  // update placements.
109
+ add_action( 'admin_init', [ 'Advanced_Ads_Placements', 'update_placements' ] );
110
 
111
  // add Advanced Ads admin notices
112
  // removes admin notices from other plugins
113
  // `in_admin_header` is the last hook to run before àdmin_notices` according to https://codex.wordpress.org/Plugin_API/Action_Reference.
114
+ add_action( 'in_admin_header', [ $this, 'register_admin_notices' ] );
115
 
116
  // add links to plugin page.
117
+ add_filter( 'plugin_action_links_' . ADVADS_BASE, [ $this, 'add_plugin_links' ] );
118
 
119
  // display information when user is going to disable the plugin.
120
+ add_filter( 'admin_footer', [ $this, 'add_deactivation_logic' ] );
121
  // add_filter( 'after_plugin_row_' . ADVADS_BASE, array( $this, 'display_deactivation_message' ) );
122
  // disable adding rel="noopener noreferrer" to link added through TinyMCE for rich content ads.
123
+ add_filter( 'tiny_mce_before_init', [ $this, 'tinymce_allow_unsafe_link_target' ] );
124
 
125
+ add_action( 'plugins_api_result', [ $this, 'recommend_suitable_add_ons' ], 11, 3 );
126
 
127
  // register dynamic action to load a starter setup.
128
+ add_action( 'admin_action_advanced_ads_starter_setup', [ $this, 'import_starter_setup' ] );
129
 
130
  Advanced_Ads_Admin_Meta_Boxes::get_instance();
131
  Advanced_Ads_Admin_Menu::get_instance();
142
  // needed here in order to work with Quick Edit option on ad list page.
143
  Advanced_Ads_Admin_Ad_Type::get_instance();
144
 
145
+ add_action( 'wp_ajax_advads_send_feedback', [ $this, 'send_feedback' ] );
146
+ add_action( 'wp_ajax_advads_load_rss_widget_content', [ 'Advanced_Ads_Admin_Meta_Boxes', 'dashboard_widget_function_output' ] );
147
  }
148
 
149
  /**
182
  * Register and enqueue admin-specific style sheet.
183
  */
184
  public function enqueue_admin_styles() {
185
+ wp_enqueue_style( $this->plugin_slug . '-ui-styles', plugins_url( 'assets/css/ui.css', __FILE__ ), [], ADVADS_VERSION );
186
+ wp_enqueue_style( $this->plugin_slug . '-admin-styles', plugins_url( 'assets/css/admin.css', __FILE__ ), [], ADVADS_VERSION );
187
 
188
  $screen = get_current_screen();
189
  if ( ! $screen instanceof \WP_Screen ) {
191
  }
192
 
193
  if ( $screen->post_type === Advanced_Ads::POST_TYPE_SLUG && $screen->base === 'post' ) {
194
+ wp_enqueue_style( $this->plugin_slug . '-ad-positioning-styles', ADVADS_BASE_URL . '/modules/ad-positioning/assets/css/ad-positioning.css', [ $this->plugin_slug . '-admin-styles' ], ADVADS_VERSION );
195
  }
196
  }
197
 
201
  public function enqueue_admin_scripts() {
202
 
203
  // global js script.
204
+ wp_enqueue_script( $this->plugin_slug . '-admin-global-script', plugins_url( 'assets/js/admin-global.js', __FILE__ ), [ 'jquery' ], ADVADS_VERSION, false );
205
+ wp_enqueue_script( $this->plugin_slug . '-admin-find-adblocker', plugins_url( 'assets/js/advertisement.js', __FILE__ ), [], ADVADS_VERSION, false );
206
 
207
  // register ajax nonce.
208
+ $params = [
209
  'ajax_nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
210
+ ];
211
  wp_localize_script( $this->plugin_slug . '-admin-global-script', 'advadsglobal', $params );
212
 
213
  if ( self::screen_belongs_to_advanced_ads() ) {
214
+ wp_register_script( $this->plugin_slug . '-ui-scripts', plugins_url( 'assets/js/ui.js', __FILE__ ), [ 'jquery' ], ADVADS_VERSION, false );
215
+ wp_register_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), [ 'jquery', $this->plugin_slug . '-ui-scripts', 'jquery-ui-autocomplete' ], ADVADS_VERSION, false );
216
+ wp_register_script( $this->plugin_slug . '-conditions-script', plugins_url( 'assets/js/conditions.js', __FILE__ ), [ 'jquery', $this->plugin_slug . '-ui-scripts' ], ADVADS_VERSION, false );
217
+ wp_register_script( $this->plugin_slug . '-wizard-script', plugins_url( 'assets/js/wizard.js', __FILE__ ), [ 'jquery' ], ADVADS_VERSION, false );
218
 
219
  // just register this script for later inclusion on ad group list page.
220
+ wp_register_script( 'inline-edit-group-ads', plugins_url( 'assets/js/inline-edit-group-ads.js', __FILE__ ), [ 'jquery' ], ADVADS_VERSION, false );
221
 
222
  // register admin.js translations.
223
+ $translation_array = [
224
  'condition_or' => __( 'or', 'advanced-ads' ),
225
  'condition_and' => __( 'and', 'advanced-ads' ),
226
  'after_paragraph_promt' => __( 'After which paragraph?', 'advanced-ads' ),
239
  'display_conditions_form_name' => Advanced_Ads_Display_Conditions::FORM_NAME, // not meant for translation.
240
  'delete_placement_confirmation' => __( 'Permanently delete this placement?', 'advanced-ads' ),
241
  'close' => __( 'Close', 'advanced-ads' ),
242
+ ];
243
 
244
  wp_localize_script( $this->plugin_slug . '-admin-script', 'advadstxt', $translation_array );
245
 
260
  // in this case, the '_wpMediaViewsL10n' js object inside html will contain id of the post, that is necessary to view oEmbed priview inside tinyMCE editor.
261
  // since other plugins can call the 'wp_enqueue_media' function without the 'post' parameter, Advanced Ads should call it earlier.
262
  global $post;
263
+ wp_enqueue_media( [ 'post' => $post ] );
264
  }
265
 
266
  // single ad edit screen.
268
  wp_enqueue_script(
269
  $this->plugin_slug . '-ad-positioning-script',
270
  ADVADS_BASE_URL . '/modules/ad-positioning/assets/js/ad-positioning.js',
271
+ [],
272
  ADVADS_VERSION,
273
  true
274
  );
292
 
293
  $advads_pages = apply_filters(
294
  'advanced-ads-dashboard-screens',
295
+ [
296
  'advanced-ads_page_advanced-ads-groups', // ad groups.
297
  'edit-advanced_ads', // ads overview.
298
  'advanced_ads', // ad edit page.
302
  'admin_page_advanced-ads-debug', // debug.
303
  // 'advanced-ads_page_advanced-ads-support', // support.
304
  'admin_page_advanced-ads-import-export', // import & export.
305
+ ]
306
  );
307
 
308
  if ( in_array( $screen->id, $advads_pages, true ) ) {
365
  }
366
 
367
  // register our own notices.
368
+ add_action( 'admin_notices', [ $this, 'admin_notices' ] );
369
  }
370
 
371
  /**
385
 
386
  // Show success notice after starter setup was imported. Registered here because it will be visible only once.
387
  if ( isset( $_GET['message'] ) && 'advanced-ads-starter-setup-success' === $_GET['message'] ) {
388
+ add_action( 'advanced-ads-admin-notices', [ $this, 'starter_setup_success_message' ] );
389
  }
390
 
391
  // register our own notices on Advanced Ads pages, except from the overview page where they should appear in the notices section.
438
  */
439
  public function add_deactivation_logic() {
440
  $screen = get_current_screen();
441
+ if ( ! isset( $screen->id ) || ! in_array( $screen->id, [ 'plugins', 'plugins-network' ], true ) ) {
442
  return;
443
  }
444
 
483
 
484
  $text .= "\n\n" . home_url() . " ($installed)";
485
 
486
+ $headers = [];
487
 
488
  $from = isset( $form['advanced_ads_disable_from'] ) ? $form['advanced_ads_disable_from'] : '';
489
  // the user clicked on the "don’t disable" button or if an address is given in the form then use that one.
600
  return $result;
601
  }
602
 
603
+ $query_args = [
604
  'slug' => 'advanced-ads-adsense-in-feed',
605
+ 'fields' => [
606
  'icons' => true,
607
  'active_installs' => true,
608
  'short_description' => true,
609
  'group' => true,
610
+ ],
611
+ ];
612
  $plugin_data = plugins_api( 'plugin_information', $query_args );
613
 
614
  if ( ! is_wp_error( $plugin_data ) ) {
632
  return $result;
633
  }
634
 
635
+ $query_args = [
636
  'slug' => 'advanced-ads-genesis',
637
+ 'fields' => [
638
  'icons' => true,
639
  'active_installs' => true,
640
  'short_description' => true,
641
  'group' => true,
642
+ ],
643
+ ];
644
  $plugin_data = plugins_api( 'plugin_information', $query_args );
645
 
646
  if ( ! is_wp_error( $plugin_data ) ) {
664
  return $result;
665
  }
666
 
667
+ $query_args = [
668
  'slug' => 'ads-for-visual-composer',
669
+ 'fields' => [
670
  'icons' => true,
671
  'active_installs' => true,
672
  'short_description' => true,
673
  'group' => true,
674
+ ],
675
+ ];
676
  $plugin_data = plugins_api( 'plugin_information', $query_args );
677
 
678
  if ( ! is_wp_error( $plugin_data ) ) {
734
 
735
  // load link to latest post.
736
 
737
+ $args = [
738
  'numberposts' => 1,
739
+ ];
740
  $last_post = get_posts( $args );
741
  $last_post_link = isset( $last_post[0]->ID ) ? get_permalink( $last_post[0]->ID ) : false;
742
 
753
  self::$admin_settings = get_user_meta( get_current_user_id(), 'advanced-ads-admin-settings', true );
754
 
755
  if ( ! is_array( self::$admin_settings ) ) {
756
+ self::$admin_settings = [];
757
  }
758
  }
759
  return self::$admin_settings;
783
  $manual_url = 'manual/';
784
  $new_button_id = '';
785
  $new_button_label = '';
786
+ $new_button_href = '';
787
  $show_filter_button = false;
788
  $reset_href = '';
789
  $filter_disabled = '';
810
  case 'advanced-ads_page_advanced-ads-groups': // ad groups
811
  $title = __( 'Your Groups', 'advanced-ads' );
812
  $new_button_label = __( 'New Ad Group', 'advanced-ads' );
813
+ $new_button_href = '#modal-group-new';
814
  $new_button_id = 'advads-new-ad-group-link';
815
  $manual_url = 'manual/rotate-ad/';
816
  $show_filter_button = empty( $_GET['s'] );
admin/includes/ad-authors.php CHANGED
@@ -15,9 +15,9 @@ class Advanced_Ads_Ad_Authors {
15
  * Attach callbacks to hooks and filters.
16
  */
17
  private function __construct() {
18
- add_filter( 'wp_dropdown_users_args', array( $this, 'filter_ad_authors' ) );
19
- add_action( 'pre_post_update', array( $this, 'sanitize_author_saving' ), 10, 2 );
20
- add_filter( 'map_meta_cap', array( $this, 'filter_editable_posts' ), 10, 4 );
21
  }
22
 
23
  /**
@@ -76,7 +76,7 @@ class Advanced_Ads_Ad_Authors {
76
  }
77
 
78
  $options = Advanced_Ads::get_instance()->options();
79
- $allowed_roles = isset( $options['allow-unfiltered-html'] ) ? $options['allow-unfiltered-html'] : array();
80
 
81
  // if the current user can unfiltered_html, return the default args.
82
  if ( ! empty( array_intersect( wp_get_current_user()->roles, $allowed_roles ) ) ) {
@@ -115,7 +115,7 @@ class Advanced_Ads_Ad_Authors {
115
  return;
116
  }
117
 
118
- $user_query = new WP_User_Query( $this->filter_ad_authors( array( 'fields' => 'ID' ) ) );
119
  if ( ! in_array( (int) $data['post_author'], array_map( 'intval', $user_query->get_results() ), true ) ) {
120
  wp_die( esc_html__( 'Sorry, you\'re not allowed to assign this user.', 'advanced-ads' ) );
121
  }
@@ -153,7 +153,7 @@ class Advanced_Ads_Ad_Authors {
153
 
154
  static $user_query;
155
  if ( $user_query === null ) {
156
- $user_query = new WP_User_Query( $this->filter_ad_authors( array( 'fields' => 'ID' ) ) );
157
  }
158
 
159
  if ( ! in_array( $author_id, array_map( 'intval', $user_query->get_results() ), true ) ) {
15
  * Attach callbacks to hooks and filters.
16
  */
17
  private function __construct() {
18
+ add_filter( 'wp_dropdown_users_args', [ $this, 'filter_ad_authors' ] );
19
+ add_action( 'pre_post_update', [ $this, 'sanitize_author_saving' ], 10, 2 );
20
+ add_filter( 'map_meta_cap', [ $this, 'filter_editable_posts' ], 10, 4 );
21
  }
22
 
23
  /**
76
  }
77
 
78
  $options = Advanced_Ads::get_instance()->options();
79
+ $allowed_roles = isset( $options['allow-unfiltered-html'] ) ? $options['allow-unfiltered-html'] : [];
80
 
81
  // if the current user can unfiltered_html, return the default args.
82
  if ( ! empty( array_intersect( wp_get_current_user()->roles, $allowed_roles ) ) ) {
115
  return;
116
  }
117
 
118
+ $user_query = new WP_User_Query( $this->filter_ad_authors( [ 'fields' => 'ID' ] ) );
119
  if ( ! in_array( (int) $data['post_author'], array_map( 'intval', $user_query->get_results() ), true ) ) {
120
  wp_die( esc_html__( 'Sorry, you\'re not allowed to assign this user.', 'advanced-ads' ) );
121
  }
153
 
154
  static $user_query;
155
  if ( $user_query === null ) {
156
+ $user_query = new WP_User_Query( $this->filter_ad_authors( [ 'fields' => 'ID' ] ) );
157
  }
158
 
159
  if ( ! in_array( $author_id, array_map( 'intval', $user_query->get_results() ), true ) ) {
admin/includes/ad-health-notices.php CHANGED
@@ -23,10 +23,10 @@
23
  */
24
  $advanced_ads_ad_health_notices = apply_filters(
25
  'advanced-ads-ad-health-notices',
26
- array(
27
  // old PHP version
28
  // checked using Advanced_Ads_Checks::php_version_minimum().
29
- 'old_php' => array(
30
  'text' => sprintf(
31
  // translators: %1$s is a version number.
32
  __( 'Your <strong>PHP version (%1$s) is too low</strong>. Advanced Ads is built for PHP %2$s and higher. It might work, but updating PHP is highly recommended. Please ask your hosting provider for more information.', 'advanced-ads' ),
@@ -34,10 +34,10 @@ $advanced_ads_ad_health_notices = apply_filters(
34
  Advanced_Ads_Checks::MINIMUM_PHP_VERSION
35
  ),
36
  'type' => 'problem',
37
- ),
38
  // conflicting plugins found
39
  // Advanced_Ads_Checks::conflicting_plugins().
40
- 'conflicting_plugins' => array(
41
  'text' => sprintf(
42
  // translators: %1$s is a list of plugin names; %2$s a target URL.
43
  __( 'Plugins that are known to cause (partial) problems: <strong>%1$s</strong>. <a href="%2$s" target="_blank">Learn more</a>.', 'advanced-ads' ),
@@ -45,36 +45,36 @@ $advanced_ads_ad_health_notices = apply_filters(
45
  ADVADS_URL . 'manual/known-plugin-conflicts/?utm_source=advanced-ads&utm_medium=link&utm_campaign=error-plugin-conflicts'
46
  ),
47
  'type' => 'problem',
48
- ),
49
  // PHP extensions missing
50
  // Advanced_Ads_Checks::php_extensions().
51
- 'php_extensions_missing' => array(
52
  'text' => sprintf(
53
  // translators: %s is a list of PHP extensions.
54
  __( 'Missing PHP extensions could cause issues. Please ask your hosting provider to enable them: %s', 'advanced-ads' ),
55
  implode( ', ', Advanced_Ads_Checks::php_extensions() )
56
  ),
57
  'type' => 'problem',
58
- ),
59
  // ads are disabled
60
  // Advanced_Ads_Checks::ads_disabled().
61
- 'ads_disabled' => array(
62
  'text' => sprintf(
63
  // translators: %s is a target URL.
64
  __( 'Ads are disabled for all or some pages. See "disabled ads" in <a href="%s">settings</a>.', 'advanced-ads' ),
65
  admin_url( 'admin.php?page=advanced-ads-settings#top#general' )
66
  ),
67
  'type' => 'problem',
68
- ),
69
  // check if Advanced Ads related constants are enabled
70
  // Advanced_Ads_Checks::get_defined_constants().
71
- 'constants_enabled' => array(
72
  'text' => '<a href="' . admin_url( 'admin.php?page=advanced-ads-settings#top#support' ) . '">' . esc_html__( 'Advanced Ads related constants enabled', 'advanced-ads' ) . '</a>',
73
  'type' => 'notice',
74
- ),
75
  // adblocker assets expired
76
  // Advanced_Ads_Checks::assets_expired().
77
- 'assets_expired' => array(
78
  'text' => sprintf(
79
  // translators: %s is a target URL.
80
  __( 'Some assets were changed. Please <strong>rebuild the asset folder</strong> in the <a href="%s">Advanced Ads settings</a> to update the ad blocker disguise.', 'advanced-ads' ),
@@ -82,10 +82,10 @@ $advanced_ads_ad_health_notices = apply_filters(
82
  ),
83
  'type' => 'problem',
84
  'hide' => true,
85
- ),
86
  // missing license codes
87
  // Advanced_Ads_Checks::license_invalid().
88
- 'license_invalid' => array(
89
  'text' => __( 'One or more license keys for <strong>Advanced Ads add-ons are invalid or missing</strong>.', 'advanced-ads' ) . ' '
90
  . sprintf(
91
  // translators: %s is a target URL.
@@ -95,16 +95,16 @@ $advanced_ads_ad_health_notices = apply_filters(
95
  'type' => 'problem',
96
  'hide' => false,
97
  'timeout' => WEEK_IN_SECONDS,
98
- ),
99
  // an individual ad expired.
100
- 'ad_expired' => array(
101
  'text' => __( 'Ad expired', 'advanced-ads' ) . ': ',
102
  'type' => 'notice',
103
  'hide' => false,
104
- ),
105
  // a visible ad is used in <head> tags
106
  // is checked in the frontend by Ad Health in Advanced_Ads_Frontend_Checks::can_use_head_placement().
107
- 'ad_with_output_in_head' => array(
108
  // we keep the %s here and replace it with an empty string, because we use it somewhere else and don’t want to create a new string that is basically the same.
109
  'text' => sprintf(
110
  // translators: %s is empty here, but the string will be followed by a name of an ad unit.
@@ -115,29 +115,29 @@ $advanced_ads_ad_health_notices = apply_filters(
115
  'hide' => false,
116
  'get_help_link' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=error-visible-ad-in-header#header-ads',
117
  'timeout' => YEAR_IN_SECONDS,
118
- ),
119
  // Ad has HTTP, but site uses HTTPS
120
  // check in Ad Health in frontend.
121
- 'ad_has_http' => array(
122
  'text' => __( 'Your website is using HTTPS, but the ad code contains HTTP and might not work.', 'advanced-ads' ),
123
  'type' => 'notice',
124
  'hide' => false,
125
  'get_help_link' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=error-https-ads#https-ads',
126
- ),
127
  // dummy text for general AdSense issue.
128
- 'adsense_issue' => array(
129
  // we keep the %s here and replace it with an empty string, because we use it somewhere else and don’t want to create a new string that is basically the same.
130
  'text' => __( 'AdSense issue' ),
131
  'type' => 'problem',
132
- ),
133
  // AdSense connection error: disapproved account.
134
- 'adsense_connect_disapprovedAccount' => array(
135
  'text' => __( 'Last AdSense account connection attempt failed.', 'advanced-ads' ) . '&nbsp;' . __( 'Your account was not approved by AdSense.', 'advance-ads' ) . ' ' . Advanced_Ads_Ad_Health_Notices::get_adsense_error_link( 'disapprovedAccount' ),
136
  'type' => 'problem',
137
  'hide' => false,
138
- ),
139
  // AdSense connection error: no adsense account.
140
- 'adsense_connect_noAdSenseAccount' => array(
141
  'text' => sprintf(
142
  __( 'Last AdSense account connection attempt failed.', 'advanced-ads' ) . '&nbsp;' .
143
  // translators: %1$s is the opening a tag and %2$s the closing one.
@@ -147,9 +147,9 @@ $advanced_ads_ad_health_notices = apply_filters(
147
  ),
148
  'type' => 'problem',
149
  'hide' => false,
150
- ),
151
  // AdSense account alert. Missing ads.txt – version 1.
152
- 'adsense_alert_ALERT_TYPE_ADS_TXT_UNAUTHORIZED' => array(
153
  'text' => sprintf(
154
  __( 'One of your sites is missing the AdSense publisher ID in the ads.txt file.', 'advanced-ads' )
155
  . ' <a class="advads-settings-link" href="%s">'
@@ -157,9 +157,9 @@ $advanced_ads_ad_health_notices = apply_filters(
157
  admin_url( 'admin.php?page=advanced-ads-settings#general__advads-ads-txt' )
158
  ) . ' ' . Advanced_Ads_Ad_Health_Notices::get_adsense_error_link( 'ALERT_TYPE_ADS_TXT_UNAUTHORIZED' ),
159
  'type' => 'problem',
160
- ),
161
  // AdSense account alert. . Missing ads.txt – version 2.
162
- 'adsense_alert_ADS_TXT_MISSING' => array(
163
  'text' => sprintf(
164
  __( 'One of your sites is missing the AdSense publisher ID in the ads.txt file.', 'advanced-ads' )
165
  . ' <a class="advads-settings-link" href="%s">'
@@ -167,9 +167,9 @@ $advanced_ads_ad_health_notices = apply_filters(
167
  admin_url( 'admin.php?page=advanced-ads-settings#general__advads-ads-txt' )
168
  ) . ' ' . Advanced_Ads_Ad_Health_Notices::get_adsense_error_link( 'ADS_TXT_MISSING' ),
169
  'type' => 'problem',
170
- ),
171
  // AdSense account alert. . Missing ads.txt – version 3.
172
- 'adsense_alert_ADS_TXT_ISSUES' => array(
173
  'text' => sprintf(
174
  __( 'One of your sites is missing the AdSense publisher ID in the ads.txt file.', 'advanced-ads' )
175
  . ' <a class="advads-settings-link" href="%s">'
@@ -177,16 +177,16 @@ $advanced_ads_ad_health_notices = apply_filters(
177
  admin_url( 'admin.php?page=advanced-ads-settings#general__advads-ads-txt' )
178
  ) . ' ' . Advanced_Ads_Ad_Health_Notices::get_adsense_error_link( 'ADS_TXT_ISSUES' ),
179
  'type' => 'problem',
180
- ),
181
  // AdSense deprecated link units
182
- 'adsense_link_units_deprecated' => array(
183
  'text' => __( 'Google AdSense deprecated Link Units. Please choose another format.', 'advanced-ads' )
184
  . ' <a href="' . esc_url( ADVADS_URL ) . 'adsense-link-units/" target="_blank" rel="noopener">'
185
  . esc_html__( 'Learn more', 'advanced-ads' )
186
  . '</a>',
187
  'type' => 'problem',
188
- ),
189
- 'nested_the_content_filters' => array(
190
  'text' => sprintf(
191
  // translators: %s is a filter hook, here `the_content`.
192
  __( '<strong>%s</strong> filter found multiple times.', 'advanced-ads' ),
@@ -195,9 +195,9 @@ $advanced_ads_ad_health_notices = apply_filters(
195
  'get_help_link' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=error-multiple-the-content#the_content_filter_found_multiple_times',
196
  'type' => 'notice',
197
  'hide' => false,
198
- ),
199
  // BuddyPress or BuddyBoss installed.
200
- 'buddypress_no_pro' => array(
201
  'text' => sprintf(
202
  // translators: %1$s is a plugin name, %2$s is the opening a tag and %3$s the closing one.
203
  __( 'Learn how to integrate %1$s with Advanced Ads %2$shere%3$s.', 'advanced-ads' ),
@@ -206,9 +206,9 @@ $advanced_ads_ad_health_notices = apply_filters(
206
  '</a>'
207
  ),
208
  'type' => 'notice',
209
- ),
210
  // bbPress installed.
211
- 'bbpress_no_pro' => array(
212
  'text' => sprintf(
213
  // translators: %1$s is a plugin name, %2$s is the opening a tag and %3$s the closing one.
214
  __( 'Learn how to integrate %1$s with Advanced Ads %2$shere%3$s.', 'advanced-ads' ),
@@ -217,9 +217,9 @@ $advanced_ads_ad_health_notices = apply_filters(
217
  '</a>'
218
  ),
219
  'type' => 'notice',
220
- ),
221
  // WPML plugin activated.
222
- 'WPML_active' => array(
223
  'text' => sprintf(
224
  // translators: %1$s is a plugin name, %2$s is the opening a tag and %3$s the closing one.
225
  __( 'Learn how to integrate %1$s with Advanced Ads %2$shere%3$s.', 'advanced-ads' ),
@@ -230,9 +230,9 @@ $advanced_ads_ad_health_notices = apply_filters(
230
  'type' => 'notice',
231
  'hide' => false,
232
  'timeout' => YEAR_IN_SECONDS,
233
- ),
234
  // AMP and Accelerated Mobile Pages plugins.
235
- 'AMP_active' => array(
236
  'text' => sprintf(
237
  // translators: %1$s is a plugin name, %2$s is the opening a tag and %3$s the closing one.
238
  __( 'Learn how to integrate %1$s with Advanced Ads %2$shere%3$s.', 'advanced-ads' ),
@@ -243,10 +243,10 @@ $advanced_ads_ad_health_notices = apply_filters(
243
  'type' => 'notice',
244
  'hide' => false,
245
  'timeout' => YEAR_IN_SECONDS,
246
- ),
247
  // Hosting on WP Engine
248
  // Advanced_Ads_Checks::wp_engine_hosting().
249
- 'wpengine' => array(
250
  'text' => sprintf(
251
  // translators: %s is a service or plugin name.
252
  '<strong>' . __( '%s detected.', 'advanced-ads' ) . '</strong>'
@@ -256,10 +256,10 @@ $advanced_ads_ad_health_notices = apply_filters(
256
  'type' => 'notice',
257
  'hide' => false,
258
  'timeout' => YEAR_IN_SECONDS,
259
- ),
260
  // Notice about existing ads.txt plugins.
261
  // Advanced_Ads_Checks::ads_txt_plugins().
262
- 'ads_txt_plugins_enabled' => array(
263
  'text' => sprintf(
264
  __( 'Advanced Ads handles your ads.txt file automatically. You might be able to <strong>remove %1$s</strong>.', 'advanced-ads' ),
265
  implode( ', ', Advanced_Ads_Checks::ads_txt_plugins() )
@@ -267,10 +267,10 @@ $advanced_ads_ad_health_notices = apply_filters(
267
  'type' => 'notice',
268
  'hide' => false,
269
  'timeout' => YEAR_IN_SECONDS,
270
- ),
271
  // Notice about plugins that add header or footer code.
272
  // Advanced_Ads_Checks::header_footer_plugins().
273
- 'header_footer_plugins_enabled' => array(
274
  'text' =>
275
  __( 'Advanced Ads handles header and footer codes.', 'advanced-ads' ) . '&nbsp;' .
276
  sprintf( __( 'You might be able to <strong>remove %1$s</strong>.', 'advanced-ads' ),
@@ -280,6 +280,6 @@ $advanced_ads_ad_health_notices = apply_filters(
280
  'type' => 'notice',
281
  'hide' => false,
282
  'timeout' => YEAR_IN_SECONDS,
283
- ),
284
- )
285
  );
23
  */
24
  $advanced_ads_ad_health_notices = apply_filters(
25
  'advanced-ads-ad-health-notices',
26
+ [
27
  // old PHP version
28
  // checked using Advanced_Ads_Checks::php_version_minimum().
29
+ 'old_php' => [
30
  'text' => sprintf(
31
  // translators: %1$s is a version number.
32
  __( 'Your <strong>PHP version (%1$s) is too low</strong>. Advanced Ads is built for PHP %2$s and higher. It might work, but updating PHP is highly recommended. Please ask your hosting provider for more information.', 'advanced-ads' ),
34
  Advanced_Ads_Checks::MINIMUM_PHP_VERSION
35
  ),
36
  'type' => 'problem',
37
+ ],
38
  // conflicting plugins found
39
  // Advanced_Ads_Checks::conflicting_plugins().
40
+ 'conflicting_plugins' => [
41
  'text' => sprintf(
42
  // translators: %1$s is a list of plugin names; %2$s a target URL.
43
  __( 'Plugins that are known to cause (partial) problems: <strong>%1$s</strong>. <a href="%2$s" target="_blank">Learn more</a>.', 'advanced-ads' ),
45
  ADVADS_URL . 'manual/known-plugin-conflicts/?utm_source=advanced-ads&utm_medium=link&utm_campaign=error-plugin-conflicts'
46
  ),
47
  'type' => 'problem',
48
+ ],
49
  // PHP extensions missing
50
  // Advanced_Ads_Checks::php_extensions().
51
+ 'php_extensions_missing' => [
52
  'text' => sprintf(
53
  // translators: %s is a list of PHP extensions.
54
  __( 'Missing PHP extensions could cause issues. Please ask your hosting provider to enable them: %s', 'advanced-ads' ),
55
  implode( ', ', Advanced_Ads_Checks::php_extensions() )
56
  ),
57
  'type' => 'problem',
58
+ ],
59
  // ads are disabled
60
  // Advanced_Ads_Checks::ads_disabled().
61
+ 'ads_disabled' => [
62
  'text' => sprintf(
63
  // translators: %s is a target URL.
64
  __( 'Ads are disabled for all or some pages. See "disabled ads" in <a href="%s">settings</a>.', 'advanced-ads' ),
65
  admin_url( 'admin.php?page=advanced-ads-settings#top#general' )
66
  ),
67
  'type' => 'problem',
68
+ ],
69
  // check if Advanced Ads related constants are enabled
70
  // Advanced_Ads_Checks::get_defined_constants().
71
+ 'constants_enabled' => [
72
  'text' => '<a href="' . admin_url( 'admin.php?page=advanced-ads-settings#top#support' ) . '">' . esc_html__( 'Advanced Ads related constants enabled', 'advanced-ads' ) . '</a>',
73
  'type' => 'notice',
74
+ ],
75
  // adblocker assets expired
76
  // Advanced_Ads_Checks::assets_expired().
77
+ 'assets_expired' => [
78
  'text' => sprintf(
79
  // translators: %s is a target URL.
80
  __( 'Some assets were changed. Please <strong>rebuild the asset folder</strong> in the <a href="%s">Advanced Ads settings</a> to update the ad blocker disguise.', 'advanced-ads' ),
82
  ),
83
  'type' => 'problem',
84
  'hide' => true,
85
+ ],
86
  // missing license codes
87
  // Advanced_Ads_Checks::license_invalid().
88
+ 'license_invalid' => [
89
  'text' => __( 'One or more license keys for <strong>Advanced Ads add-ons are invalid or missing</strong>.', 'advanced-ads' ) . ' '
90
  . sprintf(
91
  // translators: %s is a target URL.
95
  'type' => 'problem',
96
  'hide' => false,
97
  'timeout' => WEEK_IN_SECONDS,
98
+ ],
99
  // an individual ad expired.
100
+ 'ad_expired' => [
101
  'text' => __( 'Ad expired', 'advanced-ads' ) . ': ',
102
  'type' => 'notice',
103
  'hide' => false,
104
+ ],
105
  // a visible ad is used in <head> tags
106
  // is checked in the frontend by Ad Health in Advanced_Ads_Frontend_Checks::can_use_head_placement().
107
+ 'ad_with_output_in_head' => [
108
  // we keep the %s here and replace it with an empty string, because we use it somewhere else and don’t want to create a new string that is basically the same.
109
  'text' => sprintf(
110
  // translators: %s is empty here, but the string will be followed by a name of an ad unit.
115
  'hide' => false,
116
  'get_help_link' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=error-visible-ad-in-header#header-ads',
117
  'timeout' => YEAR_IN_SECONDS,
118
+ ],
119
  // Ad has HTTP, but site uses HTTPS
120
  // check in Ad Health in frontend.
121
+ 'ad_has_http' => [
122
  'text' => __( 'Your website is using HTTPS, but the ad code contains HTTP and might not work.', 'advanced-ads' ),
123
  'type' => 'notice',
124
  'hide' => false,
125
  'get_help_link' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=error-https-ads#https-ads',
126
+ ],
127
  // dummy text for general AdSense issue.
128
+ 'adsense_issue' => [
129
  // we keep the %s here and replace it with an empty string, because we use it somewhere else and don’t want to create a new string that is basically the same.
130
  'text' => __( 'AdSense issue' ),
131
  'type' => 'problem',
132
+ ],
133
  // AdSense connection error: disapproved account.
134
+ 'adsense_connect_disapprovedAccount' => [
135
  'text' => __( 'Last AdSense account connection attempt failed.', 'advanced-ads' ) . '&nbsp;' . __( 'Your account was not approved by AdSense.', 'advance-ads' ) . ' ' . Advanced_Ads_Ad_Health_Notices::get_adsense_error_link( 'disapprovedAccount' ),
136
  'type' => 'problem',
137
  'hide' => false,
138
+ ],
139
  // AdSense connection error: no adsense account.
140
+ 'adsense_connect_noAdSenseAccount' => [
141
  'text' => sprintf(
142
  __( 'Last AdSense account connection attempt failed.', 'advanced-ads' ) . '&nbsp;' .
143
  // translators: %1$s is the opening a tag and %2$s the closing one.
147
  ),
148
  'type' => 'problem',
149
  'hide' => false,
150
+ ],
151
  // AdSense account alert. Missing ads.txt – version 1.
152
+ 'adsense_alert_ALERT_TYPE_ADS_TXT_UNAUTHORIZED' => [
153
  'text' => sprintf(
154
  __( 'One of your sites is missing the AdSense publisher ID in the ads.txt file.', 'advanced-ads' )
155
  . ' <a class="advads-settings-link" href="%s">'
157
  admin_url( 'admin.php?page=advanced-ads-settings#general__advads-ads-txt' )
158
  ) . ' ' . Advanced_Ads_Ad_Health_Notices::get_adsense_error_link( 'ALERT_TYPE_ADS_TXT_UNAUTHORIZED' ),
159
  'type' => 'problem',
160
+ ],
161
  // AdSense account alert. . Missing ads.txt – version 2.
162
+ 'adsense_alert_ADS_TXT_MISSING' => [
163
  'text' => sprintf(
164
  __( 'One of your sites is missing the AdSense publisher ID in the ads.txt file.', 'advanced-ads' )
165
  . ' <a class="advads-settings-link" href="%s">'
167
  admin_url( 'admin.php?page=advanced-ads-settings#general__advads-ads-txt' )
168
  ) . ' ' . Advanced_Ads_Ad_Health_Notices::get_adsense_error_link( 'ADS_TXT_MISSING' ),
169
  'type' => 'problem',
170
+ ],
171
  // AdSense account alert. . Missing ads.txt – version 3.
172
+ 'adsense_alert_ADS_TXT_ISSUES' => [
173
  'text' => sprintf(
174
  __( 'One of your sites is missing the AdSense publisher ID in the ads.txt file.', 'advanced-ads' )
175
  . ' <a class="advads-settings-link" href="%s">'
177
  admin_url( 'admin.php?page=advanced-ads-settings#general__advads-ads-txt' )
178
  ) . ' ' . Advanced_Ads_Ad_Health_Notices::get_adsense_error_link( 'ADS_TXT_ISSUES' ),
179
  'type' => 'problem',
180
+ ],
181
  // AdSense deprecated link units
182
+ 'adsense_link_units_deprecated' => [
183
  'text' => __( 'Google AdSense deprecated Link Units. Please choose another format.', 'advanced-ads' )
184
  . ' <a href="' . esc_url( ADVADS_URL ) . 'adsense-link-units/" target="_blank" rel="noopener">'
185
  . esc_html__( 'Learn more', 'advanced-ads' )
186
  . '</a>',
187
  'type' => 'problem',
188
+ ],
189
+ 'nested_the_content_filters' => [
190
  'text' => sprintf(
191
  // translators: %s is a filter hook, here `the_content`.
192
  __( '<strong>%s</strong> filter found multiple times.', 'advanced-ads' ),
195
  'get_help_link' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=error-multiple-the-content#the_content_filter_found_multiple_times',
196
  'type' => 'notice',
197
  'hide' => false,
198
+ ],
199
  // BuddyPress or BuddyBoss installed.
200
+ 'buddypress_no_pro' => [
201
  'text' => sprintf(
202
  // translators: %1$s is a plugin name, %2$s is the opening a tag and %3$s the closing one.
203
  __( 'Learn how to integrate %1$s with Advanced Ads %2$shere%3$s.', 'advanced-ads' ),
206
  '</a>'
207
  ),
208
  'type' => 'notice',
209
+ ],
210
  // bbPress installed.
211
+ 'bbpress_no_pro' => [
212
  'text' => sprintf(
213
  // translators: %1$s is a plugin name, %2$s is the opening a tag and %3$s the closing one.
214
  __( 'Learn how to integrate %1$s with Advanced Ads %2$shere%3$s.', 'advanced-ads' ),
217
  '</a>'
218
  ),
219
  'type' => 'notice',
220
+ ],
221
  // WPML plugin activated.
222
+ 'WPML_active' => [
223
  'text' => sprintf(
224
  // translators: %1$s is a plugin name, %2$s is the opening a tag and %3$s the closing one.
225
  __( 'Learn how to integrate %1$s with Advanced Ads %2$shere%3$s.', 'advanced-ads' ),
230
  'type' => 'notice',
231
  'hide' => false,
232
  'timeout' => YEAR_IN_SECONDS,
233
+ ],
234
  // AMP and Accelerated Mobile Pages plugins.
235
+ 'AMP_active' => [
236
  'text' => sprintf(
237
  // translators: %1$s is a plugin name, %2$s is the opening a tag and %3$s the closing one.
238
  __( 'Learn how to integrate %1$s with Advanced Ads %2$shere%3$s.', 'advanced-ads' ),
243
  'type' => 'notice',
244
  'hide' => false,
245
  'timeout' => YEAR_IN_SECONDS,
246
+ ],
247
  // Hosting on WP Engine
248
  // Advanced_Ads_Checks::wp_engine_hosting().
249
+ 'wpengine' => [
250
  'text' => sprintf(
251
  // translators: %s is a service or plugin name.
252
  '<strong>' . __( '%s detected.', 'advanced-ads' ) . '</strong>'
256
  'type' => 'notice',
257
  'hide' => false,
258
  'timeout' => YEAR_IN_SECONDS,
259
+ ],
260
  // Notice about existing ads.txt plugins.
261
  // Advanced_Ads_Checks::ads_txt_plugins().
262
+ 'ads_txt_plugins_enabled' => [
263
  'text' => sprintf(
264
  __( 'Advanced Ads handles your ads.txt file automatically. You might be able to <strong>remove %1$s</strong>.', 'advanced-ads' ),
265
  implode( ', ', Advanced_Ads_Checks::ads_txt_plugins() )
267
  'type' => 'notice',
268
  'hide' => false,
269
  'timeout' => YEAR_IN_SECONDS,
270
+ ],
271
  // Notice about plugins that add header or footer code.
272
  // Advanced_Ads_Checks::header_footer_plugins().
273
+ 'header_footer_plugins_enabled' => [
274
  'text' =>
275
  __( 'Advanced Ads handles header and footer codes.', 'advanced-ads' ) . '&nbsp;' .
276
  sprintf( __( 'You might be able to <strong>remove %1$s</strong>.', 'advanced-ads' ),
280
  'type' => 'notice',
281
  'hide' => false,
282
  'timeout' => YEAR_IN_SECONDS,
283
+ ],
284
+ ]
285
  );
admin/includes/class-ad-groups-list.php CHANGED
@@ -13,14 +13,14 @@ class Advanced_Ads_Groups_List {
13
  *
14
  * @var $groups
15
  */
16
- public $groups = array();
17
 
18
  /**
19
  * Array with all ad group types
20
  *
21
  * @var $types
22
  */
23
- public $types = array();
24
 
25
  /**
26
  * Construct the current list
@@ -44,11 +44,11 @@ class Advanced_Ads_Groups_List {
44
  // load all groups.
45
  $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
46
 
47
- $args = array(
48
  'taxonomy' => $this->taxonomy,
49
  'search' => $search,
50
  'hide_empty' => 0,
51
- );
52
  // get wp term objects.
53
  $terms = Advanced_Ads::get_ad_groups( $args );
54
 
@@ -65,7 +65,7 @@ class Advanced_Ads_Groups_List {
65
  */
66
  protected function load_groups_objects_from_terms( array $terms ) {
67
 
68
- $groups = array();
69
  foreach ( $terms as $_group ) {
70
  $groups[] = new Advanced_Ads_Group( $_group );
71
  }
@@ -87,7 +87,6 @@ class Advanced_Ads_Groups_List {
87
  public function render_rows() {
88
  foreach ( $this->groups as $_group ) {
89
  $this->render_row( $_group );
90
- $this->render_form_row( $_group );
91
  }
92
  }
93
 
@@ -98,26 +97,23 @@ class Advanced_Ads_Groups_List {
98
  * @param Advanced_Ads_Group $group the ad group object.
99
  */
100
  public function render_row( Advanced_Ads_Group $group ) {
101
- ob_start();
102
- $hints = ! Advanced_Ads_Placements::get_placements_by( 'group', $group->id ) ? Advanced_Ads_Group::get_hints( $group ) : array();
103
- require ADVADS_BASE_PATH . 'admin/views/group-hints.php';
104
- $hints_html = ob_get_clean();
105
-
106
- $file = ADVADS_BASE_PATH . 'admin/views/ad-group-list-row.php';
107
- require $file;
108
- }
109
-
110
- /**
111
- * Render the form row of a group
112
- *
113
- * @param Advanced_Ads_Group $group the ad group object.
114
- */
115
- public function render_form_row( Advanced_Ads_Group $group ) {
116
  // query ads.
117
- $ads = $this->get_ads( $group );
118
- $weights = $group->get_ad_weights( wp_list_pluck( $ads->posts, 'ID' ) );
119
- $ad_form_rows = $this->get_weighted_ad_order( $weights );
120
- $max_weight = Advanced_Ads_Group::get_max_ad_weight( $ads->post_count );
 
 
 
 
 
 
 
 
 
 
 
 
121
 
122
  // The Loop.
123
  if ( $ads->post_count ) {
@@ -145,13 +141,12 @@ class Advanced_Ads_Groups_List {
145
  }
146
  $new_ad_weights .= '</select>';
147
 
148
-
149
  ob_start();
150
- $hints = Advanced_Ads_Group::get_hints( $group );
151
  require ADVADS_BASE_PATH . 'admin/views/group-hints.php';
152
  $hints_html = ob_get_clean();
153
 
154
- require ADVADS_BASE_PATH . 'admin/views/ad-group-list-form-row.php';
155
  }
156
 
157
  /**
@@ -242,7 +237,7 @@ class Advanced_Ads_Groups_List {
242
  } else {
243
  esc_html_e( 'No ads assigned', 'advanced-ads' );
244
  ?>
245
- <br/><a class="edit advads-add-ads">+ <?php esc_html_e( 'Add some', 'advanced-ads' ); ?></a>
246
  <?php
247
  }
248
  // Restore original Post Data.
@@ -300,13 +295,13 @@ class Advanced_Ads_Groups_List {
300
  * @return WP_Query
301
  */
302
  public function get_ads( $group ) {
303
- return new WP_Query( array(
304
  'post_type' => $this->post_type,
305
- 'post_status' => array( 'publish', 'pending', 'future', 'private' ),
306
  'taxonomy' => $group->taxonomy,
307
  'term' => $group->slug,
308
  'posts_per_page' => - 1,
309
- ) );
310
  }
311
 
312
  /**
@@ -315,15 +310,15 @@ class Advanced_Ads_Groups_List {
315
  * @return array
316
  */
317
  public function ads_for_select() {
318
- $select = array();
319
  $model = Advanced_Ads::get_instance()->get_model();
320
 
321
  // load all ads.
322
  $ads = $model->get_ads(
323
- array(
324
  'orderby' => 'title',
325
  'order' => 'ASC',
326
- )
327
  );
328
  foreach ( $ads as $_ad ) {
329
  $select[ $_ad->ID ] = esc_html( $_ad->post_title );
@@ -338,18 +333,35 @@ class Advanced_Ads_Groups_List {
338
  * @return array $types ad group information
339
  */
340
  public function get_ad_group_types() {
341
- $types = array(
342
- 'default' => array(
343
  'title' => __( 'Random ads', 'advanced-ads' ),
344
  'description' => __( 'Display random ads based on ad weight', 'advanced-ads' ),
345
- ),
346
- 'ordered' => array(
 
347
  'title' => __( 'Ordered ads', 'advanced-ads' ),
348
  'description' => __( 'Display ads with the highest ad weight first', 'advanced-ads' ),
349
- ),
350
- );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
 
352
- return apply_filters( 'advanced-ads-group-types', $types );
353
  }
354
 
355
  /**
@@ -362,17 +374,17 @@ class Advanced_Ads_Groups_List {
362
 
363
  $tax = get_taxonomy( $this->taxonomy );
364
 
365
- $actions = array();
366
  if ( current_user_can( $tax->cap->edit_terms ) ) {
367
- $actions['edit'] = '<a class="edit">' . __( 'Edit', 'advanced-ads' ) . '</a>';
368
- $actions['usage'] = '<a href="#modal-' . esc_attr( $group->id ) . '-usage" class="usage-modal-link">' . esc_html__( 'show usage', 'advanced-ads' ) . '</a>';
369
  }
370
 
371
  if ( current_user_can( $tax->cap->delete_terms ) ) {
372
- $args = array(
373
  'action' => 'delete',
374
  'group_id' => $group->id,
375
- );
376
  $delete_link = self::group_page_url( $args );
377
  $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( $delete_link, 'delete-tag_' . $group->id ) . "'>" . __( 'Delete', 'advanced-ads' ) . '</a>';
378
  }
@@ -383,7 +395,7 @@ class Advanced_Ads_Groups_List {
383
 
384
  echo '<div class="row-actions">';
385
  foreach ( $actions as $action => $link ) {
386
- echo "<span class='" . esc_attr( $action ) . "'>" . wp_kses( $link, array( 'a' => array( 'class' => array(), 'href' => array() ) ) ) . '</span>';
387
  }
388
  echo '</div>';
389
  }
@@ -413,6 +425,15 @@ class Advanced_Ads_Groups_List {
413
  return $new_group;
414
  }
415
 
 
 
 
 
 
 
 
 
 
416
  // save default values.
417
  if ( is_array( $new_group ) ) {
418
  $group = new Advanced_Ads_Group( $new_group['term_id'] );
@@ -420,11 +441,11 @@ class Advanced_Ads_Groups_List {
420
  // allow other add-ons to save their own group attributes.
421
  $atts = apply_filters(
422
  'advanced-ads-group-save-atts',
423
- array(
424
- 'type' => 'default',
425
  'ad_count' => 1,
426
- 'options' => array(),
427
- ),
428
  $group
429
  );
430
 
@@ -449,7 +470,7 @@ class Advanced_Ads_Groups_List {
449
  * @return array
450
  */
451
  private function get_groups_by_ad_id( $ad_id ) {
452
- $ids = array();
453
  $terms = wp_get_object_terms( $ad_id, $this->taxonomy );
454
  foreach ( $terms as $term ) {
455
  $ids[] = $term->term_id;
@@ -481,16 +502,16 @@ class Advanced_Ads_Groups_List {
481
  // empty weights.
482
  // update_option( 'advads-ad-weights', array() );
483
 
484
- $all_weights = get_option( 'advads-ad-weights', array() );
485
 
486
- $ad_groups_assoc = array();
487
 
488
  if ( isset( $_POST['advads-groups-removed-ads'] ) && is_array( $_POST['advads-groups-removed-ads'] ) && isset( $_POST['advads-groups-removed-ads-gid'] ) ) {
489
  $len = count( $_POST['advads-groups-removed-ads'] );
490
  for ( $i = 0; $i < $len; $i ++ ) {
491
  $ad_id = absint( wp_unslash( $_POST['advads-groups-removed-ads'][ $i ] ) );
492
  $group_id = absint( wp_unslash( $_POST['advads-groups-removed-ads-gid'][ $i ] ) );
493
- $ad_groups_assoc[ $ad_id ] = array();
494
  // remove it from the weights.
495
  if ( isset( $all_weights[ $group_id ] ) && isset( $all_weights[ $group_id ][ $ad_id ] ) ) {
496
  unset( $all_weights[ $group_id ][ $ad_id ] );
@@ -507,7 +528,7 @@ class Advanced_Ads_Groups_List {
507
 
508
 
509
  // iterate through groups.
510
- $post_ad_groups = isset( $_POST['advads-groups'] ) ? wp_unslash( $_POST['advads-groups'] ) : array();
511
 
512
  if ( count( $post_ad_groups ) ) {
513
 
@@ -549,15 +570,15 @@ class Advanced_Ads_Groups_List {
549
  // save other attributes.
550
  $type = isset( $_group['type'] ) ? $_group['type'] : 'default';
551
  $ad_count = isset( $_group['ad_count'] ) ? $_group['ad_count'] : 1;
552
- $options = isset( $_group['options'] ) ? $_group['options'] : array();
553
 
554
  // allow other add-ons to save their own group attributes.
555
  $atts = apply_filters( 'advanced-ads-group-save-atts',
556
- array(
557
  'type' => $type,
558
  'ad_count' => $ad_count,
559
  'options' => $options,
560
- ),
561
  $_group
562
  );
563
 
@@ -586,12 +607,12 @@ class Advanced_Ads_Groups_List {
586
  * @return string admin url
587
  * @since 1.0.0
588
  */
589
- public static function group_page_url( $args = array() ) {
590
  $plugin = Advanced_Ads::get_instance();
591
 
592
- $default_args = array(
593
  'page' => 'advanced-ads-groups',
594
- );
595
  $args = $args + $default_args;
596
 
597
  return add_query_arg( $args, admin_url( 'admin.php' ) );
@@ -606,7 +627,7 @@ class Advanced_Ads_Groups_List {
606
  * @return array
607
  */
608
  private function sanitize_ad_weights( array $weights ) {
609
- $sanitized_weights = array();
610
  foreach ( $weights as $ad_id => $weight ) {
611
  $ad_id_int = absint( $ad_id );
612
  if ( $ad_id_int === 0 || array_key_exists( $ad_id_int, $sanitized_weights ) ) {
@@ -627,7 +648,7 @@ class Advanced_Ads_Groups_List {
627
  */
628
  private function get_weighted_ad_order( array $weights ) {
629
  arsort( $weights );
630
- $ad_title_weights = array();
631
 
632
  // index ads with the same weight by weight.
633
  foreach ( $weights as $ad_id => $weight ) {
@@ -640,7 +661,7 @@ class Advanced_Ads_Groups_List {
640
  } );
641
 
642
  // flatten the array with the ad_id as key and the weight as value
643
- $ad_order = array();
644
  foreach ( $ad_title_weights as $weight => $ad_array ) {
645
  $ad_order += array_fill_keys( array_keys( $ad_array ), $weight );
646
  }
13
  *
14
  * @var $groups
15
  */
16
+ public $groups = [];
17
 
18
  /**
19
  * Array with all ad group types
20
  *
21
  * @var $types
22
  */
23
+ public $types = [];
24
 
25
  /**
26
  * Construct the current list
44
  // load all groups.
45
  $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
46
 
47
+ $args = [
48
  'taxonomy' => $this->taxonomy,
49
  'search' => $search,
50
  'hide_empty' => 0,
51
+ ];
52
  // get wp term objects.
53
  $terms = Advanced_Ads::get_ad_groups( $args );
54
 
65
  */
66
  protected function load_groups_objects_from_terms( array $terms ) {
67
 
68
+ $groups = [];
69
  foreach ( $terms as $_group ) {
70
  $groups[] = new Advanced_Ads_Group( $_group );
71
  }
87
  public function render_rows() {
88
  foreach ( $this->groups as $_group ) {
89
  $this->render_row( $_group );
 
90
  }
91
  }
92
 
97
  * @param Advanced_Ads_Group $group the ad group object.
98
  */
99
  public function render_row( Advanced_Ads_Group $group ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  // query ads.
101
+ $ads = $this->get_ads( $group );
102
+ $weights = $group->get_ad_weights( wp_list_pluck( $ads->posts, 'ID' ) );
103
+ $ad_form_rows = $this->get_weighted_ad_order( $weights );
104
+ $max_weight = Advanced_Ads_Group::get_max_ad_weight( $ads->post_count );
105
+ $type_name = isset( $this->types[ $group->type ]['title'] ) ? $this->types[ $group->type ]['title'] : 'default';
106
+ $missing_type_error = '';
107
+
108
+ // set the group to behave as default, if the original type is not available
109
+ if ( ! array_key_exists( $group->type, $this->types ) ) {
110
+ $missing_type_error = sprintf(
111
+ /* translators: %s is the group type string */
112
+ __( 'The originally selected group type “%s” is not enabled.', 'advanced-ads' ),
113
+ $group->type
114
+ );
115
+ $group->type = 'default';
116
+ }
117
 
118
  // The Loop.
119
  if ( $ads->post_count ) {
141
  }
142
  $new_ad_weights .= '</select>';
143
 
 
144
  ob_start();
145
+ $hints = ! Advanced_Ads_Placements::get_placements_by( 'group', $group->id ) ? Advanced_Ads_Group::get_hints( $group ) : [];
146
  require ADVADS_BASE_PATH . 'admin/views/group-hints.php';
147
  $hints_html = ob_get_clean();
148
 
149
+ require ADVADS_BASE_PATH . 'admin/views/ad-group-list-row.php';
150
  }
151
 
152
  /**
237
  } else {
238
  esc_html_e( 'No ads assigned', 'advanced-ads' );
239
  ?>
240
+ <br/><a href="#modal-group-edit-<?php echo esc_attr( $group->id ); ?>">+ <?php esc_html_e( 'Add some', 'advanced-ads' ); ?></a>
241
  <?php
242
  }
243
  // Restore original Post Data.
295
  * @return WP_Query
296
  */
297
  public function get_ads( $group ) {
298
+ return new WP_Query( [
299
  'post_type' => $this->post_type,
300
+ 'post_status' => [ 'publish', 'pending', 'future', 'private' ],
301
  'taxonomy' => $group->taxonomy,
302
  'term' => $group->slug,
303
  'posts_per_page' => - 1,
304
+ ] );
305
  }
306
 
307
  /**
310
  * @return array
311
  */
312
  public function ads_for_select() {
313
+ $select = [];
314
  $model = Advanced_Ads::get_instance()->get_model();
315
 
316
  // load all ads.
317
  $ads = $model->get_ads(
318
+ [
319
  'orderby' => 'title',
320
  'order' => 'ASC',
321
+ ]
322
  );
323
  foreach ( $ads as $_ad ) {
324
  $select[ $_ad->ID ] = esc_html( $_ad->post_title );
333
  * @return array $types ad group information
334
  */
335
  public function get_ad_group_types() {
336
+ $types = [
337
+ 'default' => [
338
  'title' => __( 'Random ads', 'advanced-ads' ),
339
  'description' => __( 'Display random ads based on ad weight', 'advanced-ads' ),
340
+ 'image' => ADVADS_BASE_URL . 'admin/assets/img/groups/random.svg',
341
+ ],
342
+ 'ordered' => [
343
  'title' => __( 'Ordered ads', 'advanced-ads' ),
344
  'description' => __( 'Display ads with the highest ad weight first', 'advanced-ads' ),
345
+ 'image' => ADVADS_BASE_URL . 'admin/assets/img/groups/ordered.svg',
346
+ ],
347
+ ];
348
+
349
+ /**
350
+ * Add, change, or remove group types.
351
+ *
352
+ * @param array[] $types Group types.
353
+ */
354
+ $types = apply_filters( 'advanced-ads-group-types', $types );
355
+
356
+ // fallback if the add-ons don’t contain type images, yet.
357
+ if ( isset( $types['grid'] ) && empty( $types['grid']['image'] ) ) {
358
+ $types['grid']['image'] = ADVADS_BASE_URL . 'admin/assets/img/groups/grid.svg';
359
+ }
360
+ if ( isset( $types['slider'] ) && empty( $types['slider']['image'] ) ) {
361
+ $types['slider']['image'] = ADVADS_BASE_URL . 'admin/assets/img/groups/slider.svg';
362
+ }
363
 
364
+ return $types;
365
  }
366
 
367
  /**
374
 
375
  $tax = get_taxonomy( $this->taxonomy );
376
 
377
+ $actions = [];
378
  if ( current_user_can( $tax->cap->edit_terms ) ) {
379
+ $actions['edit'] = '<a href="#modal-group-edit-' . $group->id . '" class="edits">' . esc_html__( 'Edit', 'advanced-ads' ) . '</a>';
380
+ $actions['usage'] = '<a href="#modal-' . (int) $group->id . '-usage" class="usage-modal-link">' . esc_html__( 'show usage', 'advanced-ads' ) . '</a>';
381
  }
382
 
383
  if ( current_user_can( $tax->cap->delete_terms ) ) {
384
+ $args = [
385
  'action' => 'delete',
386
  'group_id' => $group->id,
387
+ ];
388
  $delete_link = self::group_page_url( $args );
389
  $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( $delete_link, 'delete-tag_' . $group->id ) . "'>" . __( 'Delete', 'advanced-ads' ) . '</a>';
390
  }
395
 
396
  echo '<div class="row-actions">';
397
  foreach ( $actions as $action => $link ) {
398
+ echo "<span class='" . esc_attr( $action ) . "'>" . wp_kses( $link, [ 'a' => [ 'class' => [], 'href' => [] ] ] ) . '</span>';
399
  }
400
  echo '</div>';
401
  }
425
  return $new_group;
426
  }
427
 
428
+ // set the ad group
429
+ $type = 'default';
430
+ if ( ! empty( $_POST['advads-group-type'] ) ) {
431
+ $posted_type = sanitize_text_field( $_POST['advads-group-type'] );
432
+ if ( array_key_exists( $posted_type, $this->get_ad_group_types() ) ) {
433
+ $type = $posted_type;
434
+ }
435
+ }
436
+
437
  // save default values.
438
  if ( is_array( $new_group ) ) {
439
  $group = new Advanced_Ads_Group( $new_group['term_id'] );
441
  // allow other add-ons to save their own group attributes.
442
  $atts = apply_filters(
443
  'advanced-ads-group-save-atts',
444
+ [
445
+ 'type' => $type,
446
  'ad_count' => 1,
447
+ 'options' => [],
448
+ ],
449
  $group
450
  );
451
 
470
  * @return array
471
  */
472
  private function get_groups_by_ad_id( $ad_id ) {
473
+ $ids = [];
474
  $terms = wp_get_object_terms( $ad_id, $this->taxonomy );
475
  foreach ( $terms as $term ) {
476
  $ids[] = $term->term_id;
502
  // empty weights.
503
  // update_option( 'advads-ad-weights', array() );
504
 
505
+ $all_weights = get_option( 'advads-ad-weights', [] );
506
 
507
+ $ad_groups_assoc = [];
508
 
509
  if ( isset( $_POST['advads-groups-removed-ads'] ) && is_array( $_POST['advads-groups-removed-ads'] ) && isset( $_POST['advads-groups-removed-ads-gid'] ) ) {
510
  $len = count( $_POST['advads-groups-removed-ads'] );
511
  for ( $i = 0; $i < $len; $i ++ ) {
512
  $ad_id = absint( wp_unslash( $_POST['advads-groups-removed-ads'][ $i ] ) );
513
  $group_id = absint( wp_unslash( $_POST['advads-groups-removed-ads-gid'][ $i ] ) );
514
+ $ad_groups_assoc[ $ad_id ] = [];
515
  // remove it from the weights.
516
  if ( isset( $all_weights[ $group_id ] ) && isset( $all_weights[ $group_id ][ $ad_id ] ) ) {
517
  unset( $all_weights[ $group_id ][ $ad_id ] );
528
 
529
 
530
  // iterate through groups.
531
+ $post_ad_groups = isset( $_POST['advads-groups'] ) ? wp_unslash( $_POST['advads-groups'] ) : [];
532
 
533
  if ( count( $post_ad_groups ) ) {
534
 
570
  // save other attributes.
571
  $type = isset( $_group['type'] ) ? $_group['type'] : 'default';
572
  $ad_count = isset( $_group['ad_count'] ) ? $_group['ad_count'] : 1;
573
+ $options = isset( $_group['options'] ) ? $_group['options'] : [];
574
 
575
  // allow other add-ons to save their own group attributes.
576
  $atts = apply_filters( 'advanced-ads-group-save-atts',
577
+ [
578
  'type' => $type,
579
  'ad_count' => $ad_count,
580
  'options' => $options,
581
+ ],
582
  $_group
583
  );
584
 
607
  * @return string admin url
608
  * @since 1.0.0
609
  */
610
+ public static function group_page_url( $args = [] ) {
611
  $plugin = Advanced_Ads::get_instance();
612
 
613
+ $default_args = [
614
  'page' => 'advanced-ads-groups',
615
+ ];
616
  $args = $args + $default_args;
617
 
618
  return add_query_arg( $args, admin_url( 'admin.php' ) );
627
  * @return array
628
  */
629
  private function sanitize_ad_weights( array $weights ) {
630
+ $sanitized_weights = [];
631
  foreach ( $weights as $ad_id => $weight ) {
632
  $ad_id_int = absint( $ad_id );
633
  if ( $ad_id_int === 0 || array_key_exists( $ad_id_int, $sanitized_weights ) ) {
648
  */
649
  private function get_weighted_ad_order( array $weights ) {
650
  arsort( $weights );
651
+ $ad_title_weights = [];
652
 
653
  // index ads with the same weight by weight.
654
  foreach ( $weights as $ad_id => $weight ) {
661
  } );
662
 
663
  // flatten the array with the ad_id as key and the weight as value
664
+ $ad_order = [];
665
  foreach ( $ad_title_weights as $weight => $ad_array ) {
666
  $ad_order += array_fill_keys( array_keys( $ad_array ), $weight );
667
  }
admin/includes/class-ad-network.php CHANGED
@@ -96,14 +96,14 @@ abstract class Advanced_Ads_Ad_Network {
96
  */
97
  public function register() {
98
  // register the ad type.
99
- add_filter( 'advanced-ads-ad-types', array( $this, 'register_ad_type_callback' ) );
100
 
101
  if ( is_admin() ) {
102
  if ( wp_doing_ajax() ) {
103
  // we need add all the actions for our ajax calls here.
104
  // our ajax method that will trigger an update of the ad units of this network.
105
- add_action( 'wp_ajax_advanced_ads_get_ad_units_' . $this->identifier, array( $this, 'update_external_ad_units' ) );
106
- add_action( 'wp_ajax_advanced_ads_toggle_idle_ads_' . $this->identifier, array( $this, 'toggle_idle_ads' ) );
107
  } else {
108
  // find out if we need to register the settings. this is necessary
109
  // 1) when viewing the settings (admin.php with page="advanced-ads-settings")
@@ -129,7 +129,7 @@ abstract class Advanced_Ads_Ad_Network {
129
  $requires_settings = true;
130
  } elseif ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
131
  $post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : '';
132
- add_filter( 'advanced-ads-ad-settings-pre-save', array( $this, 'sanitize_ad_settings' ) );
133
 
134
  if ( isset( $_GET['action'] ) && 'edit' === $_GET['action'] ) {
135
  $requires_javascript = true;
@@ -140,11 +140,11 @@ abstract class Advanced_Ads_Ad_Network {
140
 
141
  if ( $requires_settings ) {
142
  // register the settings.
143
- add_action( 'advanced-ads-settings-init', array( $this, 'register_settings_callback' ) );
144
- add_filter( 'advanced-ads-setting-tabs', array( $this, 'register_settings_tabs_callback' ) );
145
  }
146
  if ( $requires_javascript ) {
147
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts_callback' ) );
148
  }
149
  }
150
  }
@@ -171,7 +171,7 @@ abstract class Advanced_Ads_Ad_Network {
171
  register_setting(
172
  ADVADS_SLUG . '-' . $this->identifier,
173
  ADVADS_SLUG . '-' . $this->identifier,
174
- array( $this, 'sanitize_settings_callback' )
175
  );
176
 
177
  /**
@@ -191,7 +191,7 @@ abstract class Advanced_Ads_Ad_Network {
191
  add_settings_section(
192
  $this->settings_section_id,
193
  '',
194
- array( $this, 'render_settings_callback' ),
195
  $this->settings_page_hook
196
  );
197
 
@@ -222,11 +222,11 @@ abstract class Advanced_Ads_Ad_Network {
222
  $js_path = $this->get_javascript_base_path();
223
  if ( $js_path ) {
224
  $id = $this->get_js_library_name();
225
- wp_enqueue_script( $id, $js_path, array( 'jquery' ) );
226
  // next we have to pass the data.
227
- $data = array(
228
  'nonce' => $this->get_nonce(),
229
- );
230
  $data = $this->append_javascript_data( $data );
231
  wp_localize_script( $id, $this->get_localized_script_object_name(), $data );
232
  }
@@ -266,12 +266,12 @@ abstract class Advanced_Ads_Ad_Network {
266
  */
267
  public function register_settings_tabs_callback( $tabs ) {
268
  $tab_id = $this->identifier;
269
- $tabs[ $tab_id ] = array(
270
  'page' => $this->settings_page_hook,
271
  'group' => ADVADS_SLUG . '-' . $this->identifier,
272
  'tabid' => $tab_id,
273
  'title' => $this->get_settings_tab_name(),
274
- );
275
 
276
  return $tabs;
277
  }
@@ -366,10 +366,10 @@ abstract class Advanced_Ads_Ad_Network {
366
  $this->print_external_ads_list( $hide_idle_ads );
367
  $ad_selector = ob_get_clean();
368
 
369
- $response = array(
370
  'status' => true,
371
  'html' => $ad_selector,
372
- );
373
  $this->send_ajax_response_and_die( $response );
374
  }
375
 
96
  */
97
  public function register() {
98
  // register the ad type.
99
+ add_filter( 'advanced-ads-ad-types', [ $this, 'register_ad_type_callback' ] );
100
 
101
  if ( is_admin() ) {
102
  if ( wp_doing_ajax() ) {
103
  // we need add all the actions for our ajax calls here.
104
  // our ajax method that will trigger an update of the ad units of this network.
105
+ add_action( 'wp_ajax_advanced_ads_get_ad_units_' . $this->identifier, [ $this, 'update_external_ad_units' ] );
106
+ add_action( 'wp_ajax_advanced_ads_toggle_idle_ads_' . $this->identifier, [ $this, 'toggle_idle_ads' ] );
107
  } else {
108
  // find out if we need to register the settings. this is necessary
109
  // 1) when viewing the settings (admin.php with page="advanced-ads-settings")
129
  $requires_settings = true;
130
  } elseif ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) {
131
  $post_type = isset( $_REQUEST['post_type'] ) ? $_REQUEST['post_type'] : '';
132
+ add_filter( 'advanced-ads-ad-settings-pre-save', [ $this, 'sanitize_ad_settings' ] );
133
 
134
  if ( isset( $_GET['action'] ) && 'edit' === $_GET['action'] ) {
135
  $requires_javascript = true;
140
 
141
  if ( $requires_settings ) {
142
  // register the settings.
143
+ add_action( 'advanced-ads-settings-init', [ $this, 'register_settings_callback' ] );
144
+ add_filter( 'advanced-ads-setting-tabs', [ $this, 'register_settings_tabs_callback' ] );
145
  }
146
  if ( $requires_javascript ) {
147
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts_callback' ] );
148
  }
149
  }
150
  }
171
  register_setting(
172
  ADVADS_SLUG . '-' . $this->identifier,
173
  ADVADS_SLUG . '-' . $this->identifier,
174
+ [ $this, 'sanitize_settings_callback' ]
175
  );
176
 
177
  /**
191
  add_settings_section(
192
  $this->settings_section_id,
193
  '',
194
+ [ $this, 'render_settings_callback' ],
195
  $this->settings_page_hook
196
  );
197
 
222
  $js_path = $this->get_javascript_base_path();
223
  if ( $js_path ) {
224
  $id = $this->get_js_library_name();
225
+ wp_enqueue_script( $id, $js_path, [ 'jquery' ] );
226
  // next we have to pass the data.
227
+ $data = [
228
  'nonce' => $this->get_nonce(),
229
+ ];
230
  $data = $this->append_javascript_data( $data );
231
  wp_localize_script( $id, $this->get_localized_script_object_name(), $data );
232
  }
266
  */
267
  public function register_settings_tabs_callback( $tabs ) {
268
  $tab_id = $this->identifier;
269
+ $tabs[ $tab_id ] = [
270
  'page' => $this->settings_page_hook,
271
  'group' => ADVADS_SLUG . '-' . $this->identifier,
272
  'tabid' => $tab_id,
273
  'title' => $this->get_settings_tab_name(),
274
+ ];
275
 
276
  return $tabs;
277
  }
366
  $this->print_external_ads_list( $hide_idle_ads );
367
  $ad_selector = ob_get_clean();
368
 
369
+ $response = [
370
  'status' => true,
371
  'html' => $ad_selector,
372
+ ];
373
  $this->send_ajax_response_and_die( $response );
374
  }
375
 
admin/includes/class-ad-type.php CHANGED
@@ -26,39 +26,39 @@ class Advanced_Ads_Admin_Ad_Type {
26
  // Register column headers.
27
  add_filter(
28
  'manage_advanced_ads_posts_columns',
29
- array(
30
  $this,
31
  'ad_list_columns_head',
32
- )
33
  );
34
- add_filter( 'manage_advanced_ads_posts_custom_column', array( $this, 'ad_list_columns' ), 10, 2 );
35
  // Add custom filter views.
36
- add_action( 'restrict_manage_posts', array( $this, 'ad_list_add_filters' ) );
37
- add_filter( 'default_hidden_columns', array( $this, 'hide_ad_list_columns' ), 10, 2 );
38
- add_filter( 'bulk_post_updated_messages', array( $this, 'ad_bulk_update_messages' ), 10, 2 );
39
  // order ad lists.
40
- add_filter( 'request', array( $this, 'ad_list_request' ) );
41
- add_action( 'all_admin_notices', array( $this, 'no_ads_yet_notice' ) );
42
  // Manipulate post data when post is created.
43
- add_filter( 'wp_insert_post_data', array( $this, 'prepare_insert_post_data' ) );
44
  // Save ads post type.
45
  // @source https://developer.wordpress.org/reference/hooks/save_post_post-post_type/
46
- add_action( 'save_post_advanced_ads', array( $this, 'save_ad' ) );
47
- add_action( 'delete_post', array( $this, 'delete_ad' ) );
48
- add_action( 'edit_form_top', array( $this, 'edit_form_above_title' ) );
49
- add_action( 'edit_form_after_title', array( $this, 'edit_form_below_title' ) );
50
- add_action( 'dbx_post_sidebar', array( $this, 'edit_form_end' ) );
51
- add_action( 'post_submitbox_misc_actions', array( $this, 'add_submit_box_meta' ) );
52
- add_action( 'admin_enqueue_scripts', array( $this, 'use_code_editor' ) );
53
- add_filter( 'post_updated_messages', array( $this, 'ad_update_messages' ) );
54
- add_filter( 'gettext', array( $this, 'replace_cheating_message' ), 20, 2 );
55
- add_action( 'current_screen', array( $this, 'run_on_ad_edit_screen' ) );
56
- add_filter( 'pre_wp_unique_post_slug', array( $this, 'pre_wp_unique_post_slug' ), 10, 6 );
57
- add_filter( 'view_mode_post_types', array( $this, 'remove_view_mode' ) );
58
- add_filter( 'get_user_option_user-settings', array( $this, 'reset_view_mode_option' ) );
59
- add_filter( 'screen_settings', array( $this, 'add_screen_options' ), 10, 2 );
60
- add_action( 'wp_loaded', array( $this, 'save_screen_options' ) );
61
- add_action( 'load-edit.php', array( $this, 'set_screen_options' ) );
62
 
63
  $this->post_type = constant( 'Advanced_Ads::POST_TYPE_SLUG' );
64
  }
@@ -124,7 +124,7 @@ class Advanced_Ads_Admin_Ad_Type {
124
  * @return string[]
125
  */
126
  public function ad_list_columns_head( $columns ) {
127
- $new_columns = array();
128
 
129
  foreach ( $columns as $key => $value ) {
130
  $new_columns[ $key ] = $value;
@@ -144,7 +144,7 @@ class Advanced_Ads_Admin_Ad_Type {
144
  }
145
  }
146
 
147
- $allowed_columns = array(
148
  'cb', // checkbox.
149
  'title',
150
  'author',
@@ -155,7 +155,7 @@ class Advanced_Ads_Admin_Ad_Type {
155
  'ad_timing',
156
  'ad_shortcode',
157
  'taxonomy-advanced_ads_groups',
158
- );
159
 
160
  /**
161
  * Filter the allowed columns for Advanced Ads post type list.
@@ -315,10 +315,10 @@ class Advanced_Ads_Admin_Ad_Type {
315
  ob_start();
316
  do_action_ref_array(
317
  'advanced-ads-ad-list-timing-column-after',
318
- array(
319
  $ad,
320
  &$html_classes,
321
- )
322
  );
323
  $content_after = ob_get_clean();
324
 
@@ -381,7 +381,7 @@ class Advanced_Ads_Admin_Ad_Type {
381
  public function ad_bulk_update_messages( array $messages, array $counts ) {
382
  $post = get_post();
383
 
384
- $messages[ Advanced_Ads::POST_TYPE_SLUG ] = array(
385
  // translators: %s is the number of ads.
386
  'updated' => _n( '%s ad updated.', '%s ads updated.', $counts['updated'], 'advanced-ads' ),
387
  // translators: %s is the number of ads.
@@ -392,7 +392,7 @@ class Advanced_Ads_Admin_Ad_Type {
392
  'trashed' => _n( '%s ad moved to the Trash.', '%s ads moved to the Trash.', $counts['trashed'], 'advanced-ads' ),
393
  // translators: %s is the number of ads.
394
  'untrashed' => _n( '%s ad restored from the Trash.', '%s ads restored from the Trash.', $counts['untrashed'], 'advanced-ads' ),
395
- );
396
 
397
  return $messages;
398
  }
@@ -417,7 +417,7 @@ class Advanced_Ads_Admin_Ad_Type {
417
 
418
  // order ads by title on ads list by default
419
  if ( empty( $vars['orderby'] ) ) {
420
- add_action( 'pre_get_posts', array( $this, 'default_ad_list_order' ) );
421
  }
422
 
423
  if ( $vars['orderby'] === 'expiry_date' ) {
@@ -504,13 +504,13 @@ class Advanced_Ads_Admin_Ad_Type {
504
  if ( isset( $_POST['advanced_ad']['visitor'] ) ) {
505
  $ad->set_option( 'visitor', $_POST['advanced_ad']['visitor'] );
506
  } else {
507
- $ad->set_option( 'visitor', array() );
508
  }
509
  // visitor conditions.
510
  if ( isset( $_POST['advanced_ad']['visitors'] ) ) {
511
  $ad->set_option( 'visitors', $_POST['advanced_ad']['visitors'] );
512
  } else {
513
- $ad->set_option( 'visitors', array() );
514
  }
515
  $ad->url = 0;
516
  if ( isset( $_POST['advanced_ad']['url'] ) ) {
@@ -540,16 +540,16 @@ class Advanced_Ads_Admin_Ad_Type {
540
  $ad->content = '';
541
  }
542
 
543
- $output = isset( $_POST['advanced_ad']['output'] ) ? $_POST['advanced_ad']['output'] : array();
544
 
545
  // Find Advanced Ads shortcodes.
546
  if ( ! empty( $output['allow_shortcodes'] ) ) {
547
  $shortcode_pattern = get_shortcode_regex(
548
- array(
549
  'the_ad',
550
  'the_ad_group',
551
  'the_ad_placement',
552
- )
553
  );
554
  $output['has_shortcode'] = preg_match( '/' . $shortcode_pattern . '/s', $ad->content );
555
  }
@@ -560,7 +560,7 @@ class Advanced_Ads_Admin_Ad_Type {
560
  if ( ! empty( $_POST['advanced_ad']['conditions'] ) ) {
561
  $ad->conditions = $_POST['advanced_ad']['conditions'];
562
  } else {
563
- $ad->conditions = array();
564
  }
565
  // prepare expiry date.
566
  if ( isset( $_POST['advanced_ad']['expiry_date']['enabled'] ) ) {
@@ -591,10 +591,10 @@ class Advanced_Ads_Admin_Ad_Type {
591
  $attachment = get_post( $image_id );
592
  if ( $attachment && 0 === $attachment->post_parent ) {
593
  wp_update_post(
594
- array(
595
  'ID' => $image_id,
596
  'post_parent' => $post_id,
597
- )
598
  );
599
  }
600
  }
@@ -779,7 +779,7 @@ class Advanced_Ads_Admin_Ad_Type {
779
  }
780
 
781
  // Enqueue code editor and settings for manipulating HTML.
782
- $settings = wp_enqueue_code_editor( array( 'type' => 'application/x-httpd-php' ) );
783
 
784
  // Bail if user disabled CodeMirror.
785
  if ( false === $settings ) {
@@ -802,7 +802,7 @@ class Advanced_Ads_Admin_Ad_Type {
802
  * @since 1.4.7
803
  * @see wp-admin/edit-form-advanced.php
804
  */
805
- public function ad_update_messages( $messages = array() ) {
806
  $post = get_post();
807
 
808
  // added to hide error message caused by third party code that uses post_updated_messages filter wrong.
@@ -810,7 +810,7 @@ class Advanced_Ads_Admin_Ad_Type {
810
  return $messages;
811
  }
812
 
813
- $messages[ Advanced_Ads::POST_TYPE_SLUG ] = array(
814
  0 => '', // Unused. Messages start at index 1.
815
  1 => __( 'Ad updated.', 'advanced-ads' ),
816
  4 => __( 'Ad updated.', 'advanced-ads' ), /* translators: %s: date and time of the revision */
@@ -825,7 +825,7 @@ class Advanced_Ads_Admin_Ad_Type {
825
  date_i18n( __( 'M j, Y @ G:i', 'advanced-ads' ), strtotime( $post->post_date ) )
826
  ),
827
  10 => __( 'Ad draft updated.', 'advanced-ads' ),
828
- );
829
 
830
  return $messages;
831
  }
@@ -900,10 +900,10 @@ class Advanced_Ads_Admin_Ad_Type {
900
  // Remove parent group dropdown in ad edit.
901
  add_filter(
902
  'wp_dropdown_cats',
903
- array(
904
  $this,
905
  'remove_parent_group_dropdown',
906
- ),
907
  10,
908
  2
909
  );
@@ -947,7 +947,7 @@ class Advanced_Ads_Admin_Ad_Type {
947
 
948
  $feeds = $wp_rewrite->feeds;
949
  if ( ! is_array( $feeds ) ) {
950
- $feeds = array();
951
  }
952
 
953
  // Advanced Ads post types slugs must be unique across all types.
@@ -1033,9 +1033,9 @@ class Advanced_Ads_Admin_Ad_Type {
1033
  }
1034
 
1035
  // sanitize options
1036
- update_user_meta( $user->ID, 'advanced-ads-ad-list-screen-options', array(
1037
  'show-filters' => ! empty( $_POST['advanced-ads-screen-options']['show-filters'] ),
1038
- ) );
1039
  }
1040
 
1041
  /**
26
  // Register column headers.
27
  add_filter(
28
  'manage_advanced_ads_posts_columns',
29
+ [
30
  $this,
31
  'ad_list_columns_head',
32
+ ]
33
  );
34
+ add_filter( 'manage_advanced_ads_posts_custom_column', [ $this, 'ad_list_columns' ], 10, 2 );
35
  // Add custom filter views.
36
+ add_action( 'restrict_manage_posts', [ $this, 'ad_list_add_filters' ] );
37
+ add_filter( 'default_hidden_columns', [ $this, 'hide_ad_list_columns' ], 10, 2 );
38
+ add_filter( 'bulk_post_updated_messages', [ $this, 'ad_bulk_update_messages' ], 10, 2 );
39
  // order ad lists.
40
+ add_filter( 'request', [ $this, 'ad_list_request' ] );
41
+ add_action( 'all_admin_notices', [ $this, 'no_ads_yet_notice' ] );
42
  // Manipulate post data when post is created.
43
+ add_filter( 'wp_insert_post_data', [ $this, 'prepare_insert_post_data' ] );
44
  // Save ads post type.
45
  // @source https://developer.wordpress.org/reference/hooks/save_post_post-post_type/
46
+ add_action( 'save_post_advanced_ads', [ $this, 'save_ad' ] );
47
+ add_action( 'delete_post', [ $this, 'delete_ad' ] );
48
+ add_action( 'edit_form_top', [ $this, 'edit_form_above_title' ] );
49
+ add_action( 'edit_form_after_title', [ $this, 'edit_form_below_title' ] );
50
+ add_action( 'dbx_post_sidebar', [ $this, 'edit_form_end' ] );
51
+ add_action( 'post_submitbox_misc_actions', [ $this, 'add_submit_box_meta' ] );
52
+ add_action( 'admin_enqueue_scripts', [ $this, 'use_code_editor' ] );
53
+ add_filter( 'post_updated_messages', [ $this, 'ad_update_messages' ] );
54
+ add_filter( 'gettext', [ $this, 'replace_cheating_message' ], 20, 2 );
55
+ add_action( 'current_screen', [ $this, 'run_on_ad_edit_screen' ] );
56
+ add_filter( 'pre_wp_unique_post_slug', [ $this, 'pre_wp_unique_post_slug' ], 10, 6 );
57
+ add_filter( 'view_mode_post_types', [ $this, 'remove_view_mode' ] );
58
+ add_filter( 'get_user_option_user-settings', [ $this, 'reset_view_mode_option' ] );
59
+ add_filter( 'screen_settings', [ $this, 'add_screen_options' ], 10, 2 );
60
+ add_action( 'wp_loaded', [ $this, 'save_screen_options' ] );
61
+ add_action( 'load-edit.php', [ $this, 'set_screen_options' ] );
62
 
63
  $this->post_type = constant( 'Advanced_Ads::POST_TYPE_SLUG' );
64
  }
124
  * @return string[]
125
  */
126
  public function ad_list_columns_head( $columns ) {
127
+ $new_columns = [];
128
 
129
  foreach ( $columns as $key => $value ) {
130
  $new_columns[ $key ] = $value;
144
  }
145
  }
146
 
147
+ $allowed_columns = [
148
  'cb', // checkbox.
149
  'title',
150
  'author',
155
  'ad_timing',
156
  'ad_shortcode',
157
  'taxonomy-advanced_ads_groups',
158
+ ];
159
 
160
  /**
161
  * Filter the allowed columns for Advanced Ads post type list.
315
  ob_start();
316
  do_action_ref_array(
317
  'advanced-ads-ad-list-timing-column-after',
318
+ [
319
  $ad,
320
  &$html_classes,
321
+ ]
322
  );
323
  $content_after = ob_get_clean();
324
 
381
  public function ad_bulk_update_messages( array $messages, array $counts ) {
382
  $post = get_post();
383
 
384
+ $messages[ Advanced_Ads::POST_TYPE_SLUG ] = [
385
  // translators: %s is the number of ads.
386
  'updated' => _n( '%s ad updated.', '%s ads updated.', $counts['updated'], 'advanced-ads' ),
387
  // translators: %s is the number of ads.
392
  'trashed' => _n( '%s ad moved to the Trash.', '%s ads moved to the Trash.', $counts['trashed'], 'advanced-ads' ),
393
  // translators: %s is the number of ads.
394
  'untrashed' => _n( '%s ad restored from the Trash.', '%s ads restored from the Trash.', $counts['untrashed'], 'advanced-ads' ),
395
+ ];
396
 
397
  return $messages;
398
  }
417
 
418
  // order ads by title on ads list by default
419
  if ( empty( $vars['orderby'] ) ) {
420
+ add_action( 'pre_get_posts', [ $this, 'default_ad_list_order' ] );
421
  }
422
 
423
  if ( $vars['orderby'] === 'expiry_date' ) {
504
  if ( isset( $_POST['advanced_ad']['visitor'] ) ) {
505
  $ad->set_option( 'visitor', $_POST['advanced_ad']['visitor'] );
506
  } else {
507
+ $ad->set_option( 'visitor', [] );
508
  }
509
  // visitor conditions.
510
  if ( isset( $_POST['advanced_ad']['visitors'] ) ) {
511
  $ad->set_option( 'visitors', $_POST['advanced_ad']['visitors'] );
512
  } else {
513
+ $ad->set_option( 'visitors', [] );
514
  }
515
  $ad->url = 0;
516
  if ( isset( $_POST['advanced_ad']['url'] ) ) {
540
  $ad->content = '';
541
  }
542
 
543
+ $output = isset( $_POST['advanced_ad']['output'] ) ? $_POST['advanced_ad']['output'] : [];
544
 
545
  // Find Advanced Ads shortcodes.
546
  if ( ! empty( $output['allow_shortcodes'] ) ) {
547
  $shortcode_pattern = get_shortcode_regex(
548
+ [
549
  'the_ad',
550
  'the_ad_group',
551
  'the_ad_placement',
552
+ ]
553
  );
554
  $output['has_shortcode'] = preg_match( '/' . $shortcode_pattern . '/s', $ad->content );
555
  }
560
  if ( ! empty( $_POST['advanced_ad']['conditions'] ) ) {
561
  $ad->conditions = $_POST['advanced_ad']['conditions'];
562
  } else {
563
+ $ad->conditions = [];
564
  }
565
  // prepare expiry date.
566
  if ( isset( $_POST['advanced_ad']['expiry_date']['enabled'] ) ) {
591
  $attachment = get_post( $image_id );
592
  if ( $attachment && 0 === $attachment->post_parent ) {
593
  wp_update_post(
594
+ [
595
  'ID' => $image_id,
596
  'post_parent' => $post_id,
597
+ ]
598
  );
599
  }
600
  }
779
  }
780
 
781
  // Enqueue code editor and settings for manipulating HTML.
782
+ $settings = wp_enqueue_code_editor( [ 'type' => 'application/x-httpd-php' ] );
783
 
784
  // Bail if user disabled CodeMirror.
785
  if ( false === $settings ) {
802
  * @since 1.4.7
803
  * @see wp-admin/edit-form-advanced.php
804
  */
805
+ public function ad_update_messages( $messages = [] ) {
806
  $post = get_post();
807
 
808
  // added to hide error message caused by third party code that uses post_updated_messages filter wrong.
810
  return $messages;
811
  }
812
 
813
+ $messages[ Advanced_Ads::POST_TYPE_SLUG ] = [
814
  0 => '', // Unused. Messages start at index 1.
815
  1 => __( 'Ad updated.', 'advanced-ads' ),
816
  4 => __( 'Ad updated.', 'advanced-ads' ), /* translators: %s: date and time of the revision */
825
  date_i18n( __( 'M j, Y @ G:i', 'advanced-ads' ), strtotime( $post->post_date ) )
826
  ),
827
  10 => __( 'Ad draft updated.', 'advanced-ads' ),
828
+ ];
829
 
830
  return $messages;
831
  }
900
  // Remove parent group dropdown in ad edit.
901
  add_filter(
902
  'wp_dropdown_cats',
903
+ [
904
  $this,
905
  'remove_parent_group_dropdown',
906
+ ],
907
  10,
908
  2
909
  );
947
 
948
  $feeds = $wp_rewrite->feeds;
949
  if ( ! is_array( $feeds ) ) {
950
+ $feeds = [];
951
  }
952
 
953
  // Advanced Ads post types slugs must be unique across all types.
1033
  }
1034
 
1035
  // sanitize options
1036
+ update_user_meta( $user->ID, 'advanced-ads-ad-list-screen-options', [
1037
  'show-filters' => ! empty( $_POST['advanced-ads-screen-options']['show-filters'] ),
1038
+ ] );
1039
  }
1040
 
1041
  /**
admin/includes/class-admin-upgrades.php CHANGED
@@ -11,15 +11,15 @@ class Advanced_Ads_Admin_Upgrades {
11
  */
12
  public function __construct() {
13
  // Show premium ad types on the ad edit page.
14
- add_action( 'advanced-ads-ad-types', array( $this, 'ad_types' ), 1000 );
15
  // Show notice in Ad Parameters when someone uses an Ad Manager ad in the plain text code field.
16
- add_filter( 'advanced-ads-ad-notices', array( $this, 'ad_notices' ), 10, 3 );
17
  // Show AMP options on ad edit page of AdSense ads.
18
- add_action( 'advanced-ads-gadsense-extra-ad-param', array( $this, 'adsense_type_amp_options' ) );
19
  // Add Duplicate link to ad overview list.
20
- add_filter( 'post_row_actions', array( $this, 'render_duplicate_link' ), 10, 2 );
21
  // Add Duplicate link to post submit box.
22
- add_action( 'post_submitbox_start', array( $this, 'render_duplicate_link_in_submit_box' ) );
23
  }
24
 
25
  /**
@@ -63,11 +63,11 @@ class Advanced_Ads_Admin_Upgrades {
63
  $title = ! empty( $title ) ? $title : __( 'Upgrade', 'advanced-ads' );
64
  $url = ! empty( $url ) ? $url : ADVADS_URL . 'add-ons/';
65
 
66
- $url = add_query_arg( array(
67
  'utm_source' => 'advanced-ads',
68
  'utm_medium' => 'link',
69
  'utm_campaign' => $utm_campaign,
70
- ), $url );
71
 
72
  include ADVADS_BASE_PATH . 'admin/views/upgrades/upgrade-link.php';
73
  }
@@ -99,14 +99,14 @@ class Advanced_Ads_Admin_Upgrades {
99
  if ( ! defined( 'AAGAM_VERSION' ) && 'ad-parameters-box' === $box['id'] ) {
100
  $ad = new Advanced_Ads_Ad( $post->ID );
101
  if ( 'plain' === $ad->type && strpos( $ad->content, 'div-gpt-ad-' ) ) {
102
- $notices[] = array(
103
  'text' => sprintf(
104
  // Translators: %1$s opening a tag, %2$s closing a tag.
105
  esc_html__( 'This looks like a Google Ad Manager ad. Use the %1$sGAM Integration%2$s.', 'advanced' ),
106
  '<a href="' . ADVADS_URL . 'add-ons/google-ad-manager/?utm_source=advanced-ads&utm_medium=link&utm_campaign=upgrade-ad-parameters-gam" target="_blank">',
107
  '</a>'
108
  ) . ' ' . __( 'A quick and error-free way of implementing ad units from your Google Ad Manager account.', 'advanced-ads' ),
109
- );
110
  }
111
  }
112
 
11
  */
12
  public function __construct() {
13
  // Show premium ad types on the ad edit page.
14
+ add_action( 'advanced-ads-ad-types', [ $this, 'ad_types' ], 1000 );
15
  // Show notice in Ad Parameters when someone uses an Ad Manager ad in the plain text code field.
16
+ add_filter( 'advanced-ads-ad-notices', [ $this, 'ad_notices' ], 10, 3 );
17
  // Show AMP options on ad edit page of AdSense ads.
18
+ add_action( 'advanced-ads-gadsense-extra-ad-param', [ $this, 'adsense_type_amp_options' ] );
19
  // Add Duplicate link to ad overview list.
20
+ add_filter( 'post_row_actions', [ $this, 'render_duplicate_link' ], 10, 2 );
21
  // Add Duplicate link to post submit box.
22
+ add_action( 'post_submitbox_start', [ $this, 'render_duplicate_link_in_submit_box' ] );
23
  }
24
 
25
  /**
63
  $title = ! empty( $title ) ? $title : __( 'Upgrade', 'advanced-ads' );
64
  $url = ! empty( $url ) ? $url : ADVADS_URL . 'add-ons/';
65
 
66
+ $url = add_query_arg( [
67
  'utm_source' => 'advanced-ads',
68
  'utm_medium' => 'link',
69
  'utm_campaign' => $utm_campaign,
70
+ ], $url );
71
 
72
  include ADVADS_BASE_PATH . 'admin/views/upgrades/upgrade-link.php';
73
  }
99
  if ( ! defined( 'AAGAM_VERSION' ) && 'ad-parameters-box' === $box['id'] ) {
100
  $ad = new Advanced_Ads_Ad( $post->ID );
101
  if ( 'plain' === $ad->type && strpos( $ad->content, 'div-gpt-ad-' ) ) {
102
+ $notices[] = [
103
  'text' => sprintf(
104
  // Translators: %1$s opening a tag, %2$s closing a tag.
105
  esc_html__( 'This looks like a Google Ad Manager ad. Use the %1$sGAM Integration%2$s.', 'advanced' ),
106
  '<a href="' . ADVADS_URL . 'add-ons/google-ad-manager/?utm_source=advanced-ads&utm_medium=link&utm_campaign=upgrade-ad-parameters-gam" target="_blank">',
107
  '</a>'
108
  ) . ' ' . __( 'A quick and error-free way of implementing ad units from your Google Ad Manager account.', 'advanced-ads' ),
109
+ ];
110
  }
111
  }
112
 
admin/includes/class-licenses.php CHANGED
@@ -24,12 +24,12 @@ class Advanced_Ads_Admin_Licenses {
24
  */
25
  private function __construct() {
26
  if ( ! defined( 'DOING_AJAX' ) ) {
27
- add_action( 'load-plugins.php', array( $this, 'check_plugin_licenses' ) );
28
  }
29
- add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
30
 
31
  // todo: check if this is loaded late enough and all add-ons are registered already.
32
- add_filter( 'upgrader_pre_download', array( $this, 'addon_upgrade_filter' ), 10, 3 );
33
  }
34
 
35
  /**
@@ -38,9 +38,9 @@ class Advanced_Ads_Admin_Licenses {
38
  public function wp_plugins_loaded() {
39
 
40
  // check for add-on updates.
41
- add_action( 'admin_init', array( $this, 'add_on_updater' ), 1 );
42
  // react on API update checks
43
- add_action( 'http_api_debug', array( $this, 'update_license_after_version_info' ), 10, 5 );
44
  }
45
 
46
  /**
@@ -68,14 +68,14 @@ class Advanced_Ads_Admin_Licenses {
68
  }
69
 
70
  // gather all add-on plugin files.
71
- $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
72
  foreach ( $add_ons as $_add_on ) {
73
 
74
  // check license status.
75
  if ( $this->get_license_status( $_add_on['options_slug'] ) !== 'valid' ) {
76
  // register warning.
77
  $plugin_file = plugin_basename( $_add_on['path'] );
78
- add_action( 'after_plugin_row_' . $plugin_file, array( $this, 'add_plugin_list_license_notice' ), 10, 2 );
79
  }
80
  }
81
  }
@@ -141,12 +141,12 @@ class Advanced_Ads_Admin_Licenses {
141
  */
142
  remove_filter( 'home_url', 'mltlngg_get_url_translated' );
143
 
144
- $api_params = array(
145
  'edd_action' => 'activate_license',
146
  'license' => $license_key,
147
  'item_name' => urlencode( $plugin_name ),
148
  'url' => home_url(),
149
- );
150
 
151
  /**
152
  * Re-add the filter removed from above
@@ -158,11 +158,11 @@ class Advanced_Ads_Admin_Licenses {
158
  // Call the custom API.
159
  $response = wp_remote_post(
160
  self::API_ENDPOINT,
161
- array(
162
  'timeout' => 15,
163
  'sslverify' => false,
164
  'body' => $api_params,
165
- )
166
  );
167
 
168
  // show license debug output if constant is set.
@@ -201,7 +201,7 @@ class Advanced_Ads_Admin_Licenses {
201
  // display activation problem.
202
  if ( ! empty( $license_data->error ) ) {
203
  // user friendly texts for errors.
204
- $errors = array(
205
  'license_not_activable' => __( 'This is the bundle license key.', 'advanced-ads' ),
206
  'item_name_mismatch' => __( 'This is not the correct key for this add-on.', 'advanced-ads' ),
207
  'no_activations_left' => __( 'There are no activations left.', 'advanced-ads' )
@@ -218,7 +218,7 @@ class Advanced_Ads_Admin_Licenses {
218
  '<a href="' . ADVADS_URL . 'account/upgrades/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses-activations-left" target="_blank">',
219
  '</a>'
220
  ),
221
- );
222
  $error = isset( $errors[ $license_data->error ] ) ? $errors[ $license_data->error ] : $license_data->error;
223
  if ( 'expired' === $license_data->error ) {
224
  return 'ex';
@@ -261,7 +261,7 @@ class Advanced_Ads_Admin_Licenses {
261
  if ( isset( $response['body'] ) ) {
262
  // look for the IP address in this line: `<td><span>95.90.238.103</span></td>`.
263
  $pattern = '/<span>([.0-9]*)<\/span>/';
264
- $matches = array();
265
  preg_match( $pattern, $response['body'], $matches );
266
  $ip = isset( $matches[1] ) ? $matches[1] : '–';
267
  $blocked_information = 'IP: ' . $ip;
@@ -290,17 +290,17 @@ class Advanced_Ads_Admin_Licenses {
290
  return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
291
  }
292
 
293
- $api_params = array(
294
  'edd_action' => 'check_license',
295
  'license' => $license_key,
296
  'item_name' => urlencode( $plugin_name ),
297
- );
298
  $response = wp_remote_get(
299
  add_query_arg( $api_params, ADVADS_URL ),
300
- array(
301
  'timeout' => 15,
302
  'sslverify' => false,
303
- )
304
  );
305
  if ( is_wp_error( $response ) ) {
306
  return false;
@@ -340,19 +340,19 @@ class Advanced_Ads_Admin_Licenses {
340
  return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
341
  }
342
 
343
- $api_params = array(
344
  'edd_action' => 'deactivate_license',
345
  'license' => $license_key,
346
  'item_name' => urlencode( $plugin_name ),
347
- );
348
  // send the remote request.
349
  $response = wp_remote_post(
350
  self::API_ENDPOINT,
351
- array(
352
  'body' => $api_params,
353
  'timeout' => 15,
354
  'sslverify' => false,
355
- )
356
  );
357
 
358
  // show license debug output if constant is set.
@@ -401,7 +401,7 @@ class Advanced_Ads_Admin_Licenses {
401
  * @return string[]
402
  */
403
  public function get_licenses() {
404
- return get_option( ADVADS_SLUG . '-licenses', array() );
405
  }
406
 
407
  /**
@@ -409,7 +409,7 @@ class Advanced_Ads_Admin_Licenses {
409
  *
410
  * @param array $licenses licenses.
411
  */
412
- public function save_licenses( $licenses = array() ) {
413
  update_option( ADVADS_SLUG . '-licenses', $licenses );
414
  }
415
 
@@ -438,7 +438,7 @@ class Advanced_Ads_Admin_Licenses {
438
  ARRAY_FILTER_USE_KEY
439
  );
440
 
441
- return array() !== $valid && max( array_count_values( $valid ) ) > 1;
442
  }
443
 
444
  /**
@@ -503,13 +503,13 @@ class Advanced_Ads_Admin_Licenses {
503
  * options_slug
504
  * short option slug (=key)
505
  */
506
- $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
507
 
508
- if ( array() === $add_ons ) {
509
  return;
510
  }
511
 
512
- $licenses = get_option( ADVADS_SLUG . '-licenses', array() );
513
 
514
  foreach ( $add_ons as $_add_on_key => $_add_on ) {
515
 
@@ -526,17 +526,17 @@ class Advanced_Ads_Admin_Licenses {
526
 
527
  // by default, EDD looks every 3 hours for updates. The following code block changes that to 24 hours. set_expiration_of_update_option delivers that value.
528
  $option_key = 'pre_update_option_edd_sl_' . md5( serialize( basename( $_add_on['path'], '.php' ) . $license_key ) );
529
- add_filter( $option_key, array( $this, 'set_expiration_of_update_option' ) );
530
 
531
  new ADVADS_SL_Plugin_Updater(
532
  self::API_ENDPOINT,
533
  $_add_on['path'],
534
- array(
535
  'version' => $_add_on['version'],
536
  'license' => $license_key,
537
  'item_name' => $_add_on['name'],
538
  'author' => 'Advanced Ads',
539
- )
540
  );
541
  }
542
  }
@@ -602,7 +602,7 @@ class Advanced_Ads_Admin_Licenses {
602
  * @return array array with the add-on data
603
  */
604
  private function get_installed_add_on_by_name( $name = '' ) {
605
- $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
606
 
607
  if ( is_array( $add_ons ) ) {
608
  foreach ( $add_ons as $key => $_add_on ) {
@@ -620,9 +620,9 @@ class Advanced_Ads_Admin_Licenses {
620
  * can be used to display information for any Pro user only, like link to direct support
621
  */
622
  public static function any_license_valid() {
623
- $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
624
 
625
- if ( array() === $add_ons ) {
626
  return false;
627
  }
628
 
@@ -705,7 +705,7 @@ class Advanced_Ads_Admin_Licenses {
705
  return $response;
706
  }
707
 
708
- $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
709
 
710
  // look for the add-on with the appropriate license key
711
  foreach ( $add_ons as $_add_on_key => $_add_on ) {
24
  */
25
  private function __construct() {
26
  if ( ! defined( 'DOING_AJAX' ) ) {
27
+ add_action( 'load-plugins.php', [ $this, 'check_plugin_licenses' ] );
28
  }
29
+ add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ] );
30
 
31
  // todo: check if this is loaded late enough and all add-ons are registered already.
32
+ add_filter( 'upgrader_pre_download', [ $this, 'addon_upgrade_filter' ], 10, 3 );
33
  }
34
 
35
  /**
38
  public function wp_plugins_loaded() {
39
 
40
  // check for add-on updates.
41
+ add_action( 'admin_init', [ $this, 'add_on_updater' ], 1 );
42
  // react on API update checks
43
+ add_action( 'http_api_debug', [ $this, 'update_license_after_version_info' ], 10, 5 );
44
  }
45
 
46
  /**
68
  }
69
 
70
  // gather all add-on plugin files.
71
+ $add_ons = apply_filters( 'advanced-ads-add-ons', [] );
72
  foreach ( $add_ons as $_add_on ) {
73
 
74
  // check license status.
75
  if ( $this->get_license_status( $_add_on['options_slug'] ) !== 'valid' ) {
76
  // register warning.
77
  $plugin_file = plugin_basename( $_add_on['path'] );
78
+ add_action( 'after_plugin_row_' . $plugin_file, [ $this, 'add_plugin_list_license_notice' ], 10, 2 );
79
  }
80
  }
81
  }
141
  */
142
  remove_filter( 'home_url', 'mltlngg_get_url_translated' );
143
 
144
+ $api_params = [
145
  'edd_action' => 'activate_license',
146
  'license' => $license_key,
147
  'item_name' => urlencode( $plugin_name ),
148
  'url' => home_url(),
149
+ ];
150
 
151
  /**
152
  * Re-add the filter removed from above
158
  // Call the custom API.
159
  $response = wp_remote_post(
160
  self::API_ENDPOINT,
161
+ [
162
  'timeout' => 15,
163
  'sslverify' => false,
164
  'body' => $api_params,
165
+ ]
166
  );
167
 
168
  // show license debug output if constant is set.
201
  // display activation problem.
202
  if ( ! empty( $license_data->error ) ) {
203
  // user friendly texts for errors.
204
+ $errors = [
205
  'license_not_activable' => __( 'This is the bundle license key.', 'advanced-ads' ),
206
  'item_name_mismatch' => __( 'This is not the correct key for this add-on.', 'advanced-ads' ),
207
  'no_activations_left' => __( 'There are no activations left.', 'advanced-ads' )
218
  '<a href="' . ADVADS_URL . 'account/upgrades/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses-activations-left" target="_blank">',
219
  '</a>'
220
  ),
221
+ ];
222
  $error = isset( $errors[ $license_data->error ] ) ? $errors[ $license_data->error ] : $license_data->error;
223
  if ( 'expired' === $license_data->error ) {
224
  return 'ex';
261
  if ( isset( $response['body'] ) ) {
262
  // look for the IP address in this line: `<td><span>95.90.238.103</span></td>`.
263
  $pattern = '/<span>([.0-9]*)<\/span>/';
264
+ $matches = [];
265
  preg_match( $pattern, $response['body'], $matches );
266
  $ip = isset( $matches[1] ) ? $matches[1] : '–';
267
  $blocked_information = 'IP: ' . $ip;
290
  return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
291
  }
292
 
293
+ $api_params = [
294
  'edd_action' => 'check_license',
295
  'license' => $license_key,
296
  'item_name' => urlencode( $plugin_name ),
297
+ ];
298
  $response = wp_remote_get(
299
  add_query_arg( $api_params, ADVADS_URL ),
300
+ [
301
  'timeout' => 15,
302
  'sslverify' => false,
303
+ ]
304
  );
305
  if ( is_wp_error( $response ) ) {
306
  return false;
340
  return apply_filters( 'advanced_ads_license_' . $options_slug, false, __METHOD__, $plugin_name, $options_slug, $license_key );
341
  }
342
 
343
+ $api_params = [
344
  'edd_action' => 'deactivate_license',
345
  'license' => $license_key,
346
  'item_name' => urlencode( $plugin_name ),
347
+ ];
348
  // send the remote request.
349
  $response = wp_remote_post(
350
  self::API_ENDPOINT,
351
+ [
352
  'body' => $api_params,
353
  'timeout' => 15,
354
  'sslverify' => false,
355
+ ]
356
  );
357
 
358
  // show license debug output if constant is set.
401
  * @return string[]
402
  */
403
  public function get_licenses() {
404
+ return get_option( ADVADS_SLUG . '-licenses', [] );
405
  }
406
 
407
  /**
409
  *
410
  * @param array $licenses licenses.
411
  */
412
+ public function save_licenses( $licenses = [] ) {
413
  update_option( ADVADS_SLUG . '-licenses', $licenses );
414
  }
415
 
438
  ARRAY_FILTER_USE_KEY
439
  );
440
 
441
+ return [] !== $valid && max( array_count_values( $valid ) ) > 1;
442
  }
443
 
444
  /**
503
  * options_slug
504
  * short option slug (=key)
505
  */
506
+ $add_ons = apply_filters( 'advanced-ads-add-ons', [] );
507
 
508
+ if ( [] === $add_ons ) {
509
  return;
510
  }
511
 
512
+ $licenses = get_option( ADVADS_SLUG . '-licenses', [] );
513
 
514
  foreach ( $add_ons as $_add_on_key => $_add_on ) {
515
 
526
 
527
  // by default, EDD looks every 3 hours for updates. The following code block changes that to 24 hours. set_expiration_of_update_option delivers that value.
528
  $option_key = 'pre_update_option_edd_sl_' . md5( serialize( basename( $_add_on['path'], '.php' ) . $license_key ) );
529
+ add_filter( $option_key, [ $this, 'set_expiration_of_update_option' ] );
530
 
531
  new ADVADS_SL_Plugin_Updater(
532
  self::API_ENDPOINT,
533
  $_add_on['path'],
534
+ [
535
  'version' => $_add_on['version'],
536
  'license' => $license_key,
537
  'item_name' => $_add_on['name'],
538
  'author' => 'Advanced Ads',
539
+ ]
540
  );
541
  }
542
  }
602
  * @return array array with the add-on data
603
  */
604
  private function get_installed_add_on_by_name( $name = '' ) {
605
+ $add_ons = apply_filters( 'advanced-ads-add-ons', [] );
606
 
607
  if ( is_array( $add_ons ) ) {
608
  foreach ( $add_ons as $key => $_add_on ) {
620
  * can be used to display information for any Pro user only, like link to direct support
621
  */
622
  public static function any_license_valid() {
623
+ $add_ons = apply_filters( 'advanced-ads-add-ons', [] );
624
 
625
+ if ( [] === $add_ons ) {
626
  return false;
627
  }
628
 
705
  return $response;
706
  }
707
 
708
+ $add_ons = apply_filters( 'advanced-ads-add-ons', [] );
709
 
710
  // look for the add-on with the appropriate license key
711
  foreach ( $add_ons as $_add_on_key => $_add_on ) {
admin/includes/class-list-filters.php CHANGED
@@ -18,21 +18,21 @@ class Advanced_Ads_Ad_List_Filters {
18
  *
19
  * @var array
20
  */
21
- protected $all_ads = array();
22
 
23
  /**
24
  * Ads ad groups
25
  *
26
  * @var array
27
  */
28
- protected $all_groups = array();
29
 
30
  /**
31
  * Ads in each group
32
  *
33
  * @var array
34
  */
35
- protected $ads_in_groups = array();
36
 
37
  /**
38
  * Ads array with ID as key
@@ -40,37 +40,37 @@ class Advanced_Ads_Ad_List_Filters {
40
  * @var array
41
  * @deprecated 1.31.0 -- we don't needs ads indexed by id, since we have all ads.
42
  */
43
- protected $adsbyid = array();
44
 
45
  /**
46
  * All filters available in the current ad list table
47
  *
48
  * @var array
49
  */
50
- protected $all_filters = array();
51
 
52
  /**
53
  * All ad options for the ad list table
54
  *
55
  * @var array
56
  */
57
- protected $all_ads_options = array();
58
 
59
  /**
60
  * Constructs the unique instance.
61
  */
62
  private function __construct() {
63
  if ( is_admin() && ! wp_doing_ajax() ) {
64
- add_filter( 'posts_results', array( $this, 'post_results' ), 10, 2 );
65
- add_filter( 'post_limits', array( $this, 'limit_filter' ), 10, 2 );
66
  }
67
 
68
- add_filter( 'views_edit-' . Advanced_Ads::POST_TYPE_SLUG, array( $this, 'add_expired_view' ) );
69
- add_filter( 'views_edit-' . Advanced_Ads::POST_TYPE_SLUG, array( $this, 'add_expiring_view' ) );
70
- add_action( 'restrict_manage_posts', array( $this, 'send_addate_in_filter' ) );
71
 
72
- add_action( 'manage_posts_extra_tablenav', array( $this, 'ad_views' ) );
73
- add_action( 'admin_enqueue_scripts', array( $this, 'ad_list_scripts' ), 11 );
74
  }
75
 
76
  /**
@@ -100,17 +100,17 @@ class Advanced_Ads_Ad_List_Filters {
100
  * @return null
101
  */
102
  private function collect_filters( $posts ) {
103
- $all_sizes = array();
104
- $all_types = array();
105
- $all_dates = array();
106
- $all_groups = array();
107
-
108
- $all_filters = array(
109
- 'all_sizes' => array(),
110
- 'all_types' => array(),
111
- 'all_dates' => array(),
112
- 'all_groups' => array(),
113
- );
114
 
115
  // can not filter correctly with "trashed" posts. Do not display any filtering option in this case.
116
  if ( isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash' ) {
@@ -189,7 +189,7 @@ class Advanced_Ads_Ad_List_Filters {
189
  $this->adsbyid[ $post->ID ] = $post;
190
  $this->all_ads_options[ $post->ID ] = get_post_meta( $post->ID, 'advanced_ads_ad_options', true );
191
  if ( empty( $this->all_ads_options[ $post->ID ] ) ) {
192
- $this->all_ads_options[ $post->ID ] = array();
193
  }
194
 
195
  // convert all expiration dates.
@@ -209,7 +209,7 @@ class Advanced_Ads_Ad_List_Filters {
209
  global $wpdb;
210
 
211
  $_groups = Advanced_Ads::get_ad_groups();
212
- $groups = array();
213
 
214
  /**
215
  * It looks like there might be a third-party conflict we haven’t been able to reproduce that causes the group
@@ -219,15 +219,15 @@ class Advanced_Ads_Ad_List_Filters {
219
  if ( empty( $g->term_id ) ) {
220
  continue;
221
  }
222
- $groups[ $g->term_id ] = array(
223
  'name' => $g->name,
224
  'slug' => $g->slug,
225
- );
226
  }
227
 
228
  $group_ids = array_keys( $groups );
229
  $group_ids_str = implode( ',', $group_ids );
230
- $term_relations = array();
231
 
232
  /**
233
  * We need to use %1$s below, because when using %s the $wpdb->prepare function adds quotation marks around the value,
@@ -317,19 +317,19 @@ class Advanced_Ads_Ad_List_Filters {
317
  if ( (int) $the_query->query_vars['s'] !== 0 ) {
318
  global $wpdb;
319
  $single_ad = ( new Advanced_Ads_Model( $wpdb ) )->get_ads(
320
- array(
321
  'p' => (int) $the_query->query_vars['s'],
322
- 'post_status' => array( 'any' ),
323
- )
324
  );
325
 
326
  if ( ! empty( $single_ad ) ) {
327
  // Head to the ad edit page if one and only one ad found.
328
  if ( empty( $posts ) ) {
329
- wp_safe_redirect( add_query_arg( array(
330
  'post' => $single_ad[0]->ID,
331
  'action' => 'edit',
332
- ), admin_url( 'post.php' ) ) );
333
  die;
334
  }
335
 
@@ -382,8 +382,8 @@ class Advanced_Ads_Ad_List_Filters {
382
  /**
383
  * Filter post status
384
  */
385
- if ( isset( $request['post_status'] ) && '' !== $request['post_status'] && ! in_array( $request['post_status'], array( 'all', 'trash' ), true ) ) {
386
- $new_posts = array();
387
  foreach ( $this->all_ads as $post ) {
388
  if ( $request['post_status'] === $post->post_status ) {
389
  $new_posts[] = $post;
@@ -399,7 +399,7 @@ class Advanced_Ads_Ad_List_Filters {
399
  */
400
  if ( isset( $request['author'] ) && '' !== $request['author'] ) {
401
  $author = absint( $request['author'] );
402
- $new_posts = array();
403
  $the_list = $using_original ? $this->all_ads : $posts;
404
  foreach ( $the_list as $post ) {
405
  if ( absint( $post->post_author ) === $author ) {
@@ -415,7 +415,7 @@ class Advanced_Ads_Ad_List_Filters {
415
  * Filter groups
416
  */
417
  if ( isset( $request['adgroup'] ) && '' !== $request['adgroup'] ) {
418
- $new_posts = array();
419
  $the_list = $using_original ? $this->all_ads : $posts;
420
  foreach ( $the_list as $post ) {
421
  if ( isset( $this->ads_in_groups[ absint( $request['adgroup'] ) ] ) && in_array( $post->ID, $this->ads_in_groups[ absint( $request['adgroup'] ) ], true ) ) {
@@ -442,13 +442,13 @@ class Advanced_Ads_Ad_List_Filters {
442
  $q = $wpdb->prepare( $q, $term, Advanced_Ads::AD_GROUP_TAXONOMY );
443
 
444
  $object_ids = $wpdb->get_results( $q, 'ARRAY_A' );
445
- $ads_in_taxo = array();
446
 
447
  foreach ( $object_ids as $object ) {
448
  $ads_in_taxo[] = absint( $object['object_id'] );
449
  }
450
 
451
- $new_posts = array();
452
  $the_list = $using_original ? $this->all_ads : $posts;
453
  foreach ( $the_list as $post ) {
454
  if ( in_array( $post->ID, $ads_in_taxo, true ) ) {
@@ -464,7 +464,7 @@ class Advanced_Ads_Ad_List_Filters {
464
  * Filter ad type
465
  */
466
  if ( isset( $request['adtype'] ) && '' !== $request['adtype'] ) {
467
- $new_posts = array();
468
  $the_list = $using_original ? $this->all_ads : $posts;
469
  foreach ( $the_list as $post ) {
470
  $option = $this->all_ads_options[ $post->ID ];
@@ -481,7 +481,7 @@ class Advanced_Ads_Ad_List_Filters {
481
  * Filter ad size
482
  */
483
  if ( isset( $request['adsize'] ) && '' !== $request['adsize'] ) {
484
- $new_posts = array();
485
  $the_list = $using_original ? $this->all_ads : $posts;
486
  foreach ( $the_list as $post ) {
487
  $option = $this->all_ads_options[ $post->ID ];
@@ -512,7 +512,7 @@ class Advanced_Ads_Ad_List_Filters {
512
 
513
  if ( isset( $request['addate'] ) ) {
514
  $filter_value = urldecode( $request['addate'] );
515
- if ( in_array( $filter_value, array( 'advads-filter-expired', 'advads-filter-expiring' ), true ) ) {
516
  $posts = $this->filter_expired_ads( $filter_value, $using_original ? $this->all_ads : $posts );
517
  }
518
  }
@@ -551,12 +551,12 @@ class Advanced_Ads_Ad_List_Filters {
551
  }
552
  $views[ Advanced_Ads_Ad_Expiration::POST_STATUS ] = sprintf(
553
  '<a href="%s" %s>%s <span class="count">(%d)</span></a>',
554
- add_query_arg( array(
555
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
556
  'addate' => 'advads-filter-expired',
557
  'orderby' => 'expiry_date',
558
  'order' => 'DESC',
559
- ), 'edit.php' ),
560
  isset( $_REQUEST['addate'] ) && $_REQUEST['addate'] === 'advads-filter-expired' ? 'class="current" aria-current="page"' : '',
561
  esc_attr_x( 'Expired', 'Post list header for expired ads.', 'advanced-ads' ),
562
  $count
@@ -571,10 +571,10 @@ class Advanced_Ads_Ad_List_Filters {
571
  * @return int
572
  */
573
  private function count_expired_ads() {
574
- return ( new WP_Query( array(
575
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
576
  'post_status' => Advanced_Ads_Ad_Expiration::POST_STATUS,
577
- ) ) )->found_posts;
578
  }
579
 
580
  /**
@@ -591,12 +591,12 @@ class Advanced_Ads_Ad_List_Filters {
591
  }
592
  $views['expiring'] = sprintf(
593
  '<a href="%s" %s>%s <span class="count">(%d)</span></a>',
594
- add_query_arg( array(
595
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
596
  'addate' => 'advads-filter-expiring',
597
  'orderby' => 'expiry_date',
598
  'order' => 'ASC',
599
- ), 'edit.php' ),
600
  isset( $_REQUEST['addate'] ) && $_REQUEST['addate'] === 'advads-filter-expiring' ? 'class="current" aria-current="page"' : '',
601
  esc_attr_x( 'Expiring', 'Post list header for ads expiring in the future.', 'advanced-ads' ),
602
  $count
@@ -611,18 +611,18 @@ class Advanced_Ads_Ad_List_Filters {
611
  * @return int
612
  */
613
  private function count_expiring_ads() {
614
- return ( new WP_Query( array(
615
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
616
  'post_status' => 'any',
617
- 'meta_query' => array(
618
- array(
619
  'key' => Advanced_Ads_Ad_Expiration::POST_META,
620
  'value' => current_time( 'mysql', true ),
621
  'compare' => '>=',
622
  'type' => 'DATETIME',
623
- ),
624
- ),
625
- ) ) )->found_posts;
626
  }
627
 
628
  /**
@@ -633,7 +633,7 @@ class Advanced_Ads_Ad_List_Filters {
633
  private function views_order() {
634
  static $views_order;
635
  if ( $views_order === null ) {
636
- $views_order = array_flip( array( 'all', 'mine', 'publish', 'future', 'expiring', Advanced_Ads_Ad_Expiration::POST_STATUS, 'draft', 'pending', 'trash' ) );
637
  }
638
 
639
  return $views_order;
@@ -676,7 +676,7 @@ class Advanced_Ads_Ad_List_Filters {
676
  }
677
 
678
  // unregister the hook to prevent the navigation to appear again below the footer
679
- remove_action( 'manage_posts_extra_tablenav', array( $this, 'ad_views' ) );
680
 
681
  $views = $wp_list_table->get_views();
682
  /**
@@ -694,18 +694,18 @@ class Advanced_Ads_Ad_List_Filters {
694
  }
695
 
696
  $wp_list_table->screen->render_screen_reader_content( 'heading_views' );
697
- $views_new = array();
698
 
699
- $is_all = count( array_diff_key( $_GET, array(
700
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
701
  'orderby' => '',
702
  'order' => '',
703
  'paged' => '',
704
  'mode' => '',
705
- ) ) ) === 0;
706
 
707
  foreach ( $views as $class => $view ) {
708
- $view = str_replace( array( ')', '(' ), array( '', '' ), $view );
709
  $class .= strpos( $view, 'current' ) ? ' advads-button-primary' : ' advads-button-secondary';
710
  $views_new[ $class ] = $view;
711
  }
18
  *
19
  * @var array
20
  */
21
+ protected $all_ads = [];
22
 
23
  /**
24
  * Ads ad groups
25
  *
26
  * @var array
27
  */
28
+ protected $all_groups = [];
29
 
30
  /**
31
  * Ads in each group
32
  *
33
  * @var array
34
  */
35
+ protected $ads_in_groups = [];
36
 
37
  /**
38
  * Ads array with ID as key
40
  * @var array
41
  * @deprecated 1.31.0 -- we don't needs ads indexed by id, since we have all ads.
42
  */
43
+ protected $adsbyid = [];
44
 
45
  /**
46
  * All filters available in the current ad list table
47
  *
48
  * @var array
49
  */
50
+ protected $all_filters = [];
51
 
52
  /**
53
  * All ad options for the ad list table
54
  *
55
  * @var array
56
  */
57
+ protected $all_ads_options = [];
58
 
59
  /**
60
  * Constructs the unique instance.
61
  */
62
  private function __construct() {
63
  if ( is_admin() && ! wp_doing_ajax() ) {
64
+ add_filter( 'posts_results', [ $this, 'post_results' ], 10, 2 );
65
+ add_filter( 'post_limits', [ $this, 'limit_filter' ], 10, 2 );
66
  }
67
 
68
+ add_filter( 'views_edit-' . Advanced_Ads::POST_TYPE_SLUG, [ $this, 'add_expired_view' ] );
69
+ add_filter( 'views_edit-' . Advanced_Ads::POST_TYPE_SLUG, [ $this, 'add_expiring_view' ] );
70
+ add_action( 'restrict_manage_posts', [ $this, 'send_addate_in_filter' ] );
71
 
72
+ add_action( 'manage_posts_extra_tablenav', [ $this, 'ad_views' ] );
73
+ add_action( 'admin_enqueue_scripts', [ $this, 'ad_list_scripts' ], 11 );
74
  }
75
 
76
  /**
100
  * @return null
101
  */
102
  private function collect_filters( $posts ) {
103
+ $all_sizes = [];
104
+ $all_types = [];
105
+ $all_dates = [];
106
+ $all_groups = [];
107
+
108
+ $all_filters = [
109
+ 'all_sizes' => [],
110
+ 'all_types' => [],
111
+ 'all_dates' => [],
112
+ 'all_groups' => [],
113
+ ];
114
 
115
  // can not filter correctly with "trashed" posts. Do not display any filtering option in this case.
116
  if ( isset( $_REQUEST['post_status'] ) && $_REQUEST['post_status'] === 'trash' ) {
189
  $this->adsbyid[ $post->ID ] = $post;
190
  $this->all_ads_options[ $post->ID ] = get_post_meta( $post->ID, 'advanced_ads_ad_options', true );
191
  if ( empty( $this->all_ads_options[ $post->ID ] ) ) {
192
+ $this->all_ads_options[ $post->ID ] = [];
193
  }
194
 
195
  // convert all expiration dates.
209
  global $wpdb;
210
 
211
  $_groups = Advanced_Ads::get_ad_groups();
212
+ $groups = [];
213
 
214
  /**
215
  * It looks like there might be a third-party conflict we haven’t been able to reproduce that causes the group
219
  if ( empty( $g->term_id ) ) {
220
  continue;
221
  }
222
+ $groups[ $g->term_id ] = [
223
  'name' => $g->name,
224
  'slug' => $g->slug,
225
+ ];
226
  }
227
 
228
  $group_ids = array_keys( $groups );
229
  $group_ids_str = implode( ',', $group_ids );
230
+ $term_relations = [];
231
 
232
  /**
233
  * We need to use %1$s below, because when using %s the $wpdb->prepare function adds quotation marks around the value,
317
  if ( (int) $the_query->query_vars['s'] !== 0 ) {
318
  global $wpdb;
319
  $single_ad = ( new Advanced_Ads_Model( $wpdb ) )->get_ads(
320
+ [
321
  'p' => (int) $the_query->query_vars['s'],
322
+ 'post_status' => [ 'any' ],
323
+ ]
324
  );
325
 
326
  if ( ! empty( $single_ad ) ) {
327
  // Head to the ad edit page if one and only one ad found.
328
  if ( empty( $posts ) ) {
329
+ wp_safe_redirect( add_query_arg( [
330
  'post' => $single_ad[0]->ID,
331
  'action' => 'edit',
332
+ ], admin_url( 'post.php' ) ) );
333
  die;
334
  }
335
 
382
  /**
383
  * Filter post status
384
  */
385
+ if ( isset( $request['post_status'] ) && '' !== $request['post_status'] && ! in_array( $request['post_status'], [ 'all', 'trash' ], true ) ) {
386
+ $new_posts = [];
387
  foreach ( $this->all_ads as $post ) {
388
  if ( $request['post_status'] === $post->post_status ) {
389
  $new_posts[] = $post;
399
  */
400
  if ( isset( $request['author'] ) && '' !== $request['author'] ) {
401
  $author = absint( $request['author'] );
402
+ $new_posts = [];
403
  $the_list = $using_original ? $this->all_ads : $posts;
404
  foreach ( $the_list as $post ) {
405
  if ( absint( $post->post_author ) === $author ) {
415
  * Filter groups
416
  */
417
  if ( isset( $request['adgroup'] ) && '' !== $request['adgroup'] ) {
418
+ $new_posts = [];
419
  $the_list = $using_original ? $this->all_ads : $posts;
420
  foreach ( $the_list as $post ) {
421
  if ( isset( $this->ads_in_groups[ absint( $request['adgroup'] ) ] ) && in_array( $post->ID, $this->ads_in_groups[ absint( $request['adgroup'] ) ], true ) ) {
442
  $q = $wpdb->prepare( $q, $term, Advanced_Ads::AD_GROUP_TAXONOMY );
443
 
444
  $object_ids = $wpdb->get_results( $q, 'ARRAY_A' );
445
+ $ads_in_taxo = [];
446
 
447
  foreach ( $object_ids as $object ) {
448
  $ads_in_taxo[] = absint( $object['object_id'] );
449
  }
450
 
451
+ $new_posts = [];
452
  $the_list = $using_original ? $this->all_ads : $posts;
453
  foreach ( $the_list as $post ) {
454
  if ( in_array( $post->ID, $ads_in_taxo, true ) ) {
464
  * Filter ad type
465
  */
466
  if ( isset( $request['adtype'] ) && '' !== $request['adtype'] ) {
467
+ $new_posts = [];
468
  $the_list = $using_original ? $this->all_ads : $posts;
469
  foreach ( $the_list as $post ) {
470
  $option = $this->all_ads_options[ $post->ID ];
481
  * Filter ad size
482
  */
483
  if ( isset( $request['adsize'] ) && '' !== $request['adsize'] ) {
484
+ $new_posts = [];
485
  $the_list = $using_original ? $this->all_ads : $posts;
486
  foreach ( $the_list as $post ) {
487
  $option = $this->all_ads_options[ $post->ID ];
512
 
513
  if ( isset( $request['addate'] ) ) {
514
  $filter_value = urldecode( $request['addate'] );
515
+ if ( in_array( $filter_value, [ 'advads-filter-expired', 'advads-filter-expiring' ], true ) ) {
516
  $posts = $this->filter_expired_ads( $filter_value, $using_original ? $this->all_ads : $posts );
517
  }
518
  }
551
  }
552
  $views[ Advanced_Ads_Ad_Expiration::POST_STATUS ] = sprintf(
553
  '<a href="%s" %s>%s <span class="count">(%d)</span></a>',
554
+ add_query_arg( [
555
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
556
  'addate' => 'advads-filter-expired',
557
  'orderby' => 'expiry_date',
558
  'order' => 'DESC',
559
+ ], 'edit.php' ),
560
  isset( $_REQUEST['addate'] ) && $_REQUEST['addate'] === 'advads-filter-expired' ? 'class="current" aria-current="page"' : '',
561
  esc_attr_x( 'Expired', 'Post list header for expired ads.', 'advanced-ads' ),
562
  $count
571
  * @return int
572
  */
573
  private function count_expired_ads() {
574
+ return ( new WP_Query( [
575
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
576
  'post_status' => Advanced_Ads_Ad_Expiration::POST_STATUS,
577
+ ] ) )->found_posts;
578
  }
579
 
580
  /**
591
  }
592
  $views['expiring'] = sprintf(
593
  '<a href="%s" %s>%s <span class="count">(%d)</span></a>',
594
+ add_query_arg( [
595
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
596
  'addate' => 'advads-filter-expiring',
597
  'orderby' => 'expiry_date',
598
  'order' => 'ASC',
599
+ ], 'edit.php' ),
600
  isset( $_REQUEST['addate'] ) && $_REQUEST['addate'] === 'advads-filter-expiring' ? 'class="current" aria-current="page"' : '',
601
  esc_attr_x( 'Expiring', 'Post list header for ads expiring in the future.', 'advanced-ads' ),
602
  $count
611
  * @return int
612
  */
613
  private function count_expiring_ads() {
614
+ return ( new WP_Query( [
615
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
616
  'post_status' => 'any',
617
+ 'meta_query' => [
618
+ [
619
  'key' => Advanced_Ads_Ad_Expiration::POST_META,
620
  'value' => current_time( 'mysql', true ),
621
  'compare' => '>=',
622
  'type' => 'DATETIME',
623
+ ],
624
+ ],
625
+ ] ) )->found_posts;
626
  }
627
 
628
  /**
633
  private function views_order() {
634
  static $views_order;
635
  if ( $views_order === null ) {
636
+ $views_order = array_flip( [ 'all', 'mine', 'publish', 'future', 'expiring', Advanced_Ads_Ad_Expiration::POST_STATUS, 'draft', 'pending', 'trash' ] );
637
  }
638
 
639
  return $views_order;
676
  }
677
 
678
  // unregister the hook to prevent the navigation to appear again below the footer
679
+ remove_action( 'manage_posts_extra_tablenav', [ $this, 'ad_views' ] );
680
 
681
  $views = $wp_list_table->get_views();
682
  /**
694
  }
695
 
696
  $wp_list_table->screen->render_screen_reader_content( 'heading_views' );
697
+ $views_new = [];
698
 
699
+ $is_all = count( array_diff_key( $_GET, [
700
  'post_type' => Advanced_Ads::POST_TYPE_SLUG,
701
  'orderby' => '',
702
  'order' => '',
703
  'paged' => '',
704
  'mode' => '',
705
+ ] ) ) === 0;
706
 
707
  foreach ( $views as $class => $view ) {
708
+ $view = str_replace( [ ')', '(' ], [ '', '' ], $view );
709
  $class .= strpos( $view, 'current' ) ? ' advads-button-primary' : ' advads-button-secondary';
710
  $views_new[ $class ] = $view;
711
  }
admin/includes/class-menu.php CHANGED
@@ -24,8 +24,8 @@ class Advanced_Ads_Admin_Menu {
24
  */
25
  private function __construct() {
26
  // add menu items.
27
- add_action( 'admin_menu', array( $this, 'add_plugin_admin_menu' ) );
28
- add_action( 'admin_head', array( $this, 'highlight_menu_item' ) );
29
 
30
  $this->plugin_slug = Advanced_Ads::get_instance()->get_plugin_slug();
31
  $this->post_type = constant( 'Advanced_Ads::POST_TYPE_SLUG' );
@@ -53,7 +53,7 @@ class Advanced_Ads_Admin_Menu {
53
  public function add_plugin_admin_menu() {
54
 
55
  // get number of ads including those in trash.
56
- $has_ads = Advanced_Ads::get_number_of_ads( array( 'any', 'trash' ) );
57
 
58
  // get number of Ad Health notices.
59
  $notices = Advanced_Ads_Ad_Health_Notices::get_number_of_notices();
@@ -67,7 +67,7 @@ class Advanced_Ads_Admin_Menu {
67
  'Advanced Ads',
68
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ),
69
  $this->plugin_slug,
70
- array( $this, 'display_overview_page' ),
71
  Advanced_Ads_Plugin::get_icon_svg(),
72
  '58.74'
73
  );
@@ -100,7 +100,7 @@ class Advanced_Ads_Admin_Menu {
100
  'Advanced Ads',
101
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ),
102
  $this->plugin_slug,
103
- array( $this, 'display_overview_page' ),
104
  Advanced_Ads_Plugin::get_icon_svg(),
105
  '58.74'
106
  );
@@ -111,7 +111,7 @@ class Advanced_Ads_Admin_Menu {
111
  __( 'Dashboard', 'advanced-ads' ),
112
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ),
113
  $this->plugin_slug,
114
- array( $this, 'display_overview_page' )
115
  );
116
  }
117
 
@@ -132,7 +132,7 @@ class Advanced_Ads_Admin_Menu {
132
  __( 'Groups & Rotation', 'advanced-ads' ),
133
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ),
134
  $this->plugin_slug . '-groups',
135
- array( $this, 'ad_group_admin_page' )
136
  );
137
 
138
  // add placements page.
@@ -142,7 +142,7 @@ class Advanced_Ads_Admin_Menu {
142
  __( 'Placements', 'advanced-ads' ),
143
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_placements' ),
144
  $this->plugin_slug . '-placements',
145
- array( $this, 'display_placements_page' )
146
  );
147
  // add settings page.
148
  Advanced_Ads_Admin::get_instance()->plugin_screen_hook_suffix = add_submenu_page(
@@ -151,7 +151,7 @@ class Advanced_Ads_Admin_Menu {
151
  __( 'Settings', 'advanced-ads' ),
152
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ),
153
  $this->plugin_slug . '-settings',
154
- array( $this, 'display_plugin_settings_page' )
155
  );
156
 
157
  /**
@@ -264,12 +264,13 @@ class Advanced_Ads_Admin_Menu {
264
  printf(
265
  " data-order='%s'",
266
  wp_json_encode(
267
- array(
268
  'order' => isset( $placement_types[ $placement['type'] ]['order'] ) ? (int) $placement_types[ $placement['type'] ]['order'] : 100,
269
  'name' => esc_html( $placement['name'] ),
 
270
  'words-between-repeats' => ! empty( $placement['options']['words_between_repeats'] ) ? 1 : 0,
271
  'post-content-index' => isset( $placement['options']['index'] ) ? (int) $placement['options']['index'] : 0,
272
- )
273
  )
274
  );
275
  }
@@ -294,7 +295,6 @@ class Advanced_Ads_Admin_Menu {
294
  $taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
295
  $post_type = Advanced_Ads::POST_TYPE_SLUG;
296
  $tax = get_taxonomy( $taxonomy );
297
-
298
  $action = Advanced_Ads_Admin::get_instance()->current_action();
299
 
300
  // handle new and updated groups.
@@ -363,7 +363,26 @@ class Advanced_Ads_Admin_Menu {
363
  $screen->taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
364
  $wp_list_table = _get_list_table( 'WP_Terms_List_Table' );
365
  $wp_list_table->prepare_items();
366
- $is_search = ! empty( $_GET['s'] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
367
  // load template.
368
  include ADVADS_BASE_PATH . 'admin/views/ad-group.php';
369
  }
@@ -380,7 +399,7 @@ class Advanced_Ads_Admin_Menu {
380
  $default = isset( $admin_settings['placement-orderby'] ) ? $admin_settings['placement-orderby'] : 'type';
381
  $current = isset( $_GET['orderby'] ) ? $_GET['orderby'] : $default; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
382
 
383
- if ( ! in_array( $current, array( 'name', 'type' ) ) ) {
384
  $current = 'type';
385
  }
386
 
@@ -401,11 +420,11 @@ class Advanced_Ads_Admin_Menu {
401
 
402
  if ( 'posts' === get_option( 'show_on_front' ) ) {
403
  $recent_posts = wp_get_recent_posts(
404
- array(
405
  'numberposts' => 1,
406
  'post_type' => 'post',
407
  'post_status' => 'publish',
408
- ),
409
  'OBJECT'
410
  );
411
 
24
  */
25
  private function __construct() {
26
  // add menu items.
27
+ add_action( 'admin_menu', [ $this, 'add_plugin_admin_menu' ] );
28
+ add_action( 'admin_head', [ $this, 'highlight_menu_item' ] );
29
 
30
  $this->plugin_slug = Advanced_Ads::get_instance()->get_plugin_slug();
31
  $this->post_type = constant( 'Advanced_Ads::POST_TYPE_SLUG' );
53
  public function add_plugin_admin_menu() {
54
 
55
  // get number of ads including those in trash.
56
+ $has_ads = Advanced_Ads::get_number_of_ads( [ 'any', 'trash' ] );
57
 
58
  // get number of Ad Health notices.
59
  $notices = Advanced_Ads_Ad_Health_Notices::get_number_of_notices();
67
  'Advanced Ads',
68
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ),
69
  $this->plugin_slug,
70
+ [ $this, 'display_overview_page' ],
71
  Advanced_Ads_Plugin::get_icon_svg(),
72
  '58.74'
73
  );
100
  'Advanced Ads',
101
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ),
102
  $this->plugin_slug,
103
+ [ $this, 'display_overview_page' ],
104
  Advanced_Ads_Plugin::get_icon_svg(),
105
  '58.74'
106
  );
111
  __( 'Dashboard', 'advanced-ads' ),
112
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ),
113
  $this->plugin_slug,
114
+ [ $this, 'display_overview_page' ]
115
  );
116
  }
117
 
132
  __( 'Groups & Rotation', 'advanced-ads' ),
133
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ),
134
  $this->plugin_slug . '-groups',
135
+ [ $this, 'ad_group_admin_page' ]
136
  );
137
 
138
  // add placements page.
142
  __( 'Placements', 'advanced-ads' ),
143
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_placements' ),
144
  $this->plugin_slug . '-placements',
145
+ [ $this, 'display_placements_page' ]
146
  );
147
  // add settings page.
148
  Advanced_Ads_Admin::get_instance()->plugin_screen_hook_suffix = add_submenu_page(
151
  __( 'Settings', 'advanced-ads' ),
152
  Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options' ),
153
  $this->plugin_slug . '-settings',
154
+ [ $this, 'display_plugin_settings_page' ]
155
  );
156
 
157
  /**
264
  printf(
265
  " data-order='%s'",
266
  wp_json_encode(
267
+ [
268
  'order' => isset( $placement_types[ $placement['type'] ]['order'] ) ? (int) $placement_types[ $placement['type'] ]['order'] : 100,
269
  'name' => esc_html( $placement['name'] ),
270
+ 'type' => esc_html( $placement['type'] ),
271
  'words-between-repeats' => ! empty( $placement['options']['words_between_repeats'] ) ? 1 : 0,
272
  'post-content-index' => isset( $placement['options']['index'] ) ? (int) $placement['options']['index'] : 0,
273
+ ]
274
  )
275
  );
276
  }
295
  $taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
296
  $post_type = Advanced_Ads::POST_TYPE_SLUG;
297
  $tax = get_taxonomy( $taxonomy );
 
298
  $action = Advanced_Ads_Admin::get_instance()->current_action();
299
 
300
  // handle new and updated groups.
363
  $screen->taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
364
  $wp_list_table = _get_list_table( 'WP_Terms_List_Table' );
365
  $wp_list_table->prepare_items();
366
+ // load the ad group list after groups might have been deleted
367
+ $ad_groups_list = new Advanced_Ads_Groups_List();
368
+ $group_types = $ad_groups_list->get_ad_group_types();
369
+ $is_search = ! empty( $_GET['s'] );
370
+ $group_types_premium = [];
371
+ if ( ! defined( 'AAP_VERSION' ) ) {
372
+ $group_types_premium['grid'] = [
373
+ 'title' => __( 'Grid', 'advanced-ads' ),
374
+ 'description' => '',
375
+ 'image' => ADVADS_BASE_URL . 'admin/assets/img/groups/grid.svg',
376
+ ];
377
+ }
378
+ // Slider
379
+ if ( ! defined( 'AAS_VERSION' ) ) {
380
+ $group_types_premium['slider'] = [
381
+ 'title' => __( 'Ad Slider', 'advanced-ads' ),
382
+ 'description' => '',
383
+ 'image' => ADVADS_BASE_URL . 'admin/assets/img/groups/slider.svg',
384
+ ];
385
+ }
386
  // load template.
387
  include ADVADS_BASE_PATH . 'admin/views/ad-group.php';
388
  }
399
  $default = isset( $admin_settings['placement-orderby'] ) ? $admin_settings['placement-orderby'] : 'type';
400
  $current = isset( $_GET['orderby'] ) ? $_GET['orderby'] : $default; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
401
 
402
+ if ( ! in_array( $current, [ 'name', 'type' ] ) ) {
403
  $current = 'type';
404
  }
405
 
420
 
421
  if ( 'posts' === get_option( 'show_on_front' ) ) {
422
  $recent_posts = wp_get_recent_posts(
423
+ [
424
  'numberposts' => 1,
425
  'post_type' => 'post',
426
  'post_status' => 'publish',
427
+ ],
428
  'OBJECT'
429
  );
430
 
admin/includes/class-meta-box.php CHANGED
@@ -17,20 +17,20 @@ class Advanced_Ads_Admin_Meta_Boxes {
17
  *
18
  * @var array $meta_box_ids
19
  */
20
- protected $meta_box_ids = array();
21
 
22
  /**
23
  * Advanced_Ads_Admin_Meta_Boxes constructor.
24
  */
25
  private function __construct() {
26
- add_action( 'add_meta_boxes_' . Advanced_Ads::POST_TYPE_SLUG, array( $this, 'add_meta_boxes' ) );
27
  // add meta box for post types edit pages.
28
- add_action( 'add_meta_boxes', array( $this, 'add_post_meta_box' ) );
29
- add_action( 'save_post', array( $this, 'save_post_meta_box' ) );
30
  // register dashboard widget.
31
- add_action( 'wp_dashboard_setup', array( $this, 'add_dashboard_widget' ) );
32
  // fixes compatibility issue with WP QUADS PRO.
33
- add_action( 'quads_meta_box_post_types', array( $this, 'fix_wpquadspro_issue' ), 11 );
34
  }
35
 
36
  /**
@@ -59,7 +59,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
59
  add_meta_box(
60
  'ad-main-box',
61
  __( 'Ad Type', 'advanced-ads' ),
62
- array( $this, 'markup_meta_boxes' ),
63
  $post_type,
64
  'normal',
65
  'high'
@@ -72,7 +72,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
72
  add_meta_box(
73
  'advads-gadsense-box',
74
  __( 'AdSense Earnings', 'advanced-ads' ),
75
- array( $this, 'markup_meta_boxes' ),
76
  $post_type,
77
  'normal',
78
  'high'
@@ -80,14 +80,14 @@ class Advanced_Ads_Admin_Meta_Boxes {
80
  }
81
 
82
  // use dynamic filter from to add close class to ad type meta box after saved first time.
83
- add_filter( 'postbox_classes_advanced_ads_ad-main-box', array( $this, 'close_ad_type_metabox' ) );
84
 
85
  // show the Usage box for saved ads
86
  if ( $post->filter === 'edit' ) {
87
  add_meta_box(
88
  'ad-usage-box',
89
  __( 'Usage', 'advanced-ads' ),
90
- array( $this, 'markup_meta_boxes' ),
91
  $post_type,
92
  'normal',
93
  'high'
@@ -96,7 +96,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
96
  add_meta_box(
97
  'ad-parameters-box',
98
  __( 'Ad Parameters', 'advanced-ads' ),
99
- array( $this, 'markup_meta_boxes' ),
100
  $post_type,
101
  'normal',
102
  'high'
@@ -104,7 +104,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
104
  add_meta_box(
105
  'ad-output-box',
106
  __( 'Layout / Output', 'advanced-ads' ),
107
- array( $this, 'markup_meta_boxes' ),
108
  $post_type,
109
  'normal',
110
  'high'
@@ -112,7 +112,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
112
  add_meta_box(
113
  'ad-display-box',
114
  __( 'Display Conditions', 'advanced-ads' ),
115
- array( $this, 'markup_meta_boxes' ),
116
  $post_type,
117
  'normal',
118
  'high'
@@ -120,7 +120,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
120
  add_meta_box(
121
  'ad-visitor-box',
122
  __( 'Visitor Conditions', 'advanced-ads' ),
123
- array( $this, 'markup_meta_boxes' ),
124
  $post_type,
125
  'normal',
126
  'high'
@@ -129,7 +129,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
129
  add_meta_box(
130
  'advads-pro-pitch',
131
  __( 'Increase your ad revenue', 'advanced-ads' ),
132
- array( $this, 'markup_meta_boxes' ),
133
  $post_type,
134
  'side',
135
  'low'
@@ -139,7 +139,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
139
  add_meta_box(
140
  'advads-tracking-pitch',
141
  __( 'Statistics', 'advanced-ads' ),
142
- array( $this, 'markup_meta_boxes' ),
143
  $post_type,
144
  'normal',
145
  'low'
@@ -147,7 +147,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
147
  }
148
 
149
  // register meta box ids.
150
- $this->meta_box_ids = array(
151
  'ad-main-box',
152
  'advads-gadsense-box',
153
  'ad-parameters-box',
@@ -158,33 +158,33 @@ class Advanced_Ads_Admin_Meta_Boxes {
158
  'advads-tracking-pitch',
159
  'revisionsdiv', // revisions – only when activated.
160
  'advanced_ads_groupsdiv', // automatically added by ad groups taxonomy.
161
- );
162
 
163
  // force AA meta boxes to never be completely hidden by screen options.
164
- add_filter( 'hidden_meta_boxes', array( $this, 'unhide_meta_boxes' ), 10, 2 );
165
  // hide the checkboxes for "unhideable" meta boxes within screen options via CSS.
166
- add_action( 'admin_head', array( $this, 'unhide_meta_boxes_style' ) );
167
 
168
  $whitelist = apply_filters(
169
  'advanced-ads-ad-edit-allowed-metaboxes',
170
  array_merge(
171
  $this->meta_box_ids,
172
- array( // meta boxes in this array can be hidden using Screen Option
173
  'submitdiv',
174
  'slugdiv',
175
  'ad-usage-box',
176
  'authordiv',
177
  'tracking-ads-box',
178
  'ad-layer-ads-box', // deprecated.
179
- )
180
  )
181
  );
182
 
183
  global $wp_meta_boxes;
184
  // remove non-white-listed meta boxes.
185
- foreach ( array( 'normal', 'advanced', 'side' ) as $context ) {
186
  if ( isset( $wp_meta_boxes[ $post_type ][ $context ] ) ) {
187
- foreach ( array( 'high', 'sorted', 'core', 'default', 'low' ) as $priority ) {
188
  if ( isset( $wp_meta_boxes[ $post_type ][ $context ][ $priority ] ) ) {
189
  foreach ( (array) $wp_meta_boxes[ $post_type ][ $context ][ $priority ] as $id => $box ) {
190
  if ( ! in_array( $id, $whitelist ) ) {
@@ -273,13 +273,13 @@ class Advanced_Ads_Admin_Meta_Boxes {
273
  <?php
274
  echo wp_kses(
275
  $hndlelinks,
276
- array(
277
- 'a' => array(
278
- 'target' => array(),
279
- 'href' => array(),
280
- 'class' => array(),
281
- ),
282
- )
283
  );
284
  ?>
285
  </span>
@@ -289,46 +289,46 @@ class Advanced_Ads_Admin_Meta_Boxes {
289
  if ( isset( $videomarkup ) ) {
290
  echo '<div class="advads-video-link-container" data-videolink=\'' . wp_kses(
291
  $videomarkup,
292
- array(
293
- 'iframe' => array(
294
- 'width' => array(),
295
- 'height' => array(),
296
- 'src' => array(),
297
- 'frameborder' => array(),
298
- 'allowfullscreen' => array(),
299
- ),
300
- )
301
  ) . '\'></div>';
302
  }
303
  /**
304
  * List general notices
305
  * elements in $warnings contain [text] and [class] attributes.
306
  */
307
- $warnings = array();
308
  // show warning if ad contains https in parameters box.
309
  $https_message = Advanced_Ads_Ad_Debug::is_https_and_http( $ad );
310
  if ( 'ad-parameters-box' === $box['id'] && $https_message ) {
311
- $warnings[] = array(
312
  'text' => $https_message,
313
  'class' => 'advads-ad-notice-https-missing advads-notice-inline advads-error',
314
- );
315
  }
316
 
317
  if ( 'ad-parameters-box' === $box['id'] ) {
318
- $warnings[] = array(
319
  'text' => Advanced_Ads_AdSense_Admin::get_auto_ads_messages()[ Advanced_Ads_AdSense_Data::get_instance()->is_page_level_enabled() ? 'enabled' : 'disabled' ],
320
  'class' => 'advads-auto-ad-in-ad-content hidden advads-notice-inline advads-error',
321
- );
322
  }
323
 
324
  // Let users know that they could use the Google AdSense ad type when they enter an AdSense code.
325
- if ( 'ad-parameters-box' === $box['id'] && Advanced_Ads_Ad_Type_Adsense::content_is_adsense( $ad->content ) && in_array( $ad->type, array( 'plain', 'content' ), true ) ) {
326
  if (
327
  false === strpos( $ad->content, 'enable_page_level_ads' )
328
  && ! preg_match( '/script[^>]+data-ad-client=/', $ad->content )
329
  ) {
330
  $adsense_auto_ads = Advanced_Ads_AdSense_Data::get_instance()->is_page_level_enabled();
331
- $warnings[] = array(
332
  'class' => 'advads-adsense-found-in-content advads-notice-inline advads-error',
333
  'text' => sprintf(
334
  // translators: %1$s opening button tag, %2$s closing button tag.
@@ -336,7 +336,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
336
  '<button class="button-secondary" id="switch-to-adsense-type">',
337
  '</button>'
338
  ),
339
- );
340
  }
341
  }
342
 
@@ -393,7 +393,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
393
  $styles[] = sprintf( 'label[for="%s-hide"]', $box_id );
394
 
395
  return $styles;
396
- }, array() ) ) );
397
  }
398
 
399
  /**
@@ -409,10 +409,10 @@ class Advanced_Ads_Admin_Meta_Boxes {
409
 
410
  // get public post types.
411
  $public_post_types = get_post_types(
412
- array(
413
  'public' => true,
414
  'publicly_queryable' => true,
415
- ),
416
  'names',
417
  'or'
418
  );
@@ -422,7 +422,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
422
  add_meta_box(
423
  'advads-ad-settings',
424
  __( 'Ad Settings', 'advanced-ads' ),
425
- array( $this, 'render_post_meta_box' ),
426
  $post_type,
427
  'side',
428
  'low'
@@ -500,14 +500,14 @@ class Advanced_Ads_Admin_Meta_Boxes {
500
  * @param array $classes class attributes.
501
  * @return array $classes
502
  */
503
- public function close_ad_type_metabox( $classes = array() ) {
504
  global $post;
505
  if ( isset( $post->ID ) && 'publish' === $post->post_status ) {
506
  if ( ! in_array( 'closed', $classes, true ) ) {
507
  $classes[] = 'closed';
508
  }
509
  } else {
510
- $classes = array();
511
  }
512
  return $classes;
513
  }
@@ -520,7 +520,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
520
  if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ) ) ) {
521
  return;
522
  }
523
- add_meta_box( 'advads_dashboard_widget', __( 'Dashboard', 'advanced-ads' ), array( $this, 'dashboard_widget_function' ), 'dashboard', 'side', 'high' );
524
  }
525
 
526
  /**
@@ -536,7 +536,7 @@ class Advanced_Ads_Admin_Meta_Boxes {
536
  echo '<p>';
537
  printf(
538
  // translators: %1$d is the number of ads, %2$s and %3$s are URLs.
539
- wp_kses( __( '%1$d ads – <a href="%2$s">manage</a> - <a href="%3$s">new</a>', 'advanced-ads' ), array( 'a' => array( 'href' => array() ) ) ),
540
  absint( $ads_count ),
541
  'edit.php?post_type=' . esc_attr( Advanced_Ads::POST_TYPE_SLUG ),
542
  'post-new.php?post_type=' . esc_attr( Advanced_Ads::POST_TYPE_SLUG )
@@ -615,8 +615,8 @@ class Advanced_Ads_Admin_Meta_Boxes {
615
 
616
  $cache_key = 'dash_' . md5( 'advads_dashboard_widget' );
617
 
618
- $feeds = array(
619
- array(
620
  'link' => ADVADS_URL,
621
  'url' => ADVADS_URL . 'feed/',
622
  'title' => sprintf(
@@ -628,8 +628,8 @@ class Advanced_Ads_Admin_Meta_Boxes {
628
  'show_summary' => 1,
629
  'show_author' => 0,
630
  'show_date' => 0,
631
- ),
632
- );
633
 
634
  // create output and also cache it.
635
 
17
  *
18
  * @var array $meta_box_ids
19
  */
20
+ protected $meta_box_ids = [];
21
 
22
  /**
23
  * Advanced_Ads_Admin_Meta_Boxes constructor.
24
  */
25
  private function __construct() {
26
+ add_action( 'add_meta_boxes_' . Advanced_Ads::POST_TYPE_SLUG, [ $this, 'add_meta_boxes' ] );
27
  // add meta box for post types edit pages.
28
+ add_action( 'add_meta_boxes', [ $this, 'add_post_meta_box' ] );
29
+ add_action( 'save_post', [ $this, 'save_post_meta_box' ] );
30
  // register dashboard widget.
31
+ add_action( 'wp_dashboard_setup', [ $this, 'add_dashboard_widget' ] );
32
  // fixes compatibility issue with WP QUADS PRO.
33
+ add_action( 'quads_meta_box_post_types', [ $this, 'fix_wpquadspro_issue' ], 11 );
34
  }
35
 
36
  /**
59
  add_meta_box(
60
  'ad-main-box',
61
  __( 'Ad Type', 'advanced-ads' ),
62
+ [ $this, 'markup_meta_boxes' ],
63
  $post_type,
64
  'normal',
65
  'high'
72
  add_meta_box(
73
  'advads-gadsense-box',
74
  __( 'AdSense Earnings', 'advanced-ads' ),
75
+ [ $this, 'markup_meta_boxes' ],
76
  $post_type,
77
  'normal',
78
  'high'
80
  }
81
 
82
  // use dynamic filter from to add close class to ad type meta box after saved first time.
83
+ add_filter( 'postbox_classes_advanced_ads_ad-main-box', [ $this, 'close_ad_type_metabox' ] );
84
 
85
  // show the Usage box for saved ads
86
  if ( $post->filter === 'edit' ) {
87
  add_meta_box(
88
  'ad-usage-box',
89
  __( 'Usage', 'advanced-ads' ),
90
+ [ $this, 'markup_meta_boxes' ],
91
  $post_type,
92
  'normal',
93
  'high'
96
  add_meta_box(
97
  'ad-parameters-box',
98
  __( 'Ad Parameters', 'advanced-ads' ),
99
+ [ $this, 'markup_meta_boxes' ],
100
  $post_type,
101
  'normal',
102
  'high'
104
  add_meta_box(
105
  'ad-output-box',
106
  __( 'Layout / Output', 'advanced-ads' ),
107
+ [ $this, 'markup_meta_boxes' ],
108
  $post_type,
109
  'normal',
110
  'high'
112
  add_meta_box(
113
  'ad-display-box',
114
  __( 'Display Conditions', 'advanced-ads' ),
115
+ [ $this, 'markup_meta_boxes' ],
116
  $post_type,
117
  'normal',
118
  'high'
120
  add_meta_box(
121
  'ad-visitor-box',
122
  __( 'Visitor Conditions', 'advanced-ads' ),
123
+ [ $this, 'markup_meta_boxes' ],
124
  $post_type,
125
  'normal',
126
  'high'
129
  add_meta_box(
130
  'advads-pro-pitch',
131
  __( 'Increase your ad revenue', 'advanced-ads' ),
132
+ [ $this, 'markup_meta_boxes' ],
133
  $post_type,
134
  'side',
135
  'low'
139
  add_meta_box(
140
  'advads-tracking-pitch',
141
  __( 'Statistics', 'advanced-ads' ),
142
+ [ $this, 'markup_meta_boxes' ],
143
  $post_type,
144
  'normal',
145
  'low'
147
  }
148
 
149
  // register meta box ids.
150
+ $this->meta_box_ids = [
151
  'ad-main-box',
152
  'advads-gadsense-box',
153
  'ad-parameters-box',
158
  'advads-tracking-pitch',
159
  'revisionsdiv', // revisions – only when activated.
160
  'advanced_ads_groupsdiv', // automatically added by ad groups taxonomy.
161
+ ];
162
 
163
  // force AA meta boxes to never be completely hidden by screen options.
164
+ add_filter( 'hidden_meta_boxes', [ $this, 'unhide_meta_boxes' ], 10, 2 );
165
  // hide the checkboxes for "unhideable" meta boxes within screen options via CSS.
166
+ add_action( 'admin_head', [ $this, 'unhide_meta_boxes_style' ] );
167
 
168
  $whitelist = apply_filters(
169
  'advanced-ads-ad-edit-allowed-metaboxes',
170
  array_merge(
171
  $this->meta_box_ids,
172
+ [ // meta boxes in this array can be hidden using Screen Option
173
  'submitdiv',
174
  'slugdiv',
175
  'ad-usage-box',
176
  'authordiv',
177
  'tracking-ads-box',
178
  'ad-layer-ads-box', // deprecated.
179
+ ]
180
  )
181
  );
182
 
183
  global $wp_meta_boxes;
184
  // remove non-white-listed meta boxes.
185
+ foreach ( [ 'normal', 'advanced', 'side' ] as $context ) {
186
  if ( isset( $wp_meta_boxes[ $post_type ][ $context ] ) ) {
187
+ foreach ( [ 'high', 'sorted', 'core', 'default', 'low' ] as $priority ) {
188
  if ( isset( $wp_meta_boxes[ $post_type ][ $context ][ $priority ] ) ) {
189
  foreach ( (array) $wp_meta_boxes[ $post_type ][ $context ][ $priority ] as $id => $box ) {
190
  if ( ! in_array( $id, $whitelist ) ) {
273
  <?php
274
  echo wp_kses(
275
  $hndlelinks,
276
+ [
277
+ 'a' => [
278
+ 'target' => [],
279
+ 'href' => [],
280
+ 'class' => [],
281
+ ],
282
+ ]
283
  );
284
  ?>
285
  </span>
289
  if ( isset( $videomarkup ) ) {
290
  echo '<div class="advads-video-link-container" data-videolink=\'' . wp_kses(
291
  $videomarkup,
292
+ [
293
+ 'iframe' => [
294
+ 'width' => [],
295
+ 'height' => [],
296
+ 'src' => [],
297
+ 'frameborder' => [],
298
+ 'allowfullscreen' => [],
299
+ ],
300
+ ]
301
  ) . '\'></div>';
302
  }
303
  /**
304
  * List general notices
305
  * elements in $warnings contain [text] and [class] attributes.
306
  */
307
+ $warnings = [];
308
  // show warning if ad contains https in parameters box.
309
  $https_message = Advanced_Ads_Ad_Debug::is_https_and_http( $ad );
310
  if ( 'ad-parameters-box' === $box['id'] && $https_message ) {
311
+ $warnings[] = [
312
  'text' => $https_message,
313
  'class' => 'advads-ad-notice-https-missing advads-notice-inline advads-error',
314
+ ];
315
  }
316
 
317
  if ( 'ad-parameters-box' === $box['id'] ) {
318
+ $warnings[] = [
319
  'text' => Advanced_Ads_AdSense_Admin::get_auto_ads_messages()[ Advanced_Ads_AdSense_Data::get_instance()->is_page_level_enabled() ? 'enabled' : 'disabled' ],
320
  'class' => 'advads-auto-ad-in-ad-content hidden advads-notice-inline advads-error',
321
+ ];
322
  }
323
 
324
  // Let users know that they could use the Google AdSense ad type when they enter an AdSense code.
325
+ if ( 'ad-parameters-box' === $box['id'] && Advanced_Ads_Ad_Type_Adsense::content_is_adsense( $ad->content ) && in_array( $ad->type, [ 'plain', 'content' ], true ) ) {
326
  if (
327
  false === strpos( $ad->content, 'enable_page_level_ads' )
328
  && ! preg_match( '/script[^>]+data-ad-client=/', $ad->content )
329
  ) {
330
  $adsense_auto_ads = Advanced_Ads_AdSense_Data::get_instance()->is_page_level_enabled();
331
+ $warnings[] = [
332
  'class' => 'advads-adsense-found-in-content advads-notice-inline advads-error',
333
  'text' => sprintf(
334
  // translators: %1$s opening button tag, %2$s closing button tag.
336
  '<button class="button-secondary" id="switch-to-adsense-type">',
337
  '</button>'
338
  ),
339
+ ];
340
  }
341
  }
342
 
393
  $styles[] = sprintf( 'label[for="%s-hide"]', $box_id );
394
 
395
  return $styles;
396
+ }, [] ) ) );
397
  }
398
 
399
  /**
409
 
410
  // get public post types.
411
  $public_post_types = get_post_types(
412
+ [
413
  'public' => true,
414
  'publicly_queryable' => true,
415
+ ],
416
  'names',
417
  'or'
418
  );
422
  add_meta_box(
423
  'advads-ad-settings',
424
  __( 'Ad Settings', 'advanced-ads' ),
425
+ [ $this, 'render_post_meta_box' ],
426
  $post_type,
427
  'side',
428
  'low'
500
  * @param array $classes class attributes.
501
  * @return array $classes
502
  */
503
+ public function close_ad_type_metabox( $classes = [] ) {
504
  global $post;
505
  if ( isset( $post->ID ) && 'publish' === $post->post_status ) {
506
  if ( ! in_array( 'closed', $classes, true ) ) {
507
  $classes[] = 'closed';
508
  }
509
  } else {
510
+ $classes = [];
511
  }
512
  return $classes;
513
  }
520
  if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ) ) ) {
521
  return;
522
  }
523
+ add_meta_box( 'advads_dashboard_widget', __( 'Dashboard', 'advanced-ads' ), [ $this, 'dashboard_widget_function' ], 'dashboard', 'side', 'high' );
524
  }
525
 
526
  /**
536
  echo '<p>';
537
  printf(
538
  // translators: %1$d is the number of ads, %2$s and %3$s are URLs.
539
+ wp_kses( __( '%1$d ads – <a href="%2$s">manage</a> - <a href="%3$s">new</a>', 'advanced-ads' ), [ 'a' => [ 'href' => [] ] ] ),
540
  absint( $ads_count ),
541
  'edit.php?post_type=' . esc_attr( Advanced_Ads::POST_TYPE_SLUG ),
542
  'post-new.php?post_type=' . esc_attr( Advanced_Ads::POST_TYPE_SLUG )
615
 
616
  $cache_key = 'dash_' . md5( 'advads_dashboard_widget' );
617
 
618
+ $feeds = [
619
+ [
620
  'link' => ADVADS_URL,
621
  'url' => ADVADS_URL . 'feed/',
622
  'title' => sprintf(
628
  'show_summary' => 1,
629
  'show_author' => 0,
630
  'show_date' => 0,
631
+ ],
632
+ ];
633
 
634
  // create output and also cache it.
635
 
admin/includes/class-notices.php CHANGED
@@ -32,7 +32,7 @@ class Advanced_Ads_Admin_Notices {
32
  *
33
  * @var array
34
  */
35
- public $notices = array();
36
 
37
  /**
38
  * Plugin class
@@ -49,7 +49,7 @@ class Advanced_Ads_Admin_Notices {
49
  // load notices.
50
  $this->load_notices();
51
 
52
- add_action( 'advanced-ads-ad-params-before', array( $this, 'adsense_tutorial' ), 10, 2 );
53
  }
54
 
55
  /**
@@ -76,7 +76,7 @@ class Advanced_Ads_Admin_Notices {
76
  $plugin_options = $this->plugin->options();
77
 
78
  // load notices from queue.
79
- $this->notices = isset( $options['queue'] ) ? $options['queue'] : array();
80
  $notices_before = $this->notices;
81
 
82
  // check license notices.
@@ -119,9 +119,9 @@ class Advanced_Ads_Admin_Notices {
119
  $activation = ( isset( $internal_options['installed'] ) ) ? $internal_options['installed'] : $now; // activation time.
120
 
121
  $options = $this->options();
122
- $closed = isset( $options['closed'] ) ? $options['closed'] : array();
123
- $queue = isset( $options['queue'] ) ? $options['queue'] : array();
124
- $paused = isset( $options['paused'] ) ? $options['paused'] : array();
125
 
126
  // offer free add-ons if not yet subscribed.
127
  if ( $this->user_can_subscribe() && ! in_array( 'nl_free_addons', $queue, true ) && ! isset( $closed['nl_free_addons'] ) ) {
@@ -140,7 +140,7 @@ class Advanced_Ads_Admin_Notices {
140
 
141
  // register intro message.
142
  if ( ! $number_of_ads
143
- && array() === $options && ! in_array( 'nl_intro', $queue, true ) && ! isset( $closed['nl_intro'] ) ) {
144
  $this->notices[] = 'nl_intro';
145
  } elseif ( $number_of_ads ) {
146
  $key = array_search( 'nl_intro', $this->notices, true );
@@ -175,7 +175,7 @@ class Advanced_Ads_Admin_Notices {
175
  }
176
 
177
  $options = $this->options();
178
- $queue = isset( $options['queue'] ) ? $options['queue'] : array();
179
  // check license keys.
180
 
181
  if ( Advanced_Ads_Checks::licenses_invalid() ) {
@@ -201,7 +201,7 @@ class Advanced_Ads_Admin_Notices {
201
 
202
  // get queue from options.
203
  $options = $this->options();
204
- $queue = isset( $options['queue'] ) ? $options['queue'] : array();
205
 
206
  if ( is_array( $notices ) ) {
207
  $queue = array_merge( $queue, $notices );
@@ -237,8 +237,8 @@ class Advanced_Ads_Admin_Notices {
237
  return;
238
  }
239
  $queue = (array) $options['queue'];
240
- $closed = isset( $options['closed'] ) ? $options['closed'] : array();
241
- $paused = isset( $options['paused'] ) ? $options['paused'] : array();
242
 
243
  $key = array_search( $notice, $queue, true );
244
  if ( false !== $key ) {
@@ -285,7 +285,7 @@ class Advanced_Ads_Admin_Notices {
285
  return;
286
  }
287
  $queue = (array) $options['queue'];
288
- $paused = isset( $options['paused'] ) ? $options['paused'] : array();
289
 
290
  $key = array_search( $notice, $queue, true );
291
  if ( false !== $key ) {
@@ -322,14 +322,14 @@ class Advanced_Ads_Admin_Notices {
322
  if ( time() > 1669291200 &&
323
  time() <= 1669723200 && Advanced_Ads_Admin::get_instance()->screen_belongs_to_advanced_ads() ) {
324
  $options = $this->options();
325
- $closed = isset( $options['closed'] ) ? $options['closed'] : array();
326
 
327
  if ( ! isset( $closed['bfcm22'] ) ) {
328
  $this->notices[] = 'bfcm22';
329
  }
330
  }
331
 
332
- if ( array() === $this->notices ) {
333
  return;
334
  }
335
 
@@ -398,7 +398,7 @@ class Advanced_Ads_Admin_Notices {
398
  */
399
  public function options() {
400
  if ( ! isset( $this->options ) ) {
401
- $this->options = get_option( ADVADS_SLUG . '-notices', array() );
402
  }
403
 
404
  return $this->options;
@@ -411,7 +411,7 @@ class Advanced_Ads_Admin_Notices {
411
  */
412
  public function update_options( array $options ) {
413
  // do not allow to clear options.
414
- if ( array() === $options ) {
415
  return;
416
  }
417
 
@@ -439,21 +439,21 @@ class Advanced_Ads_Admin_Notices {
439
  return sprintf( __( 'You don’t seem to have an email address. Please use <a href="%s" target="_blank">this form</a> to sign up.', 'advanced-ads' ), 'http://eepurl.com/bk4z4P' );
440
  }
441
 
442
- $data = array(
443
  'email' => $user->user_email,
444
  'notice' => $notice,
445
- );
446
 
447
  $result = wp_remote_post(
448
  'https://wpadvancedads.com/remote/subscribe.php?source=plugin',
449
- array(
450
  'method' => 'POST',
451
  'timeout' => 20,
452
  'redirection' => 5,
453
  'httpversion' => '1.1',
454
  'blocking' => true,
455
  'body' => $data,
456
- )
457
  );
458
 
459
  if ( is_wp_error( $result ) ) {
@@ -535,7 +535,7 @@ class Advanced_Ads_Admin_Notices {
535
  * @param Advanced_Ads_Ad $ad ad object.
536
  * @param array $types ad types.
537
  */
538
- public function adsense_tutorial( $ad, $types = array() ) {
539
 
540
  $options = $this->options();
541
  $_notice = 'nl_adsense';
32
  *
33
  * @var array
34
  */
35
+ public $notices = [];
36
 
37
  /**
38
  * Plugin class
49
  // load notices.
50
  $this->load_notices();
51
 
52
+ add_action( 'advanced-ads-ad-params-before', [ $this, 'adsense_tutorial' ], 10, 2 );
53
  }
54
 
55
  /**
76
  $plugin_options = $this->plugin->options();
77
 
78
  // load notices from queue.
79
+ $this->notices = isset( $options['queue'] ) ? $options['queue'] : [];
80
  $notices_before = $this->notices;
81
 
82
  // check license notices.
119
  $activation = ( isset( $internal_options['installed'] ) ) ? $internal_options['installed'] : $now; // activation time.
120
 
121
  $options = $this->options();
122
+ $closed = isset( $options['closed'] ) ? $options['closed'] : [];
123
+ $queue = isset( $options['queue'] ) ? $options['queue'] : [];
124
+ $paused = isset( $options['paused'] ) ? $options['paused'] : [];
125
 
126
  // offer free add-ons if not yet subscribed.
127
  if ( $this->user_can_subscribe() && ! in_array( 'nl_free_addons', $queue, true ) && ! isset( $closed['nl_free_addons'] ) ) {
140
 
141
  // register intro message.
142
  if ( ! $number_of_ads
143
+ && [] === $options && ! in_array( 'nl_intro', $queue, true ) && ! isset( $closed['nl_intro'] ) ) {
144
  $this->notices[] = 'nl_intro';
145
  } elseif ( $number_of_ads ) {
146
  $key = array_search( 'nl_intro', $this->notices, true );
175
  }
176
 
177
  $options = $this->options();
178
+ $queue = isset( $options['queue'] ) ? $options['queue'] : [];
179
  // check license keys.
180
 
181
  if ( Advanced_Ads_Checks::licenses_invalid() ) {
201
 
202
  // get queue from options.
203
  $options = $this->options();
204
+ $queue = isset( $options['queue'] ) ? $options['queue'] : [];
205
 
206
  if ( is_array( $notices ) ) {
207
  $queue = array_merge( $queue, $notices );
237
  return;
238
  }
239
  $queue = (array) $options['queue'];
240
+ $closed = isset( $options['closed'] ) ? $options['closed'] : [];
241
+ $paused = isset( $options['paused'] ) ? $options['paused'] : [];
242
 
243
  $key = array_search( $notice, $queue, true );
244
  if ( false !== $key ) {
285
  return;
286
  }
287
  $queue = (array) $options['queue'];
288
+ $paused = isset( $options['paused'] ) ? $options['paused'] : [];
289
 
290
  $key = array_search( $notice, $queue, true );
291
  if ( false !== $key ) {
322
  if ( time() > 1669291200 &&
323
  time() <= 1669723200 && Advanced_Ads_Admin::get_instance()->screen_belongs_to_advanced_ads() ) {
324
  $options = $this->options();
325
+ $closed = isset( $options['closed'] ) ? $options['closed'] : [];
326
 
327
  if ( ! isset( $closed['bfcm22'] ) ) {
328
  $this->notices[] = 'bfcm22';
329
  }
330
  }
331
 
332
+ if ( [] === $this->notices ) {
333
  return;
334
  }
335
 
398
  */
399
  public function options() {
400
  if ( ! isset( $this->options ) ) {
401
+ $this->options = get_option( ADVADS_SLUG . '-notices', [] );
402
  }
403
 
404
  return $this->options;
411
  */
412
  public function update_options( array $options ) {
413
  // do not allow to clear options.
414
+ if ( [] === $options ) {
415
  return;
416
  }
417
 
439
  return sprintf( __( 'You don’t seem to have an email address. Please use <a href="%s" target="_blank">this form</a> to sign up.', 'advanced-ads' ), 'http://eepurl.com/bk4z4P' );
440
  }
441
 
442
+ $data = [
443
  'email' => $user->user_email,
444
  'notice' => $notice,
445
+ ];
446
 
447
  $result = wp_remote_post(
448
  'https://wpadvancedads.com/remote/subscribe.php?source=plugin',
449
+ [
450
  'method' => 'POST',
451
  'timeout' => 20,
452
  'redirection' => 5,
453
  'httpversion' => '1.1',
454
  'blocking' => true,
455
  'body' => $data,
456
+ ]
457
  );
458
 
459
  if ( is_wp_error( $result ) ) {
535
  * @param Advanced_Ads_Ad $ad ad object.
536
  * @param array $types ad types.
537
  */
538
+ public function adsense_tutorial( $ad, $types = [] ) {
539
 
540
  $options = $this->options();
541
  $_notice = 'nl_adsense';
admin/includes/class-overview-widgets.php CHANGED
@@ -30,12 +30,12 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
30
 
31
  // initiate i18n notice.
32
  new Yoast_I18n_WordPressOrg_v3(
33
- array(
34
  'textdomain' => 'advanced-ads',
35
  'plugin_name' => 'Advanced Ads',
36
  'hook' => 'advanced-ads-overview-below-support',
37
  'glotpress_logo' => false, // disables the plugin icon so we don’t need to keep up with potential changes.
38
- )
39
  );
40
 
41
  // show errors.
@@ -84,7 +84,7 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
84
  */
85
  public static function add_meta_box( $id, $title, $position, $callback ) {
86
  ob_start();
87
- call_user_func( array( 'Advanced_Ads_Overview_Widgets_Callbacks', $callback ) );
88
  do_action( 'advanced-ads-overview-widget-content-' . $id, $id );
89
  $content = ob_get_clean();
90
 
@@ -189,12 +189,12 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
189
  wp_kses(
190
  // translators: %s is a URL.
191
  __( 'Thank the developer with a &#9733;&#9733;&#9733;&#9733;&#9733; review on <a href="%s" target="_blank">wordpress.org</a>', 'advanced-ads' ),
192
- array(
193
- 'a' => array(
194
- 'href' => array(),
195
- 'target' => array(),
196
- ),
197
- )
198
  ),
199
  'https://wordpress.org/support/plugin/advanced-ads/reviews/#new-post'
200
  );
@@ -296,7 +296,7 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
296
  if ( wp_verify_nonce( $post_data['nonce'], 'advads-gadsense-dashboard' ) === false ) {
297
  wp_send_json_error( 'Unauthorized request', 401 );
298
  }
299
- $report_type = in_array( $post_data['type'], array( 'domain', 'unit' ), true ) ? $post_data['type'] : false;
300
 
301
  if ( ! $report_type ) {
302
  wp_send_json_error( 'Invalid arguments', 400 );
@@ -307,17 +307,17 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
307
 
308
  if ( $report->get_data()->is_valid() ) {
309
  // There is valid data
310
- wp_send_json_success( array( 'html' => $report->get_markup() ) );
311
  }
312
 
313
  if ( $report->refresh_report() ) {
314
  // we got new data from Google;
315
- wp_send_json_success( array( 'html' => $report->get_markup() ) );
316
  }
317
 
318
  $error_message = $report->get_last_api_error();
319
  // Send markup with error info.
320
- wp_send_json_success( array( 'html' => '<div class="error"><p>' . wp_kses_post( $error_message ) . '</p></div>' ) );
321
  }
322
 
323
  /**
@@ -385,7 +385,7 @@ endif;
385
  <?php
386
  printf(
387
  // translators: %s is the name of another plugin.
388
- wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), array( 'strong' => array() ) ),
389
  'bbPress'
390
  );
391
  ?>
@@ -397,7 +397,7 @@ endif;
397
  <?php
398
  printf(
399
  // translators: %s is the name of another plugin.
400
- wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), array( 'strong' => array() ) ),
401
  defined( 'BP_PLATFORM_VERSION' ) ? 'BuddyBoss' : 'BuddyPress'
402
  );
403
  ?>
@@ -409,7 +409,7 @@ endif;
409
  <?php
410
  printf(
411
  // translators: %s is the name of another plugin.
412
- wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), array( 'strong' => array() ) ),
413
  'Paid Memberships Pro'
414
  );
415
  ?>
@@ -421,7 +421,7 @@ endif;
421
  <?php
422
  printf(
423
  // translators: %s is the name of another plugin.
424
- wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), array( 'strong' => array() ) ),
425
  'WPML'
426
  );
427
  ?>
@@ -436,65 +436,65 @@ endif;
436
  <?php
437
  $pro_content = ob_get_clean();
438
 
439
- $add_ons = array(
440
- 'pro' => array(
441
  'title' => 'Advanced Ads Pro',
442
  'desc' => $pro_content,
443
  'link' => ADVADS_URL . 'add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
444
  'order' => 4,
445
  'class' => 'recommended',
446
- ),
447
- 'tracking' => array(
448
  'title' => 'Tracking',
449
  'desc' => __( 'Analyze clicks and impressions of your ads locally or in Google Analytics, share reports, and limit ads to a specific number of impressions or clicks.', 'advanced-ads' ),
450
  'link' => ADVADS_URL . 'add-ons/tracking/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
451
  'order' => 4,
452
- ),
453
- 'responsive' => array(
454
  'title' => 'Responsive, AMP and Mobile ads',
455
  'desc' => __( 'Display ads based on the device or the size of your visitor’s browser, and control ads on AMP pages.', 'advanced-ads' ),
456
  'link' => ADVADS_URL . 'add-ons/responsive-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
457
  'order' => 4,
458
- ),
459
- 'gam' => array(
460
  'title' => 'Google Ad Manager Integration',
461
  'desc' => __( 'A quick and error-free way of implementing ad units from your Google Ad Manager account.', 'advanced-ads' ),
462
  'link' => ADVADS_URL . 'add-ons/google-ad-manager/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
463
  'order' => 5,
464
- ),
465
- 'sticky' => array(
466
  'title' => 'Sticky ads',
467
  'desc' => __( 'Increase click rates on your ads by placing them in sticky positions above, next or below your site.', 'advanced-ads' ),
468
  'link' => ADVADS_URL . 'add-ons/sticky-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
469
  'order' => 5,
470
- ),
471
- 'layer' => array(
472
  'title' => 'PopUps and Layers',
473
  'desc' => __( 'Users will never miss an ad or other information in a PopUp. Choose when it shows up and for how long a user can close it.', 'advanced-ads' ),
474
  'link' => ADVADS_URL . 'add-ons/popup-and-layer-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
475
  'order' => 5,
476
- ),
477
- 'selling' => array(
478
  'title' => 'Selling Ads',
479
  'desc' => __( 'Earn more money and let advertisers pay for ad space directly on the frontend of your site.', 'advanced-ads' ),
480
  'link' => ADVADS_URL . 'add-ons/selling-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
481
  'order' => 6,
482
- ),
483
- 'slider' => array(
484
  'title' => 'Ad Slider',
485
  'desc' => __( 'Create a beautiful and simple slider from your ads to show more information on less space.', 'advanced-ads' ),
486
  'link' => ADVADS_URL . 'add-ons/slider/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
487
  'order' => 6,
488
- ),
489
- 'adsense-in-feed' => array(
490
  'title' => 'AdSense In-feed',
491
  'desc' => __( 'Place AdSense In-feed ads between posts on homepage, category, and archive pages.', 'advanced-ads' ),
492
  'class' => 'free',
493
  'link' => wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=advanced-ads-adsense-in-feed' ), 'install-plugin_advanced-ads-adsense-in-feed' ),
494
  'link_title' => __( 'Install now', 'advanced-ads' ),
495
  'order' => 9,
496
- ),
497
- );
498
 
499
  // get all installed plugins; installed is not activated.
500
  $installed_plugins = get_plugins();
@@ -657,14 +657,14 @@ endif;
657
 
658
  // add Genesis Ads, if Genesis based theme was detected.
659
  if ( defined( 'PARENT_THEME_NAME' ) && 'Genesis' === PARENT_THEME_NAME ) {
660
- $add_ons['genesis'] = array(
661
  'title' => 'Genesis Ads',
662
  'desc' => __( 'Use Genesis specific ad positions.', 'advanced-ads' ),
663
  'order' => 2,
664
  'class' => 'free',
665
  'link' => wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=advanced-ads-genesis' ), 'install-plugin_advanced-ads-genesis' ),
666
  'link_title' => __( 'Install now', 'advanced-ads' ),
667
- );
668
  // handle install link as long as we can not be sure this is done by the Genesis plugin itself.
669
  if ( isset( $installed_plugins['advanced-ads-genesis/genesis-ads.php'] ) ) { // is installed (active or not).
670
  unset( $add_ons['genesis'] );
@@ -673,14 +673,14 @@ endif;
673
 
674
  // add Ads for WPBakery Page Builder (formerly Visual Composer), if VC was detected.
675
  if ( defined( 'WPB_VC_VERSION' ) ) {
676
- $add_ons['visual_composer'] = array(
677
  'title' => 'Ads for WPBakery Page Builder (formerly Visual Composer)',
678
  'desc' => __( 'Manage ad positions with WPBakery Page Builder (formerly Visual Composer).', 'advanced-ads' ),
679
  'order' => 2,
680
  'class' => 'free',
681
  'link' => wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=ads-for-visual-composer' ), 'install-plugin_ads-for-visual-composer' ),
682
  'link_title' => __( 'Install now', 'advanced-ads' ),
683
- );
684
  // handle install link as long as we can not be sure this is done by the Genesis plugin itself.
685
  if ( isset( $installed_plugins['ads-for-visual-composer/advanced-ads-vc.php'] ) ) { // is installed (active or not).
686
  unset( $add_ons['visual_composer'] );
@@ -689,14 +689,14 @@ endif;
689
 
690
  // show All Access Pitch if less than 2 add-ons exist.
691
  if ( $installed_pro_plugins < 2 ) {
692
- $add_ons['bundle'] = array(
693
  'title' => 'All Access',
694
  'desc' => __( 'Our best deal with all add-ons included.', 'advanced-ads' ),
695
  'link' => ADVADS_URL . 'add-ons/all-access/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
696
  'link_title' => __( 'Get full access', 'advanced-ads' ),
697
  'link_primary' => true,
698
  'order' => 0,
699
- );
700
  }
701
 
702
  $all_access_expiry = Advanced_Ads_Admin_Licenses::get_instance()->get_probably_all_access_expiry();
@@ -705,20 +705,20 @@ endif;
705
  $installed_pro_plugins < 2
706
  || ( $all_access_expiry && ( time() + YEAR_IN_SECONDS ) > strtotime( $all_access_expiry ) )
707
  ) {
708
- $add_ons['long_term'] = array(
709
  'title' => 'All Access long-term',
710
  'desc' => __( 'A one-time payment for four years of support and updates. The package saves you up to 70% compared to individually purchasing our add-ons.', 'advanced-ads' ),
711
  'link' => ADVADS_URL . 'add-ons/all-access-long-term/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
712
  'link_title' => __( 'Get full access', 'advanced-ads' ),
713
  'link_primary' => true,
714
  'order' => 1,
715
- );
716
  }
717
 
718
  // allow add-ons to manipulate the output.
719
  $add_ons = apply_filters( 'advanced-ads-overview-add-ons', $add_ons );
720
 
721
- uasort( $add_ons, array( 'self', 'sort_by_order' ) );
722
 
723
  ?>
724
  <table class="widefat striped">
30
 
31
  // initiate i18n notice.
32
  new Yoast_I18n_WordPressOrg_v3(
33
+ [
34
  'textdomain' => 'advanced-ads',
35
  'plugin_name' => 'Advanced Ads',
36
  'hook' => 'advanced-ads-overview-below-support',
37
  'glotpress_logo' => false, // disables the plugin icon so we don’t need to keep up with potential changes.
38
+ ]
39
  );
40
 
41
  // show errors.
84
  */
85
  public static function add_meta_box( $id, $title, $position, $callback ) {
86
  ob_start();
87
+ call_user_func( [ 'Advanced_Ads_Overview_Widgets_Callbacks', $callback ] );
88
  do_action( 'advanced-ads-overview-widget-content-' . $id, $id );
89
  $content = ob_get_clean();
90
 
189
  wp_kses(
190
  // translators: %s is a URL.
191
  __( 'Thank the developer with a &#9733;&#9733;&#9733;&#9733;&#9733; review on <a href="%s" target="_blank">wordpress.org</a>', 'advanced-ads' ),
192
+ [
193
+ 'a' => [
194
+ 'href' => [],
195
+ 'target' => [],
196
+ ],
197
+ ]
198
  ),
199
  'https://wordpress.org/support/plugin/advanced-ads/reviews/#new-post'
200
  );
296
  if ( wp_verify_nonce( $post_data['nonce'], 'advads-gadsense-dashboard' ) === false ) {
297
  wp_send_json_error( 'Unauthorized request', 401 );
298
  }
299
+ $report_type = in_array( $post_data['type'], [ 'domain', 'unit' ], true ) ? $post_data['type'] : false;
300
 
301
  if ( ! $report_type ) {
302
  wp_send_json_error( 'Invalid arguments', 400 );
307
 
308
  if ( $report->get_data()->is_valid() ) {
309
  // There is valid data
310
+ wp_send_json_success( [ 'html' => $report->get_markup() ] );
311
  }
312
 
313
  if ( $report->refresh_report() ) {
314
  // we got new data from Google;
315
+ wp_send_json_success( [ 'html' => $report->get_markup() ] );
316
  }
317
 
318
  $error_message = $report->get_last_api_error();
319
  // Send markup with error info.
320
+ wp_send_json_success( [ 'html' => '<div class="error"><p>' . wp_kses_post( $error_message ) . '</p></div>' ] );
321
  }
322
 
323
  /**
385
  <?php
386
  printf(
387
  // translators: %s is the name of another plugin.
388
+ wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), [ 'strong' => [] ] ),
389
  'bbPress'
390
  );
391
  ?>
397
  <?php
398
  printf(
399
  // translators: %s is the name of another plugin.
400
+ wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), [ 'strong' => [] ] ),
401
  defined( 'BP_PLATFORM_VERSION' ) ? 'BuddyBoss' : 'BuddyPress'
402
  );
403
  ?>
409
  <?php
410
  printf(
411
  // translators: %s is the name of another plugin.
412
+ wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), [ 'strong' => [] ] ),
413
  'Paid Memberships Pro'
414
  );
415
  ?>
421
  <?php
422
  printf(
423
  // translators: %s is the name of another plugin.
424
+ wp_kses( __( 'integrates with <strong>%s</strong>', 'advanced-ads' ), [ 'strong' => [] ] ),
425
  'WPML'
426
  );
427
  ?>
436
  <?php
437
  $pro_content = ob_get_clean();
438
 
439
+ $add_ons = [
440
+ 'pro' => [
441
  'title' => 'Advanced Ads Pro',
442
  'desc' => $pro_content,
443
  'link' => ADVADS_URL . 'add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
444
  'order' => 4,
445
  'class' => 'recommended',
446
+ ],
447
+ 'tracking' => [
448
  'title' => 'Tracking',
449
  'desc' => __( 'Analyze clicks and impressions of your ads locally or in Google Analytics, share reports, and limit ads to a specific number of impressions or clicks.', 'advanced-ads' ),
450
  'link' => ADVADS_URL . 'add-ons/tracking/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
451
  'order' => 4,
452
+ ],
453
+ 'responsive' => [
454
  'title' => 'Responsive, AMP and Mobile ads',
455
  'desc' => __( 'Display ads based on the device or the size of your visitor’s browser, and control ads on AMP pages.', 'advanced-ads' ),
456
  'link' => ADVADS_URL . 'add-ons/responsive-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
457
  'order' => 4,
458
+ ],
459
+ 'gam' => [
460
  'title' => 'Google Ad Manager Integration',
461
  'desc' => __( 'A quick and error-free way of implementing ad units from your Google Ad Manager account.', 'advanced-ads' ),
462
  'link' => ADVADS_URL . 'add-ons/google-ad-manager/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
463
  'order' => 5,
464
+ ],
465
+ 'sticky' => [
466
  'title' => 'Sticky ads',
467
  'desc' => __( 'Increase click rates on your ads by placing them in sticky positions above, next or below your site.', 'advanced-ads' ),
468
  'link' => ADVADS_URL . 'add-ons/sticky-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
469
  'order' => 5,
470
+ ],
471
+ 'layer' => [
472
  'title' => 'PopUps and Layers',
473
  'desc' => __( 'Users will never miss an ad or other information in a PopUp. Choose when it shows up and for how long a user can close it.', 'advanced-ads' ),
474
  'link' => ADVADS_URL . 'add-ons/popup-and-layer-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
475
  'order' => 5,
476
+ ],
477
+ 'selling' => [
478
  'title' => 'Selling Ads',
479
  'desc' => __( 'Earn more money and let advertisers pay for ad space directly on the frontend of your site.', 'advanced-ads' ),
480
  'link' => ADVADS_URL . 'add-ons/selling-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
481
  'order' => 6,
482
+ ],
483
+ 'slider' => [
484
  'title' => 'Ad Slider',
485
  'desc' => __( 'Create a beautiful and simple slider from your ads to show more information on less space.', 'advanced-ads' ),
486
  'link' => ADVADS_URL . 'add-ons/slider/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
487
  'order' => 6,
488
+ ],
489
+ 'adsense-in-feed' => [
490
  'title' => 'AdSense In-feed',
491
  'desc' => __( 'Place AdSense In-feed ads between posts on homepage, category, and archive pages.', 'advanced-ads' ),
492
  'class' => 'free',
493
  'link' => wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=advanced-ads-adsense-in-feed' ), 'install-plugin_advanced-ads-adsense-in-feed' ),
494
  'link_title' => __( 'Install now', 'advanced-ads' ),
495
  'order' => 9,
496
+ ],
497
+ ];
498
 
499
  // get all installed plugins; installed is not activated.
500
  $installed_plugins = get_plugins();
657
 
658
  // add Genesis Ads, if Genesis based theme was detected.
659
  if ( defined( 'PARENT_THEME_NAME' ) && 'Genesis' === PARENT_THEME_NAME ) {
660
+ $add_ons['genesis'] = [
661
  'title' => 'Genesis Ads',
662
  'desc' => __( 'Use Genesis specific ad positions.', 'advanced-ads' ),
663
  'order' => 2,
664
  'class' => 'free',
665
  'link' => wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=advanced-ads-genesis' ), 'install-plugin_advanced-ads-genesis' ),
666
  'link_title' => __( 'Install now', 'advanced-ads' ),
667
+ ];
668
  // handle install link as long as we can not be sure this is done by the Genesis plugin itself.
669
  if ( isset( $installed_plugins['advanced-ads-genesis/genesis-ads.php'] ) ) { // is installed (active or not).
670
  unset( $add_ons['genesis'] );
673
 
674
  // add Ads for WPBakery Page Builder (formerly Visual Composer), if VC was detected.
675
  if ( defined( 'WPB_VC_VERSION' ) ) {
676
+ $add_ons['visual_composer'] = [
677
  'title' => 'Ads for WPBakery Page Builder (formerly Visual Composer)',
678
  'desc' => __( 'Manage ad positions with WPBakery Page Builder (formerly Visual Composer).', 'advanced-ads' ),
679
  'order' => 2,
680
  'class' => 'free',
681
  'link' => wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=ads-for-visual-composer' ), 'install-plugin_ads-for-visual-composer' ),
682
  'link_title' => __( 'Install now', 'advanced-ads' ),
683
+ ];
684
  // handle install link as long as we can not be sure this is done by the Genesis plugin itself.
685
  if ( isset( $installed_plugins['ads-for-visual-composer/advanced-ads-vc.php'] ) ) { // is installed (active or not).
686
  unset( $add_ons['visual_composer'] );
689
 
690
  // show All Access Pitch if less than 2 add-ons exist.
691
  if ( $installed_pro_plugins < 2 ) {
692
+ $add_ons['bundle'] = [
693
  'title' => 'All Access',
694
  'desc' => __( 'Our best deal with all add-ons included.', 'advanced-ads' ),
695
  'link' => ADVADS_URL . 'add-ons/all-access/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
696
  'link_title' => __( 'Get full access', 'advanced-ads' ),
697
  'link_primary' => true,
698
  'order' => 0,
699
+ ];
700
  }
701
 
702
  $all_access_expiry = Advanced_Ads_Admin_Licenses::get_instance()->get_probably_all_access_expiry();
705
  $installed_pro_plugins < 2
706
  || ( $all_access_expiry && ( time() + YEAR_IN_SECONDS ) > strtotime( $all_access_expiry ) )
707
  ) {
708
+ $add_ons['long_term'] = [
709
  'title' => 'All Access long-term',
710
  'desc' => __( 'A one-time payment for four years of support and updates. The package saves you up to 70% compared to individually purchasing our add-ons.', 'advanced-ads' ),
711
  'link' => ADVADS_URL . 'add-ons/all-access-long-term/?utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
712
  'link_title' => __( 'Get full access', 'advanced-ads' ),
713
  'link_primary' => true,
714
  'order' => 1,
715
+ ];
716
  }
717
 
718
  // allow add-ons to manipulate the output.
719
  $add_ons = apply_filters( 'advanced-ads-overview-add-ons', $add_ons );
720
 
721
+ uasort( $add_ons, [ 'self', 'sort_by_order' ] );
722
 
723
  ?>
724
  <table class="widefat striped">
admin/includes/class-settings.php CHANGED
@@ -16,10 +16,10 @@ class Advanced_Ads_Admin_Settings {
16
  */
17
  private function __construct() {
18
  // settings handling.
19
- add_action( 'admin_init', array( $this, 'settings_init' ) );
20
 
21
  // add ad admin capabilities for settings.
22
- add_action( 'admin_init', array( $this, 'settings_capabilities' ), 20 );
23
  }
24
 
25
  /**
@@ -47,13 +47,13 @@ class Advanced_Ads_Admin_Settings {
47
  $hook = Advanced_Ads_Admin::get_instance()->plugin_screen_hook_suffix;
48
 
49
  // register settings.
50
- register_setting( ADVADS_SLUG, ADVADS_SLUG, array( $this, 'sanitize_settings' ) );
51
 
52
  // "Management" settings section.
53
  add_settings_section(
54
  'advanced_ads_setting_section',
55
  __( 'Admin', 'advanced-ads' ),
56
- array( $this, 'render_settings_section_callback' ),
57
  $hook
58
  );
59
 
@@ -61,7 +61,7 @@ class Advanced_Ads_Admin_Settings {
61
  add_settings_section(
62
  'advanced_ads_setting_section_disable_ads',
63
  __( 'Disable ads', 'advanced-ads' ),
64
- array( $this, 'render_settings_section_disable_ads_callback' ),
65
  $hook
66
  );
67
 
@@ -69,7 +69,7 @@ class Advanced_Ads_Admin_Settings {
69
  add_settings_section(
70
  'advanced_ads_setting_section_output',
71
  __( 'Layout / Output', 'advanced-ads' ),
72
- array( $this, 'render_settings_section_output_callback' ),
73
  $hook
74
  );
75
 
@@ -77,7 +77,7 @@ class Advanced_Ads_Admin_Settings {
77
  add_settings_section(
78
  'advanced_ads_setting_section_injection',
79
  __( 'Content injection', 'advanced-ads' ),
80
- array( $this, 'render_settings_section_injection_callback' ),
81
  $hook
82
  );
83
 
@@ -86,11 +86,11 @@ class Advanced_Ads_Admin_Settings {
86
  add_settings_section(
87
  'advanced_ads_settings_pro_pitch_section',
88
  '',
89
- array( $this, 'render_settings_pro_pitch_section_callback' ),
90
  'advanced-ads-settings-pro-pitch-page'
91
  );
92
 
93
- add_filter( 'advanced-ads-setting-tabs', array( $this, 'pro_pitch_tab' ) );
94
  }
95
 
96
  // Tracking pitch section.
@@ -98,11 +98,11 @@ class Advanced_Ads_Admin_Settings {
98
  add_settings_section(
99
  'advanced_ads_settings_tracking_pitch_section',
100
  '',
101
- array( $this, 'render_settings_tracking_pitch_section_callback' ),
102
  'advanced-ads-settings-tracking-pitch-page'
103
  );
104
 
105
- add_filter( 'advanced-ads-setting-tabs', array( $this, 'tracking_pitch_tab' ) );
106
  }
107
 
108
  // licenses section.
@@ -125,16 +125,16 @@ class Advanced_Ads_Admin_Settings {
125
  add_settings_section(
126
  'advanced_ads_settings_license_section',
127
  '',
128
- array( $this, 'render_settings_licenses_section_callback' ),
129
  'advanced-ads-settings-license-page'
130
  );
131
 
132
- add_filter( 'advanced-ads-setting-tabs', array( $this, 'license_tab' ) );
133
 
134
  add_settings_section(
135
  'advanced_ads_settings_license_pitch_section',
136
  '',
137
- array( $this, 'render_settings_licenses_pitch_section_callback' ),
138
  'advanced-ads-settings-license-page'
139
  );
140
 
@@ -142,7 +142,7 @@ class Advanced_Ads_Admin_Settings {
142
  add_settings_field(
143
  'disable-ads',
144
  __( 'Disable ads', 'advanced-ads' ),
145
- array( $this, 'render_settings_disable_ads' ),
146
  $hook,
147
  'advanced_ads_setting_section_disable_ads'
148
  );
@@ -150,7 +150,7 @@ class Advanced_Ads_Admin_Settings {
150
  add_settings_field(
151
  'hide-for-user-role',
152
  __( 'Hide ads for user roles', 'advanced-ads' ),
153
- array( $this, 'render_settings_hide_for_users' ),
154
  $hook,
155
  'advanced_ads_setting_section_disable_ads'
156
  );
@@ -158,7 +158,7 @@ class Advanced_Ads_Admin_Settings {
158
  add_settings_field(
159
  'content-injection-everywhere',
160
  __( 'Unlimited ad injection', 'advanced-ads' ),
161
- array( $this, 'render_settings_content_injection_everywhere' ),
162
  $hook,
163
  'advanced_ads_setting_section_injection'
164
  );
@@ -166,7 +166,7 @@ class Advanced_Ads_Admin_Settings {
166
  add_settings_field(
167
  'content-injection-priority',
168
  __( 'Priority of content injection filter', 'advanced-ads' ),
169
- array( $this, 'render_settings_content_injection_priority' ),
170
  $hook,
171
  'advanced_ads_setting_section_injection'
172
  );
@@ -174,7 +174,7 @@ class Advanced_Ads_Admin_Settings {
174
  add_settings_field(
175
  'content-injection-level-limitation',
176
  __( 'Disable level limitation', 'advanced-ads' ),
177
- array( $this, 'render_settings_content_injection_level_limitation' ),
178
  $hook,
179
  'advanced_ads_setting_section_injection'
180
  );
@@ -182,7 +182,7 @@ class Advanced_Ads_Admin_Settings {
182
  add_settings_field(
183
  'block-bots',
184
  __( 'Hide ads from bots', 'advanced-ads' ),
185
- array( $this, 'render_settings_block_bots' ),
186
  $hook,
187
  'advanced_ads_setting_section_disable_ads'
188
  );
@@ -191,7 +191,7 @@ class Advanced_Ads_Admin_Settings {
191
  add_settings_field(
192
  'disable-by-post-types-pro',
193
  __( 'Disable ads for post types', 'advanced-ads' ),
194
- array( $this, 'render_settings_disable_post_types' ),
195
  $hook,
196
  'advanced_ads_setting_section_disable_ads'
197
  );
@@ -200,7 +200,7 @@ class Advanced_Ads_Admin_Settings {
200
  add_settings_field(
201
  'disable-notices',
202
  __( 'Disable Ad Health and other notices', 'advanced-ads' ),
203
- array( $this, 'render_settings_disabled_notices' ),
204
  $hook,
205
  'advanced_ads_setting_section'
206
  );
@@ -208,7 +208,7 @@ class Advanced_Ads_Admin_Settings {
208
  add_settings_field(
209
  'front-prefix',
210
  __( 'ID prefix', 'advanced-ads' ),
211
- array( $this, 'render_settings_front_prefix' ),
212
  $hook,
213
  'advanced_ads_setting_section_output'
214
  );
@@ -216,7 +216,7 @@ class Advanced_Ads_Admin_Settings {
216
  add_settings_field(
217
  'editors-manage-ads',
218
  __( 'Allow editors to manage ads', 'advanced-ads' ),
219
- array( $this, 'render_settings_editors_manage_ads' ),
220
  $hook,
221
  'advanced_ads_setting_section'
222
  );
@@ -227,7 +227,7 @@ class Advanced_Ads_Admin_Settings {
227
  'allow-unfiltered-html',
228
  /* translators: unfiltered_html */
229
  sprintf( __( 'Add the %s capability to user roles on multisite', 'advanced-ads' ), '<code>unfiltered_html</code>' ),
230
- array( $this, 'renders_settings_allow_unfiltered_html' ),
231
  $hook,
232
  'advanced_ads_setting_section'
233
  );
@@ -237,7 +237,7 @@ class Advanced_Ads_Admin_Settings {
237
  add_settings_field(
238
  'add-custom-label',
239
  __( 'Ad label', 'advanced-ads' ),
240
- array( $this, 'render_settings_add_custom_label' ),
241
  $hook,
242
  'advanced_ads_setting_section_output'
243
  );
@@ -246,7 +246,7 @@ class Advanced_Ads_Admin_Settings {
246
  add_settings_field(
247
  'link-target',
248
  __( 'Open links in a new window', 'advanced-ads' ),
249
- array( $this, 'render_settings_link_target_callback' ),
250
  $hook,
251
  'advanced_ads_setting_section_output'
252
  );
@@ -254,7 +254,7 @@ class Advanced_Ads_Admin_Settings {
254
  add_settings_field(
255
  'activate-advanced-js',
256
  __( 'Use advanced JavaScript', 'advanced-ads' ),
257
- array( $this, 'render_settings_advanced_js' ),
258
  $hook,
259
  'advanced_ads_setting_section_output'
260
  );
@@ -264,7 +264,7 @@ class Advanced_Ads_Admin_Settings {
264
  add_settings_field(
265
  'uninstall-delete-data',
266
  __( 'Delete data on uninstall', 'advanced-ads' ),
267
- array( $this, 'render_settings_uninstall_delete_data' ),
268
  $hook,
269
  'advanced_ads_setting_section'
270
  );
@@ -280,7 +280,7 @@ class Advanced_Ads_Admin_Settings {
280
  * Filter option_page_capability_ with the appropriate slug in return to allow the Ad Admin user role to save these settings/options.
281
  */
282
  public function settings_capabilities() {
283
- $ad_admin_options = array( ADVADS_SLUG );
284
  /**
285
  * Filters all options that the Ad Admin Role should have access to.
286
  *
@@ -302,12 +302,12 @@ class Advanced_Ads_Admin_Settings {
302
  */
303
  public function license_tab( array $tabs ) {
304
 
305
- $tabs['licenses'] = array(
306
  'page' => 'advanced-ads-settings-license-page',
307
  'group' => ADVADS_SLUG . '-licenses',
308
  'tabid' => 'licenses',
309
  'title' => __( 'Licenses', 'advanced-ads' ),
310
- );
311
 
312
  return $tabs;
313
  }
@@ -321,12 +321,12 @@ class Advanced_Ads_Admin_Settings {
321
  */
322
  public function pro_pitch_tab( array $tabs ) {
323
 
324
- $tabs['pro_pitch'] = array(
325
  'page' => 'advanced-ads-settings-pro-pitch-page',
326
  // 'group' => ADVADS_SLUG . '-pro-pitch',
327
  'tabid' => 'pro-pitch',
328
  'title' => __( 'Pro', 'advanced-ads' ),
329
- );
330
 
331
  return $tabs;
332
  }
@@ -340,11 +340,11 @@ class Advanced_Ads_Admin_Settings {
340
  */
341
  public function tracking_pitch_tab( array $tabs ) {
342
 
343
- $tabs['tracking_pitch'] = array(
344
  'page' => 'advanced-ads-settings-tracking-pitch-page',
345
  'tabid' => 'tracking-pitch',
346
  'title' => __( 'Tracking', 'advanced-ads' ),
347
- );
348
 
349
  return $tabs;
350
  }
@@ -436,7 +436,7 @@ class Advanced_Ads_Admin_Settings {
436
  if ( isset( $options['hide-for-user-role'] ) ) {
437
  $hide_for_roles = Advanced_Ads_Utils::maybe_translate_cap_to_role( $options['hide-for-user-role'] );
438
  } else {
439
- $hide_for_roles = array();
440
  }
441
 
442
  global $wp_roles;
@@ -508,10 +508,10 @@ class Advanced_Ads_Admin_Settings {
508
  public function render_settings_disable_post_types() {
509
 
510
  $post_types = get_post_types(
511
- array(
512
  'public' => true,
513
  'publicly_queryable' => true,
514
- ),
515
  'objects',
516
  'or'
517
  );
@@ -572,7 +572,7 @@ class Advanced_Ads_Admin_Settings {
572
  return;
573
  }
574
  if ( ! isset( $options['allow-unfiltered-html'] ) ) {
575
- $options['allow-unfiltered-html'] = array();
576
  }
577
  $allowed_roles = $options['allow-unfiltered-html'];
578
 
16
  */
17
  private function __construct() {
18
  // settings handling.
19
+ add_action( 'admin_init', [ $this, 'settings_init' ] );
20
 
21
  // add ad admin capabilities for settings.
22
+ add_action( 'admin_init', [ $this, 'settings_capabilities' ], 20 );
23
  }
24
 
25
  /**
47
  $hook = Advanced_Ads_Admin::get_instance()->plugin_screen_hook_suffix;
48
 
49
  // register settings.
50
+ register_setting( ADVADS_SLUG, ADVADS_SLUG, [ $this, 'sanitize_settings' ] );
51
 
52
  // "Management" settings section.
53
  add_settings_section(
54
  'advanced_ads_setting_section',
55
  __( 'Admin', 'advanced-ads' ),
56
+ [ $this, 'render_settings_section_callback' ],
57
  $hook
58
  );
59
 
61
  add_settings_section(
62
  'advanced_ads_setting_section_disable_ads',
63
  __( 'Disable ads', 'advanced-ads' ),
64
+ [ $this, 'render_settings_section_disable_ads_callback' ],
65
  $hook
66
  );
67
 
69
  add_settings_section(
70
  'advanced_ads_setting_section_output',
71
  __( 'Layout / Output', 'advanced-ads' ),
72
+ [ $this, 'render_settings_section_output_callback' ],
73
  $hook
74
  );
75
 
77
  add_settings_section(
78
  'advanced_ads_setting_section_injection',
79
  __( 'Content injection', 'advanced-ads' ),
80
+ [ $this, 'render_settings_section_injection_callback' ],
81
  $hook
82
  );
83
 
86
  add_settings_section(
87
  'advanced_ads_settings_pro_pitch_section',
88
  '',
89
+ [ $this, 'render_settings_pro_pitch_section_callback' ],
90
  'advanced-ads-settings-pro-pitch-page'
91
  );
92
 
93
+ add_filter( 'advanced-ads-setting-tabs', [ $this, 'pro_pitch_tab' ] );
94
  }
95
 
96
  // Tracking pitch section.
98
  add_settings_section(
99
  'advanced_ads_settings_tracking_pitch_section',
100
  '',
101
+ [ $this, 'render_settings_tracking_pitch_section_callback' ],
102
  'advanced-ads-settings-tracking-pitch-page'
103
  );
104
 
105
+ add_filter( 'advanced-ads-setting-tabs', [ $this, 'tracking_pitch_tab' ] );
106
  }
107
 
108
  // licenses section.
125
  add_settings_section(
126
  'advanced_ads_settings_license_section',
127
  '',
128
+ [ $this, 'render_settings_licenses_section_callback' ],
129
  'advanced-ads-settings-license-page'
130
  );
131
 
132
+ add_filter( 'advanced-ads-setting-tabs', [ $this, 'license_tab' ] );
133
 
134
  add_settings_section(
135
  'advanced_ads_settings_license_pitch_section',
136
  '',
137
+ [ $this, 'render_settings_licenses_pitch_section_callback' ],
138
  'advanced-ads-settings-license-page'
139
  );
140
 
142
  add_settings_field(
143
  'disable-ads',
144
  __( 'Disable ads', 'advanced-ads' ),
145
+ [ $this, 'render_settings_disable_ads' ],
146
  $hook,
147
  'advanced_ads_setting_section_disable_ads'
148
  );
150
  add_settings_field(
151
  'hide-for-user-role',
152
  __( 'Hide ads for user roles', 'advanced-ads' ),
153
+ [ $this, 'render_settings_hide_for_users' ],
154
  $hook,
155
  'advanced_ads_setting_section_disable_ads'
156
  );
158
  add_settings_field(
159
  'content-injection-everywhere',
160
  __( 'Unlimited ad injection', 'advanced-ads' ),
161
+ [ $this, 'render_settings_content_injection_everywhere' ],
162
  $hook,
163
  'advanced_ads_setting_section_injection'
164
  );
166
  add_settings_field(
167
  'content-injection-priority',
168
  __( 'Priority of content injection filter', 'advanced-ads' ),
169
+ [ $this, 'render_settings_content_injection_priority' ],
170
  $hook,
171
  'advanced_ads_setting_section_injection'
172
  );
174
  add_settings_field(
175
  'content-injection-level-limitation',
176
  __( 'Disable level limitation', 'advanced-ads' ),
177
+ [ $this, 'render_settings_content_injection_level_limitation' ],
178
  $hook,
179
  'advanced_ads_setting_section_injection'
180
  );
182
  add_settings_field(
183
  'block-bots',
184
  __( 'Hide ads from bots', 'advanced-ads' ),
185
+ [ $this, 'render_settings_block_bots' ],
186
  $hook,
187
  'advanced_ads_setting_section_disable_ads'
188
  );
191
  add_settings_field(
192
  'disable-by-post-types-pro',
193
  __( 'Disable ads for post types', 'advanced-ads' ),
194
+ [ $this, 'render_settings_disable_post_types' ],
195
  $hook,
196
  'advanced_ads_setting_section_disable_ads'
197
  );
200
  add_settings_field(
201
  'disable-notices',
202
  __( 'Disable Ad Health and other notices', 'advanced-ads' ),
203
+ [ $this, 'render_settings_disabled_notices' ],
204
  $hook,
205
  'advanced_ads_setting_section'
206
  );
208
  add_settings_field(
209
  'front-prefix',
210
  __( 'ID prefix', 'advanced-ads' ),
211
+ [ $this, 'render_settings_front_prefix' ],
212
  $hook,
213
  'advanced_ads_setting_section_output'
214
  );
216
  add_settings_field(
217
  'editors-manage-ads',
218
  __( 'Allow editors to manage ads', 'advanced-ads' ),
219
+ [ $this, 'render_settings_editors_manage_ads' ],
220
  $hook,
221
  'advanced_ads_setting_section'
222
  );
227
  'allow-unfiltered-html',
228
  /* translators: unfiltered_html */
229
  sprintf( __( 'Add the %s capability to user roles on multisite', 'advanced-ads' ), '<code>unfiltered_html</code>' ),
230
+ [ $this, 'renders_settings_allow_unfiltered_html' ],
231
  $hook,
232
  'advanced_ads_setting_section'
233
  );
237
  add_settings_field(
238
  'add-custom-label',
239
  __( 'Ad label', 'advanced-ads' ),
240
+ [ $this, 'render_settings_add_custom_label' ],
241
  $hook,
242
  'advanced_ads_setting_section_output'
243
  );
246
  add_settings_field(
247
  'link-target',
248
  __( 'Open links in a new window', 'advanced-ads' ),
249
+ [ $this, 'render_settings_link_target_callback' ],
250
  $hook,
251
  'advanced_ads_setting_section_output'
252
  );
254
  add_settings_field(
255
  'activate-advanced-js',
256
  __( 'Use advanced JavaScript', 'advanced-ads' ),
257
+ [ $this, 'render_settings_advanced_js' ],
258
  $hook,
259
  'advanced_ads_setting_section_output'
260
  );
264
  add_settings_field(
265
  'uninstall-delete-data',
266
  __( 'Delete data on uninstall', 'advanced-ads' ),
267
+ [ $this, 'render_settings_uninstall_delete_data' ],
268
  $hook,
269
  'advanced_ads_setting_section'
270
  );
280
  * Filter option_page_capability_ with the appropriate slug in return to allow the Ad Admin user role to save these settings/options.
281
  */
282
  public function settings_capabilities() {
283
+ $ad_admin_options = [ ADVADS_SLUG ];
284
  /**
285
  * Filters all options that the Ad Admin Role should have access to.
286
  *
302
  */
303
  public function license_tab( array $tabs ) {
304
 
305
+ $tabs['licenses'] = [
306
  'page' => 'advanced-ads-settings-license-page',
307
  'group' => ADVADS_SLUG . '-licenses',
308
  'tabid' => 'licenses',
309
  'title' => __( 'Licenses', 'advanced-ads' ),
310
+ ];
311
 
312
  return $tabs;
313
  }
321
  */
322
  public function pro_pitch_tab( array $tabs ) {
323
 
324
+ $tabs['pro_pitch'] = [
325
  'page' => 'advanced-ads-settings-pro-pitch-page',
326
  // 'group' => ADVADS_SLUG . '-pro-pitch',
327
  'tabid' => 'pro-pitch',
328
  'title' => __( 'Pro', 'advanced-ads' ),
329
+ ];
330
 
331
  return $tabs;
332
  }
340
  */
341
  public function tracking_pitch_tab( array $tabs ) {
342
 
343
+ $tabs['tracking_pitch'] = [
344
  'page' => 'advanced-ads-settings-tracking-pitch-page',
345
  'tabid' => 'tracking-pitch',
346
  'title' => __( 'Tracking', 'advanced-ads' ),
347
+ ];
348
 
349
  return $tabs;
350
  }
436
  if ( isset( $options['hide-for-user-role'] ) ) {
437
  $hide_for_roles = Advanced_Ads_Utils::maybe_translate_cap_to_role( $options['hide-for-user-role'] );
438
  } else {
439
+ $hide_for_roles = [];
440
  }
441
 
442
  global $wp_roles;
508
  public function render_settings_disable_post_types() {
509
 
510
  $post_types = get_post_types(
511
+ [
512
  'public' => true,
513
  'publicly_queryable' => true,
514
+ ],
515
  'objects',
516
  'or'
517
  );
572
  return;
573
  }
574
  if ( ! isset( $options['allow-unfiltered-html'] ) ) {
575
+ $options['allow-unfiltered-html'] = [];
576
  }
577
  $allowed_roles = $options['allow-unfiltered-html'];
578
 
admin/includes/class-shortcode-creator.php CHANGED
@@ -10,7 +10,7 @@ class Advanced_Ads_Shortcode_Creator {
10
  *
11
  * @var array
12
  */
13
- private $editors_with_buttons = array();
14
 
15
  /**
16
  * Instance of this class.
@@ -23,7 +23,7 @@ class Advanced_Ads_Shortcode_Creator {
23
  * Advanced_Ads_Shortcode_Creator constructor.
24
  */
25
  private function __construct() {
26
- add_action( 'init', array( $this, 'init' ) );
27
  }
28
 
29
  /**
@@ -54,14 +54,14 @@ class Advanced_Ads_Shortcode_Creator {
54
  return;
55
  }
56
 
57
- add_action( 'wp_ajax_advads_content_for_shortcode_creator', array( $this, 'get_content_for_shortcode_creator' ) );
58
 
59
- add_filter( 'mce_buttons', array( $this, 'register_buttons' ), 10, 2 );
60
- add_filter( 'tiny_mce_plugins', array( $this, 'tiny_mce_plugins' ) );
61
- add_filter( 'tiny_mce_before_init', array( $this, 'tiny_mce_before_init' ), 10, 2 );
62
 
63
- add_action( 'wp_tiny_mce_init', array( $this, 'print_shortcode_plugin' ) );
64
- add_action( 'print_default_editor_scripts', array( $this, 'print_shortcode_plugin' ) );
65
  }
66
 
67
  /**
@@ -71,8 +71,8 @@ class Advanced_Ads_Shortcode_Creator {
71
  */
72
  private function hooks_exist() {
73
  if (
74
- has_action( 'wp_tiny_mce_init', array( $this, 'print_shortcode_plugin' ) )
75
- || has_action( 'print_default_editor_scripts', array( $this, 'print_shortcode_plugin' ) )
76
  ) {
77
  return true;
78
  }
@@ -85,7 +85,7 @@ class Advanced_Ads_Shortcode_Creator {
85
  *
86
  * @param array|null $mce_settings TinyMCE settings array.
87
  */
88
- public function print_shortcode_plugin( $mce_settings = array() ) {
89
  static $printed = null;
90
 
91
  if ( $printed !== null ) {
@@ -188,7 +188,7 @@ class Advanced_Ads_Shortcode_Creator {
188
  return $buttons;
189
  }
190
  if ( ! is_array( $buttons ) ) {
191
- $buttons = array();
192
  }
193
 
194
  $this->editors_with_buttons[] = $editor_id;
@@ -240,15 +240,15 @@ class Advanced_Ads_Shortcode_Creator {
240
  * @return array $select items for select field.
241
  */
242
  public static function items_for_select() {
243
- $select = array();
244
  $model = Advanced_Ads::get_instance()->get_model();
245
 
246
  // load all ads.
247
  $ads = $model->get_ads(
248
- array(
249
  'orderby' => 'title',
250
  'order' => 'ASC',
251
- )
252
  );
253
  foreach ( $ads as $_ad ) {
254
  $select['ads'][ 'ad_' . $_ad->ID ] = $_ad->post_title;
10
  *
11
  * @var array
12
  */
13
+ private $editors_with_buttons = [];
14
 
15
  /**
16
  * Instance of this class.
23
  * Advanced_Ads_Shortcode_Creator constructor.
24
  */
25
  private function __construct() {
26
+ add_action( 'init', [ $this, 'init' ] );
27
  }
28
 
29
  /**
54
  return;
55
  }
56
 
57
+ add_action( 'wp_ajax_advads_content_for_shortcode_creator', [ $this, 'get_content_for_shortcode_creator' ] );
58
 
59
+ add_filter( 'mce_buttons', [ $this, 'register_buttons' ], 10, 2 );
60
+ add_filter( 'tiny_mce_plugins', [ $this, 'tiny_mce_plugins' ] );
61
+ add_filter( 'tiny_mce_before_init', [ $this, 'tiny_mce_before_init' ], 10, 2 );
62
 
63
+ add_action( 'wp_tiny_mce_init', [ $this, 'print_shortcode_plugin' ] );
64
+ add_action( 'print_default_editor_scripts', [ $this, 'print_shortcode_plugin' ] );
65
  }
66
 
67
  /**
71
  */
72
  private function hooks_exist() {
73
  if (
74
+ has_action( 'wp_tiny_mce_init', [ $this, 'print_shortcode_plugin' ] )
75
+ || has_action( 'print_default_editor_scripts', [ $this, 'print_shortcode_plugin' ] )
76
  ) {
77
  return true;
78
  }
85
  *
86
  * @param array|null $mce_settings TinyMCE settings array.
87
  */
88
+ public function print_shortcode_plugin( $mce_settings = [] ) {
89
  static $printed = null;
90
 
91
  if ( $printed !== null ) {
188
  return $buttons;
189
  }
190
  if ( ! is_array( $buttons ) ) {
191
+ $buttons = [];
192
  }
193
 
194
  $this->editors_with_buttons[] = $editor_id;
240
  * @return array $select items for select field.
241
  */
242
  public static function items_for_select() {
243
+ $select = [];
244
  $model = Advanced_Ads::get_instance()->get_model();
245
 
246
  // load all ads.
247
  $ads = $model->get_ads(
248
+ [
249
  'orderby' => 'title',
250
  'order' => 'ASC',
251
+ ]
252
  );
253
  foreach ( $ads as $_ad ) {
254
  $select['ads'][ 'ad_' . $_ad->ID ] = $_ad->post_title;
admin/includes/notices.php CHANGED
@@ -4,43 +4,43 @@
4
  */
5
  $advanced_ads_admin_notices = apply_filters(
6
  'advanced-ads-notices',
7
- array(
8
  // email tutorial.
9
- 'nl_intro' => array(
10
  'type' => 'info',
11
  'text' => Advanced_Ads_Admin_Notices::get_instance()->get_welcome_panel(),
12
  'global' => true,
13
- ),
14
  // email tutorial.
15
- 'nl_first_steps' => array(
16
  'type' => 'subscribe',
17
  'text' => __( 'Thank you for activating <strong>Advanced Ads</strong>. Would you like to receive the first steps via email?', 'advanced-ads' ),
18
  'confirm_text' => __( 'Yes, send it', 'advanced-ads' ),
19
  'global' => true,
20
- ),
21
  // free add-ons.
22
- 'nl_free_addons' => array(
23
  'type' => 'subscribe',
24
  'text' => __( 'Thank you for using <strong>Advanced Ads</strong>. Stay informed and receive <strong>2 free add-ons</strong> for joining the newsletter.', 'advanced-ads' ),
25
  'confirm_text' => __( 'Add me now', 'advanced-ads' ),
26
  'global' => true,
27
- ),
28
  // adsense newsletter group.
29
- 'nl_adsense' => array(
30
  'type' => 'subscribe',
31
  'text' => __( 'Learn more about how and <strong>how much you can earn with AdSense</strong> and Advanced Ads from my dedicated newsletter.', 'advanced-ads' ),
32
  'confirm_text' => __( 'Subscribe me now', 'advanced-ads' ),
33
  'global' => true,
34
- ),
35
  // missing license codes.
36
- 'license_invalid' => array(
37
  'type' => 'plugin_error',
38
  'text' => __( 'One or more license keys for <strong>Advanced Ads add-ons are invalid or missing</strong>.', 'advanced-ads' ) . ' '
39
  // translators: %s is a URL.
40
  . sprintf( __( 'Please add valid license keys <a href="%s">here</a>.', 'advanced-ads' ), get_admin_url( null, 'admin.php?page=advanced-ads-settings#top#licenses' ) ),
41
- ),
42
  // please review.
43
- 'review' => array(
44
  'type' => 'info',
45
  // 'text' => '<img src="' . ADVADS_BASE_URL . 'admin/assets/img/thomas.png" alt="Thomas" width="80" height="115" class="advads-review-image"/>'
46
  'text' => '<div style="float: left; font-size: 4em; line-height: 1em; margin-right: 0.5em;">' . Advanced_Ads::get_number_of_ads() . '</div>'
@@ -55,9 +55,9 @@ $advanced_ads_admin_notices = apply_filters(
55
  . ' &nbsp;&nbsp;<span class="dashicons dashicons-sos"></span>&nbsp;<a href="' . ADVADS_URL . 'support/?utm_source=advanced-ads&utm_medium=link&utm_campaign=notice-review" target=_"blank">' . __( 'Yes, but help me first to solve a problem, please', 'advanced-ads' ) . '</a>'
56
  . '</p></div>',
57
  'global' => false,
58
- ),
59
  // Black Friday 2022 promotion.
60
- 'bfcm22' => array(
61
  'type' => 'promo',
62
  'text' => sprintf(
63
  /* translators: %1$s is the markup for the discount value, %2$s starts a button link, %3$s closes the button link. */
@@ -67,7 +67,7 @@ $advanced_ads_admin_notices = apply_filters(
67
  '</a>'
68
  ),
69
  'global' => true,
70
- ),
71
- )
72
  );
73
 
4
  */
5
  $advanced_ads_admin_notices = apply_filters(
6
  'advanced-ads-notices',
7
+ [
8
  // email tutorial.
9
+ 'nl_intro' => [
10
  'type' => 'info',
11
  'text' => Advanced_Ads_Admin_Notices::get_instance()->get_welcome_panel(),
12
  'global' => true,
13
+ ],
14
  // email tutorial.
15
+ 'nl_first_steps' => [
16
  'type' => 'subscribe',
17
  'text' => __( 'Thank you for activating <strong>Advanced Ads</strong>. Would you like to receive the first steps via email?', 'advanced-ads' ),
18
  'confirm_text' => __( 'Yes, send it', 'advanced-ads' ),
19
  'global' => true,
20
+ ],
21
  // free add-ons.
22
+ 'nl_free_addons' => [
23
  'type' => 'subscribe',
24
  'text' => __( 'Thank you for using <strong>Advanced Ads</strong>. Stay informed and receive <strong>2 free add-ons</strong> for joining the newsletter.', 'advanced-ads' ),
25
  'confirm_text' => __( 'Add me now', 'advanced-ads' ),
26
  'global' => true,
27
+ ],
28
  // adsense newsletter group.
29
+ 'nl_adsense' => [
30
  'type' => 'subscribe',
31
  'text' => __( 'Learn more about how and <strong>how much you can earn with AdSense</strong> and Advanced Ads from my dedicated newsletter.', 'advanced-ads' ),
32
  'confirm_text' => __( 'Subscribe me now', 'advanced-ads' ),
33
  'global' => true,
34
+ ],
35
  // missing license codes.
36
+ 'license_invalid' => [
37
  'type' => 'plugin_error',
38
  'text' => __( 'One or more license keys for <strong>Advanced Ads add-ons are invalid or missing</strong>.', 'advanced-ads' ) . ' '
39
  // translators: %s is a URL.
40
  . sprintf( __( 'Please add valid license keys <a href="%s">here</a>.', 'advanced-ads' ), get_admin_url( null, 'admin.php?page=advanced-ads-settings#top#licenses' ) ),
41
+ ],
42
  // please review.
43
+ 'review' => [
44
  'type' => 'info',
45
  // 'text' => '<img src="' . ADVADS_BASE_URL . 'admin/assets/img/thomas.png" alt="Thomas" width="80" height="115" class="advads-review-image"/>'
46
  'text' => '<div style="float: left; font-size: 4em; line-height: 1em; margin-right: 0.5em;">' . Advanced_Ads::get_number_of_ads() . '</div>'
55
  . ' &nbsp;&nbsp;<span class="dashicons dashicons-sos"></span>&nbsp;<a href="' . ADVADS_URL . 'support/?utm_source=advanced-ads&utm_medium=link&utm_campaign=notice-review" target=_"blank">' . __( 'Yes, but help me first to solve a problem, please', 'advanced-ads' ) . '</a>'
56
  . '</p></div>',
57
  'global' => false,
58
+ ],
59
  // Black Friday 2022 promotion.
60
+ 'bfcm22' => [
61
  'type' => 'promo',
62
  'text' => sprintf(
63
  /* translators: %1$s is the markup for the discount value, %2$s starts a button link, %3$s closes the button link. */
67
  '</a>'
68
  ),
69
  'global' => true,
70
+ ],
71
+ ]
72
  );
73
 
admin/includes/shortcode-creator-l10n.php CHANGED
@@ -13,12 +13,12 @@ if ( ! class_exists( '_WP_Editors' ) ) {
13
  * @return string
14
  */
15
  function advads_shortcode_creator_l10n() {
16
- $strings = array(
17
  'title' => _x( 'Add an ad', 'shortcode creator', 'advanced-ads' ),
18
  'ok' => _x( 'Add shortcode', 'shortcode creator', 'advanced-ads' ),
19
  'cancel' => _x( 'Cancel', 'shortcode creator', 'advanced-ads' ),
20
  'image' => ADVADS_BASE_URL . 'admin/assets/img/tinymce-icon.png',
21
- );
22
  $locale = _WP_Editors::get_mce_locale();
23
  $translated = 'tinyMCE.addI18n("' . $locale . '.advads_shortcode", ' . wp_json_encode( $strings ) . ");\n";
24
 
13
  * @return string
14
  */
15
  function advads_shortcode_creator_l10n() {
16
+ $strings = [
17
  'title' => _x( 'Add an ad', 'shortcode creator', 'advanced-ads' ),
18
  'ok' => _x( 'Add shortcode', 'shortcode creator', 'advanced-ads' ),
19
  'cancel' => _x( 'Cancel', 'shortcode creator', 'advanced-ads' ),
20
  'image' => ADVADS_BASE_URL . 'admin/assets/img/tinymce-icon.png',
21
+ ];
22
  $locale = _WP_Editors::get_mce_locale();
23
  $translated = 'tinyMCE.addI18n("' . $locale . '.advads_shortcode", ' . wp_json_encode( $strings ) . ");\n";
24
 
admin/views/ad-group-list-form-row.php CHANGED
@@ -8,95 +8,90 @@
8
  * @link https://wpadvancedads.com
9
  * @copyright since 2013 Thomas Maier, Advanced Ads GmbH
10
  *
11
- * @var Advanced_Ads_Group $group Ad group object.
12
- * @var array $ad_form_rows Array with HTML for ad form.
13
- * @var string $hints_html Hints markup.
 
14
  */
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- // Open form if this was the last edited.
17
- $is_last_edited = isset( $_REQUEST['advads-last-edited-group'] ) && $group->id == $_REQUEST['advads-last-edited-group'];
18
- $hidden = $is_last_edited ? '' : ' hidden';
19
- ?><tr id="advads-ad-group-<?php echo absint( $group->id ); ?>" class="advads-ad-group-form<?php echo esc_attr( $hidden ); ?>" <?php echo $is_last_edited ? 'data-touched="true"' : ''; ?>>
20
- <td colspan="3">
21
 
 
 
 
 
 
 
 
 
22
  <?php
23
- // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- the output is already escaped
24
- echo $hints_html;
25
-
26
- // group name.
27
- ob_start();
28
  ?>
29
- <input type="hidden" class="advads-group-id" name="advads-groups[<?php echo absint( $group->id ); ?>][id]" value="<?php echo absint( $group->id ); ?>"/>
30
- <input type="text" name="advads-groups[<?php echo absint( $group->id ); ?>][name]" value="<?php echo esc_attr( $group->name ); ?>"/>
 
31
  <?php
32
- $option_content = ob_get_clean();
 
 
 
 
33
 
34
- Advanced_Ads_Admin_Options::render_option(
35
- 'group-name static',
36
- __( 'Name', 'advanced-ads' ),
37
- $option_content
38
- );
39
 
40
- // group type.
41
- ob_start();
 
 
 
 
 
42
  ?>
43
- <div class="advads-ad-group-type">
44
  <?php
45
- foreach ( $this->types as $_type_key => $_type ) :
46
- ?>
47
- <label title="<?php echo esc_html( $_type['description'] ); ?>"><input type="radio" name="advads-groups[<?php echo absint( $group->id ); ?>][type]" value="<?php echo esc_attr( $_type_key ); ?>" <?php checked( $group->type, $_type_key ); ?>/>
48
- <?php
49
- echo esc_html( $_type['title'] );
50
- ?>
51
- </label>
52
- <?php
53
- endforeach;
54
- ?>
55
- </div>
56
  <?php
57
  $option_content = ob_get_clean();
58
 
59
  Advanced_Ads_Admin_Options::render_option(
60
- 'group-type static',
61
- esc_attr__( 'Type', 'advanced-ads' ),
62
- $option_content
 
63
  );
64
 
65
- // group number.
 
66
  ob_start();
 
 
 
 
 
 
 
67
  ?>
68
- <select name="advads-groups[<?php echo absint( $group->id ); ?>][ad_count]">
69
- <?php
70
- $max = ( count( $ad_form_rows ) >= 10 ) ? count( $ad_form_rows ) + 2 : 10;
71
- for ( $i = 1; $i <= $max; $i++ ) :
72
- ?>
73
- <option <?php selected( $group->ad_count, $i ); ?>><?php echo absint( $i ); ?></option>
74
- <?php
75
- endfor;
76
- ?>
77
- <option <?php selected( $group->ad_count, 'all' ); ?> value="all"><?php echo esc_attr_x( 'all', 'option to display all ads in an ad groups', 'advanced-ads' ); ?></option>
78
- </select>
79
- <?php
80
- $option_content = ob_get_clean();
81
-
82
- Advanced_Ads_Admin_Options::render_option(
83
- 'group-number advads-group-type-default advads-group-type-ordered',
84
- esc_attr__( 'Visible ads', 'advanced-ads' ),
85
- $option_content,
86
- esc_attr__( 'Number of ads that are visible at the same time', 'advanced-ads' )
87
- );
88
-
89
- do_action( 'advanced-ads-group-form-options', $group );
90
-
91
- ob_start();
92
- require ADVADS_BASE_PATH . 'admin/views/ad-group-list-ads.php';
93
- $option_content = ob_get_clean();
94
- Advanced_Ads_Admin_Options::render_option(
95
- 'group-ads static',
96
- esc_attr__( 'Ads', 'advanced-ads' ),
97
- $option_content
98
- );
99
-
100
- ?>
101
- </td>
102
- </tr>
8
  * @link https://wpadvancedads.com
9
  * @copyright since 2013 Thomas Maier, Advanced Ads GmbH
10
  *
11
+ * @var Advanced_Ads_Group $group Ad group object.
12
+ * @var array $ad_form_rows Array with HTML for ad form.
13
+ * @var string $hints_html Hints markup.
14
+ * @var string $missing_type_error Contains an error message if the group type is missing.
15
  */
16
+ ?>
17
+ <div class="advads-ad-group-form">
18
+ <?php
19
+ // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- the output is already escaped
20
+ echo $hints_html;
21
+ ob_start();
22
+ ?>
23
+ <input type="hidden" class="advads-group-id" name="advads-groups[<?php echo absint( $group->id ); ?>][id]" value="<?php echo absint( $group->id ); ?>"/>
24
+ <input type="text" name="advads-groups[<?php echo absint( $group->id ); ?>][name]" value="<?php echo esc_attr( $group->name ); ?>"/>
25
+ <?php
26
+ $option_content = ob_get_clean();
27
 
28
+ Advanced_Ads_Admin_Options::render_option(
29
+ 'group-name static',
30
+ __( 'Name', 'advanced-ads' ),
31
+ $option_content
32
+ );
33
 
34
+ // group type.
35
+ ob_start();
36
+ ?>
37
+ <div class="advads-ad-group-type">
38
+ <?php
39
+ if ( $missing_type_error ) :
40
+ ?>
41
+ <p class="advads-notice-inline advads-error"><?php echo esc_html( $missing_type_error ); ?></p>
42
  <?php
43
+ endif;
44
+ foreach ( $this->types as $_type_key => $_type ) :
 
 
 
45
  ?>
46
+ <label title="<?php echo esc_html( $_type['description'] ); ?>"><input type="radio" name="advads-groups[<?php echo absint( $group->id ); ?>][type]" value="<?php echo esc_attr( $_type_key ); ?>" <?php checked( $group->type, $_type_key ); ?>/>
47
+ <?php echo esc_html( $_type['title'] ); ?>
48
+ </label>
49
  <?php
50
+ endforeach;
51
+ ?>
52
+ </div>
53
+ <?php
54
+ $option_content = ob_get_clean();
55
 
56
+ Advanced_Ads_Admin_Options::render_option(
57
+ 'group-type static',
58
+ esc_attr__( 'Type', 'advanced-ads' ),
59
+ $option_content
60
+ );
61
 
62
+ // group number.
63
+ ob_start();
64
+ ?>
65
+ <select name="advads-groups[<?php echo absint( $group->id ); ?>][ad_count]">
66
+ <?php
67
+ $max = ( count( $ad_form_rows ) >= 10 ) ? count( $ad_form_rows ) + 2 : 10;
68
+ for ( $i = 1; $i <= $max; $i++ ) :
69
  ?>
70
+ <option <?php selected( $group->ad_count, $i ); ?>><?php echo absint( $i ); ?></option>
71
  <?php
72
+ endfor;
73
+ ?>
74
+ <option <?php selected( $group->ad_count, 'all' ); ?> value="all"><?php echo esc_attr_x( 'all', 'option to display all ads in an ad groups', 'advanced-ads' ); ?></option>
75
+ </select>
 
 
 
 
 
 
 
76
  <?php
77
  $option_content = ob_get_clean();
78
 
79
  Advanced_Ads_Admin_Options::render_option(
80
+ 'group-number advads-group-type-default advads-group-type-ordered',
81
+ esc_attr__( 'Visible ads', 'advanced-ads' ),
82
+ $option_content,
83
+ esc_attr__( 'Number of ads that are visible at the same time', 'advanced-ads' )
84
  );
85
 
86
+ do_action( 'advanced-ads-group-form-options', $group );
87
+
88
  ob_start();
89
+ require ADVADS_BASE_PATH . 'admin/views/ad-group-list-ads.php';
90
+ $option_content = ob_get_clean();
91
+ Advanced_Ads_Admin_Options::render_option(
92
+ 'group-ads static',
93
+ esc_attr__( 'Ads', 'advanced-ads' ),
94
+ $option_content
95
+ );
96
  ?>
97
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/views/ad-group-list-header.php CHANGED
@@ -8,10 +8,10 @@
8
  * @link https://wpadvancedads.com
9
  * @copyright since 2013 Thomas Maier, Advanced Ads GmbH
10
  */
11
-
12
  ?><thead>
13
  <tr>
14
- <th><?php esc_attr_e( 'Ad Group', 'advanced-ads' ); ?></th>
 
15
  <th><?php esc_attr_e( 'Details', 'advanced-ads' ); ?></th>
16
  <th><?php esc_attr_e( 'Ads', 'advanced-ads' ); ?></th>
17
  </tr>
8
  * @link https://wpadvancedads.com
9
  * @copyright since 2013 Thomas Maier, Advanced Ads GmbH
10
  */
 
11
  ?><thead>
12
  <tr>
13
+ <th class="column-group-type"><?php esc_html_e( 'Type', 'advanced-ads' ); ?></th>
14
+ <th><?php esc_attr_e( 'Name', 'advanced-ads' ); ?></th>
15
  <th><?php esc_attr_e( 'Details', 'advanced-ads' ); ?></th>
16
  <th><?php esc_attr_e( 'Ads', 'advanced-ads' ); ?></th>
17
  </tr>
admin/views/ad-group-list-row.php CHANGED
@@ -8,46 +8,75 @@
8
  * @link https://wpadvancedads.com
9
  * @copyright since 2013 Thomas Maier, Advanced Ads GmbH
10
  *
11
- * @var Advanced_Ads_Group $group Ad group object.
12
- * @var Advanced_Ads_Groups_List $this Groups list table object.
13
- * @var string $hints_html Hints markup.
 
 
14
  */
15
  ?><tr class="advads-group-row">
 
 
 
 
 
 
 
 
 
 
16
  <td>
17
- <strong><a class="row-title" href="#"><?php echo esc_html( $group->name ); ?></a></strong>
 
 
18
  <?php
19
  // escaping done by the function.
20
  // phpcs:ignore
21
- echo $this->render_action_links( $group ); ?>
22
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- <?php
25
  $modal_slug = esc_attr( $group->id . '-usage' );
26
  ob_start();
27
-
28
  // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- the output is already escaped
29
  echo $hints_html;
30
  ?>
31
  <div class="advads-usage">
32
- <h2><?php esc_attr_e( 'shortcode', 'advanced-ads' ); ?></h2>
33
  <code><input type="text" onclick="this.select();" value='[the_ad_group id="<?php echo absint( $group->id ); ?>"]' readonly /></code>
34
  <h2><?php esc_html_e( 'template (PHP)', 'advanced-ads' ); ?></h2>
35
  <code><input type="text" onclick="this.select();" value="the_ad_group(<?php echo absint( $group->id ); ?>);" readonly /></code>
36
  </div>
37
  <?php
38
  $modal_content = ob_get_clean();
39
- $modal_title = esc_html__( 'Usage', 'advanced-ads' );
40
- include ADVADS_BASE_PATH . 'admin/views/modal.php';
 
 
 
 
 
 
 
41
  ?>
42
  </td>
43
  <td>
44
- <ul><?php $_type = isset( $this->types[ $group->type ]['title'] ) ? $this->types[ $group->type ]['title'] : 'default'; ?>
45
  <li><strong>
46
  <?php
47
  /*
48
  * translators: %s is the name of a group type
49
  */
50
- printf( esc_html__( 'Type: %s', 'advanced-ads' ), esc_html( $_type ) );
51
  ?>
52
  </strong></li>
53
  <li>
8
  * @link https://wpadvancedads.com
9
  * @copyright since 2013 Thomas Maier, Advanced Ads GmbH
10
  *
11
+ * @var Advanced_Ads_Group $group Ad group object.
12
+ * @var Advanced_Ads_Groups_List $this Groups list table object.
13
+ * @var string $hints_html Hints markup.
14
+ * @var string $type_name Group type name.
15
+ * @var string $missing_type_error Contains an error message if the group type is missing.
16
  */
17
  ?><tr class="advads-group-row">
18
+ <td class="column-group-type">
19
+ <div class="advads-form-type">
20
+ <?php if ( ! $missing_type_error ) : ?>
21
+ <img src="<?php echo esc_url( $this->types[ $group->type ]['image'] ); ?>" alt="<?php echo esc_attr( $type_name ); ?>">
22
+ <?php endif; ?>
23
+ <p class="advads-form-description">
24
+ <strong><?php echo esc_html( $type_name ); ?></strong>
25
+ </p>
26
+ </div>
27
+ </td>
28
  <td>
29
+ <div class="advads-table-name">
30
+ <a class="row-title" href="#modal-group-edit-<?php echo absint( $group->id ); ?>"><?php echo esc_html( $group->name ); ?></a>
31
+ </div>
32
  <?php
33
  // escaping done by the function.
34
  // phpcs:ignore
35
+ echo $this->render_action_links( $group );
36
 
37
+ // edit form modal
38
+ $modal_slug = 'group-edit-' . $group->id;
39
+ ob_start();
40
+ require ADVADS_BASE_PATH . 'admin/views/ad-group-list-form-row.php';
41
+ $modal_content = ob_get_clean();
42
+ $modal_title = esc_html__( 'Edit', 'advanced-ads' ) . ' ' . $group->name;
43
+ $close_action = esc_html__( 'Save', 'advanced-ads' ) . ' ' . $group->name;
44
+ $close_form = 'advads-form-groups';
45
+ $close_validation = 'advads_group_edit_submit';
46
+ require ADVADS_BASE_PATH . 'admin/views/modal.php';
47
 
 
48
  $modal_slug = esc_attr( $group->id . '-usage' );
49
  ob_start();
 
50
  // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- the output is already escaped
51
  echo $hints_html;
52
  ?>
53
  <div class="advads-usage">
54
+ <h2><?php esc_html_e( 'shortcode', 'advanced-ads' ); ?></h2>
55
  <code><input type="text" onclick="this.select();" value='[the_ad_group id="<?php echo absint( $group->id ); ?>"]' readonly /></code>
56
  <h2><?php esc_html_e( 'template (PHP)', 'advanced-ads' ); ?></h2>
57
  <code><input type="text" onclick="this.select();" value="the_ad_group(<?php echo absint( $group->id ); ?>);" readonly /></code>
58
  </div>
59
  <?php
60
  $modal_content = ob_get_clean();
61
+ $modal_title = esc_html__( 'Usage', 'advanced-ads' );
62
+ $close_action = '';
63
+ require ADVADS_BASE_PATH . 'admin/views/modal.php';
64
+
65
+ if ( $missing_type_error ) :
66
+ ?>
67
+ <p class="advads-notice-inline advads-error"><?php echo esc_html( $missing_type_error ); ?></p>
68
+ <?php
69
+ endif;
70
  ?>
71
  </td>
72
  <td>
73
+ <ul>
74
  <li><strong>
75
  <?php
76
  /*
77
  * translators: %s is the name of a group type
78
  */
79
+ printf( esc_html__( 'Type: %s', 'advanced-ads' ), esc_html( $type_name ) );
80
  ?>
81
  </strong></li>
82
  <li>
admin/views/ad-group.php CHANGED
@@ -10,11 +10,11 @@
10
  *
11
  * @var WP_List_Table|false $wp_list_table the groups list table
12
  * @var WP_Taxonomy $tax ad group taxonomy
 
 
 
13
  * @var bool $is_search true if a group is searched.
14
  */
15
-
16
- $ad_groups_list = new Advanced_Ads_Groups_List();
17
-
18
  ?>
19
  <div class="wrap">
20
  <?php
@@ -26,9 +26,9 @@ if ( isset( $_REQUEST['advads-group-add-nonce'] ) ) {
26
  // potential error comes from WP_Error and is no user input.
27
  // phpcs:ignore
28
  $error_string = $create_result->get_error_message();
29
- echo '<div id="message" class="error inline"><p>' . esc_html( $error_string ) . '</p></div>';
30
  } else {
31
- echo '<div id="message" class="updated inline"><p>' . esc_html__( 'Ad Group successfully created', 'advanced-ads' ) . '</p></div>';
32
  }
33
  }
34
  // save updated groups.
@@ -46,39 +46,32 @@ if ( isset( $_REQUEST['advads-group-update-nonce'] ) ) {
46
  }
47
  ?>
48
  </div>
49
- <?php
50
-
51
- $last_edited_group_id = 0;
52
- if ( isset( $_REQUEST['advads-last-edited-group'] ) ) {
53
- $last_edited_group_id = $_REQUEST['advads-last-edited-group'];
54
- ?>
55
- <script>
56
- var body = document.getElementsByTagName("body")[0];
57
- body.addEventListener("load", function(){
58
- jQuery('#advads-ad-group-<?php echo esc_attr( $last_edited_group_id ); ?>').get(0).scrollIntoView(false);
59
- }, true);
60
- </script>
61
- <?php
62
- }
63
-
64
- ?>
65
  <div class="wrap nosubsub">
66
  <h2 style="display: none;"><!-- There needs to be an empty H2 headline at the top of the page so that WordPress can properly position admin notifications --></h2>
67
- <form id="advads-new-group-form" action="" method="post" style="display:none;">
68
- <?php wp_nonce_field( 'add-advads-groups', 'advads-group-add-nonce' ); ?>
69
- <input type="text" name="advads-group-name" placeholder="<?php esc_attr_e( 'Group title', 'advanced-ads' ); ?>"/>
70
- <input class="button button-primary" type="submit" value="<?php esc_attr_e( 'save', 'advanced-ads' ); ?>"/>
71
- </form>
72
  <p>
73
  <?php
74
  esc_attr_e( 'Ad Groups are a very flexible method to bundle ads. You can use them to display random ads in the frontend or run split tests, but also just for informational purposes. Not only can an Ad Groups have multiple ads, but an ad can belong to multiple ad groups.', 'advanced-ads' );
75
  ?>
76
- <a href="<?php echo esc_url( ADVADS_URL ) . 'manual/ad-groups/?utm_source=advanced-ads&utm_medium=link&utm_campaign=groups'; ?>" target="_blank" class="advads-manual-link"><?php esc_html_e( 'Manual', 'advanced-ads' ); ?></a>
77
  </p>
 
 
 
 
 
 
 
 
 
 
78
  <?php if ( isset( $message ) ) : ?>
79
  <div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
80
  <?php
81
- $_SERVER['REQUEST_URI'] = esc_url( remove_query_arg( array( 'message' ), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
82
  endif;
83
  ?>
84
  <div id="ajax-response"></div>
@@ -99,18 +92,31 @@ if ( isset( $_REQUEST['advads-last-edited-group'] ) ) {
99
  </form>
100
  </div>
101
  <div id="advads-ad-group-list">
102
- <form action="" method="post" id="advads-form-groups">
103
  <?php wp_nonce_field( 'update-advads-groups', 'advads-group-update-nonce' ); ?>
104
- <table class="wp-list-table widefat fixed adgroups">
105
  <?php $ad_groups_list->render_header(); ?>
106
- <?php $ad_groups_list->render_rows(); ?>
 
 
 
 
 
 
 
 
107
  </table>
108
- <input type="hidden" name="advads-last-edited-group" id="advads-last-edited-group" value="<?php echo esc_attr( $last_edited_group_id ); ?>"/>
109
- <div class="tablenav bottom">
110
- <?php submit_button( __( 'Update Groups', 'advanced-ads' ) ); ?>
111
- </div>
112
  </form>
113
  </div>
114
  </div>
115
  </div>
116
  </div>
 
 
 
 
 
 
 
 
 
10
  *
11
  * @var WP_List_Table|false $wp_list_table the groups list table
12
  * @var WP_Taxonomy $tax ad group taxonomy
13
+ * @var Advanced_Ads_Groups_List $ad_groups_list
14
+ * @var array[] $group_types
15
+ * @var array[] $group_types_premium
16
  * @var bool $is_search true if a group is searched.
17
  */
 
 
 
18
  ?>
19
  <div class="wrap">
20
  <?php
26
  // potential error comes from WP_Error and is no user input.
27
  // phpcs:ignore
28
  $error_string = $create_result->get_error_message();
29
+ echo '<div class="notice error inline"><p>' . esc_html( $error_string ) . '</p></div>';
30
  } else {
31
+ echo '<div class="notice inline"><p>' . esc_html__( 'Ad Group successfully created', 'advanced-ads' ) . '</p></div>';
32
  }
33
  }
34
  // save updated groups.
46
  }
47
  ?>
48
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  <div class="wrap nosubsub">
50
  <h2 style="display: none;"><!-- There needs to be an empty H2 headline at the top of the page so that WordPress can properly position admin notifications --></h2>
51
+ <?php
52
+ $modal_slug = 'group-new';
53
+ ob_start();
54
+ ?>
 
55
  <p>
56
  <?php
57
  esc_attr_e( 'Ad Groups are a very flexible method to bundle ads. You can use them to display random ads in the frontend or run split tests, but also just for informational purposes. Not only can an Ad Groups have multiple ads, but an ad can belong to multiple ad groups.', 'advanced-ads' );
58
  ?>
59
+ <a href="<?php echo esc_url( ADVADS_URL ) . 'manual/ad-groups/?utm_source=advanced-ads&utm_medium=link&utm_campaign=groups'; ?>" target="_blank" class="advads-manual-link"><?php esc_html_e( 'Manual', 'advanced-ads' ); ?></a>
60
  </p>
61
+ <?php
62
+ require ADVADS_BASE_PATH . 'admin/views/group-form.php';
63
+ $modal_content = ob_get_clean();
64
+ $modal_title = esc_html__( 'New Ad Group', 'advanced-ads' );
65
+ $close_action = esc_html__( 'Save New Group', 'advanced-ads' );
66
+ $close_form = 'advads-group-new-form';
67
+ $close_validation = 'advads_validate_new_form';
68
+ $modal_path = ADVADS_BASE_PATH . 'admin/views/modal.php';
69
+ include $modal_path;
70
+ ?>
71
  <?php if ( isset( $message ) ) : ?>
72
  <div id="message" class="updated"><p><?php echo esc_html( $message ); ?></p></div>
73
  <?php
74
+ $_SERVER['REQUEST_URI'] = esc_url( remove_query_arg( [ 'message' ], wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
75
  endif;
76
  ?>
77
  <div id="ajax-response"></div>
92
  </form>
93
  </div>
94
  <div id="advads-ad-group-list">
95
+ <form action="" method="post" id="advads-form-groups" class="advads-form-groups">
96
  <?php wp_nonce_field( 'update-advads-groups', 'advads-group-update-nonce' ); ?>
97
+ <table class="wp-list-table widefat fixed advads-table">
98
  <?php $ad_groups_list->render_header(); ?>
99
+ <?php
100
+ if ( count( $ad_groups_list->groups ) ) :
101
+ $ad_groups_list->render_rows();
102
+ else :
103
+ ?>
104
+ <tr class="advads-group-row"><td colspan="4"><?php esc_html_e( 'No Ad Group found', 'advanced-ads' ); ?></td><tr>
105
+ <?php
106
+ endif;
107
+ ?>
108
  </table>
 
 
 
 
109
  </form>
110
  </div>
111
  </div>
112
  </div>
113
  </div>
114
+ <?php
115
+ // trigger the group form when no groups exist and we are not currently searching
116
+ if ( ! count( $ad_groups_list->groups ) && ! $is_search ) :
117
+ ?>
118
+ <script>
119
+ window.location.hash = '#modal-<?php echo esc_html( $modal_slug ); ?>';
120
+ </script>
121
+ <?php
122
+ endif;
admin/views/ad-info-after-textarea.php CHANGED
@@ -22,11 +22,11 @@ if ( defined( 'WP_DEBUG' ) && WP_DEBUG &&
22
  wp_kses(
23
  // translators: %s is a URL.
24
  __( 'Reach out to <a href="%s">support</a> to get help.', 'advanced-ads' ),
25
- array(
26
- 'a' => array(
27
- 'href' => array(),
28
- ),
29
- )
30
  ),
31
  esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#support' ) )
32
  );
22
  wp_kses(
23
  // translators: %s is a URL.
24
  __( 'Reach out to <a href="%s">support</a> to get help.', 'advanced-ads' ),
25
+ [
26
+ 'a' => [
27
+ 'href' => [],
28
+ ],
29
+ ]
30
  ),
31
  esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#support' ) )
32
  );
admin/views/ad-list/timing.php CHANGED
@@ -68,9 +68,9 @@
68
  wp_kses(
69
  // translators: %s is a time and date string.
70
  __( '<strong>expired</strong> %s', 'advanced-ads' ),
71
- array(
72
- 'strong' => array(),
73
- )
74
  ),
75
  esc_html( $expiry_date_string )
76
  );
68
  wp_kses(
69
  // translators: %s is a time and date string.
70
  __( '<strong>expired</strong> %s', 'advanced-ads' ),
71
+ [
72
+ 'strong' => [],
73
+ ]
74
  ),
75
  esc_html( $expiry_date_string )
76
  );
admin/views/ad-list/view-list.php CHANGED
@@ -10,10 +10,10 @@
10
  <?php foreach ( $views_new as $class => $view ) : ?>
11
  <li class="button <?php echo esc_attr( $class ); ?>">
12
  <?php
13
- echo wp_kses( $view, array(
14
- 'a' => array( 'href' => array() ),
15
- 'span' => array( 'class' => array() ),
16
- ) );
17
  ?>
18
  </li>
19
  <?php endforeach; ?>
10
  <?php foreach ( $views_new as $class => $view ) : ?>
11
  <li class="button <?php echo esc_attr( $class ); ?>">
12
  <?php
13
+ echo wp_kses( $view, [
14
+ 'a' => [ 'href' => [] ],
15
+ 'span' => [ 'class' => [] ],
16
+ ] );
17
  ?>
18
  </li>
19
  <?php endforeach; ?>
admin/views/ad-parameters-metabox.php CHANGED
@@ -11,11 +11,11 @@ do_action( 'advanced-ads-ad-params-before', $ad, $types );
11
  ?>
12
  <div id="advanced-ads-tinymce-wrapper" style="display:none;">
13
  <?php
14
- $args = array(
15
  // used here instead of textarea_rows, because of display:none.
16
  'editor_height' => 300,
17
  'drag_drop_upload' => true,
18
- );
19
  wp_editor( '', 'advanced-ads-tinymce', $args );
20
  ?>
21
  </div>
@@ -24,7 +24,7 @@ do_action( 'advanced-ads-ad-params-before', $ad, $types );
24
  $type = ( isset( $types[ $ad->type ] ) ) ? $types[ $ad->type ] : current( $types );
25
  $type->render_parameters( $ad );
26
 
27
- $types_without_size = array( 'dummy' );
28
  $types_without_size = apply_filters( 'advanced-ads-types-without-size', $types_without_size );
29
  // todo: manage which ad types have a size in the ad type definition.
30
  if ( ! in_array( $ad->type, $types_without_size ) ) {
11
  ?>
12
  <div id="advanced-ads-tinymce-wrapper" style="display:none;">
13
  <?php
14
+ $args = [
15
  // used here instead of textarea_rows, because of display:none.
16
  'editor_height' => 300,
17
  'drag_drop_upload' => true,
18
+ ];
19
  wp_editor( '', 'advanced-ads-tinymce', $args );
20
  ?>
21
  </div>
24
  $type = ( isset( $types[ $ad->type ] ) ) ? $types[ $ad->type ] : current( $types );
25
  $type->render_parameters( $ad );
26
 
27
+ $types_without_size = [ 'dummy' ];
28
  $types_without_size = apply_filters( 'advanced-ads-types-without-size', $types_without_size );
29
  // todo: manage which ad types have a size in the ad type definition.
30
  if ( ! in_array( $ad->type, $types_without_size ) ) {
admin/views/ad-parameters-size.php CHANGED
@@ -11,7 +11,7 @@ if ( 'gam' === $type->ID ) {
11
  <label><?php esc_html_e( 'width', 'advanced-ads' ); ?><input type="number" value="<?php echo isset( $ad->width ) ? esc_attr( $ad->width ) : 0; ?>" name="advanced_ad[width]">px</label>
12
  <label><?php esc_html_e( 'height', 'advanced-ads' ); ?><input type="number" value="<?php echo isset( $ad->height ) ? esc_attr( $ad->height ) : 0; ?>" name="advanced_ad[height]">px</label>
13
  <?php
14
- $show_reserve_space = in_array( $type->ID, array( 'plain', 'content', 'group', 'adsense' ), true );
15
  $enable_reserve_space = $show_reserve_space && ! empty( $ad->output['add_wrapper_sizes'] );
16
  ?>
17
  <label
11
  <label><?php esc_html_e( 'width', 'advanced-ads' ); ?><input type="number" value="<?php echo isset( $ad->width ) ? esc_attr( $ad->width ) : 0; ?>" name="advanced_ad[width]">px</label>
12
  <label><?php esc_html_e( 'height', 'advanced-ads' ); ?><input type="number" value="<?php echo isset( $ad->height ) ? esc_attr( $ad->height ) : 0; ?>" name="advanced_ad[height]">px</label>
13
  <?php
14
+ $show_reserve_space = in_array( $type->ID, [ 'plain', 'content', 'group', 'adsense' ], true );
15
  $enable_reserve_space = $show_reserve_space && ! empty( $ad->output['add_wrapper_sizes'] );
16
  ?>
17
  <label
admin/views/checks.php CHANGED
@@ -5,7 +5,7 @@
5
  * listed on support and settings page
6
  */
7
 
8
- $messages = array();
9
 
10
  if ( Advanced_Ads_Ad_Health_Notices::has_visible_problems() ) {
11
  $messages[] = sprintf(
5
  * listed on support and settings page
6
  */
7
 
8
+ $messages = [];
9
 
10
  if ( Advanced_Ads_Ad_Health_Notices::has_visible_problems() ) {
11
  $messages[] = sprintf(
admin/views/conditions/ad-display-metabox.php CHANGED
@@ -26,7 +26,7 @@ if ( $empty_options ) :
26
  <?php
27
  // display help when no conditions are given.
28
  if ( $empty_options ) :
29
- $set_conditions = array();
30
  ?>
31
  <p>
32
  <button type="button" class="advads-video-link-inline button button-primary">
26
  <?php
27
  // display help when no conditions are given.
28
  if ( $empty_options ) :
29
+ $set_conditions = [];
30
  ?>
31
  <p>
32
  <button type="button" class="advads-video-link-inline button button-primary">
admin/views/conditions/ad-visitor-metabox.php CHANGED
@@ -29,7 +29,7 @@ endif;
29
  <?php
30
  // display help when no conditions are given
31
  if ( $empty_options ) :
32
- $set_conditions = array();
33
  ?>
34
  <p><a class="button button-primary"
35
  href="<?php echo esc_url( ADVADS_URL ); ?>manual/visitor-conditions?utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor"
29
  <?php
30
  // display help when no conditions are given
31
  if ( $empty_options ) :
32
+ $set_conditions = [];
33
  ?>
34
  <p><a class="button button-primary"
35
  href="<?php echo esc_url( ADVADS_URL ); ?>manual/visitor-conditions?utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor"
admin/views/conditions/condition-author.php CHANGED
@@ -39,13 +39,13 @@ if ( count( $authors ) >= $max_authors ) :
39
  wp_kses(
40
  // translators: %1$d is the number of elements in the list and %2$s a URL.
41
  __( 'Only %1$d elements are displayed above. Use the <code>advanced-ads-admin-max-terms</code> filter to change this limit according to <a href="%2$s" target="_blank">this page</a>.', 'advanced-ads' ),
42
- array(
43
- 'code' => array(),
44
- 'a' => array(
45
- 'href' => array(),
46
- 'target' => array(),
47
- ),
48
- )
49
  ),
50
  absint( $max_authors ),
51
  esc_url( ADVADS_URL . 'codex/filter-hooks/?utm_source=advanced-ads&utm_medium=link&utm_campaign=author-term-limit' )
39
  wp_kses(
40
  // translators: %1$d is the number of elements in the list and %2$s a URL.
41
  __( 'Only %1$d elements are displayed above. Use the <code>advanced-ads-admin-max-terms</code> filter to change this limit according to <a href="%2$s" target="_blank">this page</a>.', 'advanced-ads' ),
42
+ [
43
+ 'code' => [],
44
+ 'a' => [
45
+ 'href' => [],
46
+ 'target' => [],
47
+ ],
48
+ ]
49
  ),
50
  absint( $max_authors ),
51
  esc_url( ADVADS_URL . 'codex/filter-hooks/?utm_source=advanced-ads&utm_medium=link&utm_campaign=author-term-limit' )
admin/views/conditions/condition-number.php CHANGED
@@ -16,4 +16,11 @@
16
  <option
17
  value="is_lower" <?php selected( 'is_lower', $operator ); ?>><?php esc_html_e( 'equal or lower', 'advanced-ads' ); ?></option>
18
  </select><input type="number" name="<?php echo esc_attr( $name ); ?>[value]" value="<?php echo absint( $value ); ?>"/>
19
- <p class="description"><?php echo esc_html( $type_options[ $options['type'] ]['description'] ); ?></p>
 
 
 
 
 
 
 
16
  <option
17
  value="is_lower" <?php selected( 'is_lower', $operator ); ?>><?php esc_html_e( 'equal or lower', 'advanced-ads' ); ?></option>
18
  </select><input type="number" name="<?php echo esc_attr( $name ); ?>[value]" value="<?php echo absint( $value ); ?>"/>
19
+ <p class="description">
20
+ <?php echo esc_html( $type_options[ $options['type'] ]['description'] ); ?>
21
+ <?php if ( isset( $type_options[ $options['type'] ]['helplink'] ) ) : ?>
22
+ <a href="<?php echo esc_url( $type_options[ $options['type'] ]['helplink'] ); ?>" class="advads-manual-link" target="_blank">
23
+ <?php esc_html_e( 'Manual', 'advanced-ads' ); ?>
24
+ </a>
25
+ <?php endif; ?>
26
+ </p>
admin/views/conditions/condition-string.php CHANGED
@@ -1,6 +1,11 @@
1
  <input type="hidden" name="<?php echo esc_attr( $name ); ?>[type]" value="<?php echo esc_attr( $options['type'] ); ?>"/>
2
- <div class="advads-condition-line-wrap">
3
- <?php include ADVADS_BASE_PATH . 'admin/views/ad-conditions-string-operators.php'; ?>
4
- <input type="text" name="<?php echo esc_attr( $name ); ?>[value]" value="<?php echo esc_attr( $value ); ?>"/>
5
- </div>
6
- <p class="description"><?php echo $type_options[ $options['type'] ]['description']; ?></p>
 
 
 
 
 
1
  <input type="hidden" name="<?php echo esc_attr( $name ); ?>[type]" value="<?php echo esc_attr( $options['type'] ); ?>"/>
2
+ <div class="advads-condition-line-wrap">
3
+ <?php include ADVADS_BASE_PATH . 'admin/views/ad-conditions-string-operators.php'; ?>
4
+ <input type="text" name="<?php echo esc_attr( $name ); ?>[value]" value="<?php echo esc_attr( $value ); ?>"/>
5
+ </div>
6
+ <p class="description">
7
+ <?php echo esc_html( $type_options[ $options['type'] ]['description'] ); ?>
8
+ <?php if ( isset( $type_options[ $options['type'] ]['helplink'] ) ) : ?>
9
+ <a href="<?php echo esc_url( $type_options[ $options['type'] ]['helplink'] ); ?>" class="advads-manual-link" target="_blank"><?php esc_html_e( 'Manual', 'advanced-ads' ); ?></a>
10
+ <?php endif; ?>
11
+ </p>
admin/views/conditions/display-conditions-list.php CHANGED
@@ -74,7 +74,7 @@
74
  data-condition-type="<?php echo esc_attr( $_options['type'] ); ?>"><?php echo esc_html( $conditions[ $_options['type'] ]['label'] ); ?></td>
75
  <td>
76
  <?php
77
- call_user_func( array( $metabox[0], $metabox[1] ), $_options, $i ++, $form_name );
78
  ?>
79
  </td>
80
  <td>
74
  data-condition-type="<?php echo esc_attr( $_options['type'] ); ?>"><?php echo esc_html( $conditions[ $_options['type'] ]['label'] ); ?></td>
75
  <td>
76
  <?php
77
+ call_user_func( [ $metabox[0], $metabox[1] ], $_options, $i ++, $form_name );
78
  ?>
79
  </td>
80
  <td>
admin/views/conditions/visitor-conditions-form-top.php CHANGED
@@ -12,12 +12,12 @@ elseif ( Advanced_Ads_Checks::cache() && ! defined( 'AAP_VERSION' ) ) :
12
  wp_kses(
13
  // translators: %s is a URL.
14
  __( 'Check out cache-busting in <a href="%s" target="_blank">Advanced Ads Pro</a> if dynamic features get cached.', 'advanced-ads' ),
15
- array(
16
- 'a' => array(
17
- 'href' => array(),
18
- 'target' => array(),
19
- ),
20
- )
21
  ),
22
  esc_url( ADVADS_URL ) . 'add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor'
23
  );
12
  wp_kses(
13
  // translators: %s is a URL.
14
  __( 'Check out cache-busting in <a href="%s" target="_blank">Advanced Ads Pro</a> if dynamic features get cached.', 'advanced-ads' ),
15
+ [
16
+ 'a' => [
17
+ 'href' => [],
18
+ 'target' => [],
19
+ ],
20
+ ]
21
  ),
22
  esc_url( ADVADS_URL ) . 'add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor'
23
  );
admin/views/conditions/visitor-conditions-list.php CHANGED
@@ -25,7 +25,7 @@
25
  <td class="advads-conditions-type"><?php echo esc_html( $conditions[ $_options['type'] ]['label'] ); ?></td>
26
  <td>
27
  <?php
28
- call_user_func( array( $metabox[0], $metabox[1] ), $_options, $i ++, $form_name );
29
  ?>
30
  </td>
31
  <td>
25
  <td class="advads-conditions-type"><?php echo esc_html( $conditions[ $_options['type'] ]['label'] ); ?></td>
26
  <td>
27
  <?php
28
+ call_user_func( [ $metabox[0], $metabox[1] ], $_options, $i ++, $form_name );
29
  ?>
30
  </td>
31
  <td>
admin/views/gadsense-dashboard.php CHANGED
@@ -3,10 +3,10 @@
3
  $pub_id = Advanced_Ads_AdSense_Data::get_instance()->get_adsense_id();
4
  if ( $pub_id ) {
5
  Advanced_Ads_Overview_Widgets_Callbacks::adsense_stats_js( $pub_id );
6
- $arguments = array(
7
  'type' => $report_type,
8
  'filter' => $report_filter,
9
- );
10
  $report = new Advanced_Ads_AdSense_Report( $report_type, $report_filter );
11
 
12
  echo '<div class="advanced-ads-adsense-dashboard" data-arguments="' . esc_js( wp_json_encode( $arguments ) ) . '">';
3
  $pub_id = Advanced_Ads_AdSense_Data::get_instance()->get_adsense_id();
4
  if ( $pub_id ) {
5
  Advanced_Ads_Overview_Widgets_Callbacks::adsense_stats_js( $pub_id );
6
+ $arguments = [
7
  'type' => $report_type,
8
  'filter' => $report_filter,
9
+ ];
10
  $report = new Advanced_Ads_AdSense_Report( $report_type, $report_filter );
11
 
12
  echo '<div class="advanced-ads-adsense-dashboard" data-arguments="' . esc_js( wp_json_encode( $arguments ) ) . '">';
admin/views/group-form.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Render form to create a new ad group.
4
+ *
5
+ * @var array[] $group_types
6
+ * @var array[] $group_types_premium
7
+ */
8
+ ?>
9
+ <form method="post" class="advads-group-new-form advads-form" id="advads-group-new-form">
10
+ <h3>1. <?php esc_html_e( 'Choose the type', 'advanced-ads' ); ?></h3>
11
+ <div class="advads-form-types advads-buttonset">
12
+ <?php foreach ( $group_types as $key => $group_type ) : ?>
13
+ <div class="advads-form-type">
14
+ <label for="advads-form-type-<?php echo esc_attr( $key ); ?>">
15
+ <img src="<?php echo esc_attr( $group_type['image'] ); ?>" alt="<?php echo esc_attr( $group_type['title'] ); ?>"/>
16
+ </label>
17
+ <input type="radio" id="advads-form-type-<?php echo esc_attr( $key ); ?>" name="advads-group-type" value="<?php echo esc_attr( $key ); ?>"/>
18
+ <div class="advads-form-description">
19
+ <h4><?php echo esc_html( $group_type['title'] ); ?></h4>
20
+ <?php echo esc_html( $group_type['description'] ); ?>
21
+ </div>
22
+ </div>
23
+ <?php endforeach; ?>
24
+ </div>
25
+ <div class="clear"></div>
26
+ <?php if ( $group_types_premium ) : ?>
27
+ <h4><?php Advanced_Ads_Admin_Upgrades::upgrade_link( __( 'Pro Feature', 'advanced-ads' ), ADVADS_URL . 'manual/ad-groups/', 'upgrades-pro-groups' ); ?></h4>
28
+ <div class="advads-form-types">
29
+ <?php foreach ( $group_types_premium as $key => $group_type ) : ?>
30
+ <div class="advads-form-type">
31
+ <label class="advads-button advads-pro-link">
32
+ <span class="advads-button-text">
33
+ <img src="<?php echo esc_attr( $group_type['image'] ); ?>" alt="<?php echo esc_attr( $group_type['title'] ); ?>"/>
34
+ </span>
35
+ </label>
36
+ <p class="advads-form-description">
37
+ <strong><?php echo esc_html( $group_type['title'] ); ?></strong>
38
+ </p>
39
+ </div>
40
+ <?php endforeach; ?>
41
+ </div>
42
+ <div class="clear"></div>
43
+ <?php endif; ?>
44
+ <div class="clear"></div>
45
+ <p class="advads-notice-inline advads-error advads-form-type-error"><?php esc_html_e( 'Please select a type.', 'advanced-ads' ); ?></p>
46
+ <br/>
47
+ <h3>2. <?php esc_html_e( 'Choose a name', 'advanced-ads' ); ?></h3>
48
+ <input type="text" name="advads-group-name" class="advads-form-name" placeholder="<?php esc_attr_e( 'Group title', 'advanced-ads' ); ?>"/>
49
+ <p class="advads-notice-inline advads-error advads-form-name-error"><?php esc_html_e( 'Please enter a name.', 'advanced-ads' ); ?></p>
50
+ <?php wp_nonce_field( 'add-advads-groups', 'advads-group-add-nonce' ); ?>
51
+ </form>
admin/views/notices/info.php CHANGED
@@ -3,12 +3,12 @@
3
  <a href="
4
  <?php
5
  add_query_arg(
6
- array(
7
  'action' => 'advads-close-notice',
8
  'notice' => $_notice,
9
  'nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
10
  'redirect' => $_SERVER['REQUEST_URI'],
11
- ),
12
  admin_url( 'admin-ajax.php' )
13
  );
14
  ?>
3
  <a href="
4
  <?php
5
  add_query_arg(
6
+ [
7
  'action' => 'advads-close-notice',
8
  'notice' => $_notice,
9
  'nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
10
  'redirect' => $_SERVER['REQUEST_URI'],
11
+ ],
12
  admin_url( 'admin-ajax.php' )
13
  );
14
  ?>
admin/views/notices/promo.php CHANGED
@@ -13,28 +13,28 @@
13
  <?php
14
  echo wp_kses(
15
  $text,
16
- array(
17
- 'a' => array(
18
- 'href' => array(),
19
- 'class' => array(),
20
- 'target' => array(),
21
- ),
22
- 'span' => array(
23
- 'style' => array(),
24
- ),
25
- )
26
  );
27
  ?>
28
  </p>
29
  <a href="
30
  <?php
31
  add_query_arg(
32
- array(
33
  'action' => 'advads-close-notice',
34
  'notice' => $_notice,
35
  'nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
36
  'redirect' => $_SERVER['REQUEST_URI'],
37
- ),
38
  admin_url( 'admin-ajax.php' )
39
  );
40
  ?>
13
  <?php
14
  echo wp_kses(
15
  $text,
16
+ [
17
+ 'a' => [
18
+ 'href' => [],
19
+ 'class' => [],
20
+ 'target' => [],
21
+ ],
22
+ 'span' => [
23
+ 'style' => [],
24
+ ],
25
+ ]
26
  );
27
  ?>
28
  </p>
29
  <a href="
30
  <?php
31
  add_query_arg(
32
+ [
33
  'action' => 'advads-close-notice',
34
  'notice' => $_notice,
35
  'nonce' => wp_create_nonce( 'advanced-ads-admin-ajax-nonce' ),
36
  'redirect' => $_SERVER['REQUEST_URI'],
37
+ ],
38
  admin_url( 'admin-ajax.php' )
39
  );
40
  ?>
admin/views/overview-notices.php CHANGED
@@ -31,11 +31,11 @@ Advanced_Ads_Ad_Health_Notices::get_instance()->display_notices();
31
  wp_kses(
32
  // translators: %s includes a number and markup like <span class="count">6</span>.
33
  esc_html__( 'Show %s hidden notices', 'advanced-ads' ),
34
- array(
35
- 'span' => array(
36
  'class',
37
- ),
38
- )
39
  ),
40
  '<span class="count">' . absint( $ignored_count ) . '</span>'
41
  );
31
  wp_kses(
32
  // translators: %s includes a number and markup like <span class="count">6</span>.
33
  esc_html__( 'Show %s hidden notices', 'advanced-ads' ),
34
+ [
35
+ 'span' => [
36
  'class',
37
+ ],
38
+ ]
39
  ),
40
  '<span class="count">' . absint( $ignored_count ) . '</span>'
41
  );
admin/views/placement-form.php CHANGED
@@ -5,7 +5,7 @@
5
  * @var array $placement_types types of placements.
6
  */
7
  ?>
8
- <form method="POST" class="advads-placements-new-form" id="advads-placements-new-form">
9
  <h3>1. <?php esc_html_e( 'Choose a placement type', 'advanced-ads' ); ?></h3>
10
  <p class="description">
11
  <?php
@@ -13,11 +13,11 @@
13
  wp_kses(
14
  // translators: %s is a URL.
15
  __( 'Placement types define where the ad is going to be displayed. Learn more about the different types from the <a href="%s">manual</a>', 'advanced-ads' ),
16
- array(
17
- 'a' => array(
18
- 'href' => array(),
19
- ),
20
- )
21
  ),
22
  esc_url( ADVADS_URL ) . 'manual/placements/#utm_source=advanced-ads&utm_medium=link&utm_campaign=placements'
23
  );
@@ -27,7 +27,7 @@
27
  <div class="clear"></div>
28
  <?php
29
 
30
- // show Pro placements if Pro is not actiavated.
31
  if ( ! defined( 'AAP_VERSION' ) ) :
32
  include ADVADS_BASE_PATH . 'admin/views/upgrades/pro-placements.php';
33
  ?>
@@ -35,18 +35,18 @@
35
  <?php
36
  endif;
37
  ?>
38
- <p class="advads-notice-inline advads-error advads-placement-type-error"><?php esc_html_e( 'Please select a placement type.', 'advanced-ads' ); ?></p>
39
  <br/>
40
  <h3>2. <?php esc_html_e( 'Choose a Name', 'advanced-ads' ); ?></h3>
41
  <p>
42
- <input name="advads[placement][name]" class="advads-new-placement-name" type="text" value="" placeholder="<?php esc_html_e( 'Placement Name', 'advanced-ads' ); ?>" />
43
  <span class="advads-help">
44
  <span class="advads-tooltip">
45
  <?php esc_html_e( 'The name of the placement is only visible to you. Tip: choose a descriptive one, e.g. Below Post Headline.', 'advanced-ads' ); ?>
46
  </span>
47
  </span>
48
  </p>
49
- <p class="advads-notice-inline advads-error advads-placement-name-error"><?php esc_html_e( 'Please enter a name for your placement.', 'advanced-ads' ); ?></p>
50
  <h3>3. <?php esc_html_e( 'Choose the Ad or Group', 'advanced-ads' ); ?></h3>
51
  <p><select name="advads[placement][item]">
52
  <option value=""><?php esc_html_e( '--not selected--', 'advanced-ads' ); ?></option>
5
  * @var array $placement_types types of placements.
6
  */
7
  ?>
8
+ <form method="POST" class="advads-placements-new-form advads-form" id="advads-placements-new-form">
9
  <h3>1. <?php esc_html_e( 'Choose a placement type', 'advanced-ads' ); ?></h3>
10
  <p class="description">
11
  <?php
13
  wp_kses(
14
  // translators: %s is a URL.
15
  __( 'Placement types define where the ad is going to be displayed. Learn more about the different types from the <a href="%s">manual</a>', 'advanced-ads' ),
16
+ [
17
+ 'a' => [
18
+ 'href' => [],
19
+ ],
20
+ ]
21
  ),
22
  esc_url( ADVADS_URL ) . 'manual/placements/#utm_source=advanced-ads&utm_medium=link&utm_campaign=placements'
23
  );
27
  <div class="clear"></div>
28
  <?php
29
 
30
+ // show Pro placements if Pro is not activated.
31
  if ( ! defined( 'AAP_VERSION' ) ) :
32
  include ADVADS_BASE_PATH . 'admin/views/upgrades/pro-placements.php';
33
  ?>
35
  <?php
36
  endif;
37
  ?>
38
+ <p class="advads-notice-inline advads-error advads-form-type-error"><?php esc_html_e( 'Please select a type.', 'advanced-ads' ); ?></p>
39
  <br/>
40
  <h3>2. <?php esc_html_e( 'Choose a Name', 'advanced-ads' ); ?></h3>
41
  <p>
42
+ <input name="advads[placement][name]" class="advads-form-name" type="text" value="" placeholder="<?php esc_html_e( 'Placement Name', 'advanced-ads' ); ?>" />
43
  <span class="advads-help">
44
  <span class="advads-tooltip">
45
  <?php esc_html_e( 'The name of the placement is only visible to you. Tip: choose a descriptive one, e.g. Below Post Headline.', 'advanced-ads' ); ?>
46
  </span>
47
  </span>
48
  </p>
49
+ <p class="advads-notice-inline advads-error advads-form-name-error"><?php esc_html_e( 'Please enter a name.', 'advanced-ads' ); ?></p>
50
  <h3>3. <?php esc_html_e( 'Choose the Ad or Group', 'advanced-ads' ); ?></h3>
51
  <p><select name="advads[placement][item]">
52
  <option value=""><?php esc_html_e( '--not selected--', 'advanced-ads' ); ?></option>
admin/views/placement-injection-top.php CHANGED
@@ -19,12 +19,12 @@ $is_page_level_ad_in_code_field = ( isset( $ad->type ) && 'plain' === $ad->type
19
  // translators: %s is a URL.
20
 
21
  __( 'Ad not showing up? Take a look <a href="%s" target="_blank">here</a>', 'advanced-ads' ),
22
- array(
23
- 'a' => array(
24
- 'href' => array(),
25
- 'target' => array(),
26
- ),
27
- )
28
  ),
29
  esc_url( ADVADS_URL ) . 'manual/ads-not-showing-up/?utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-ad-not-visible'
30
  );
@@ -44,11 +44,11 @@ $is_page_level_ad_in_code_field = ( isset( $ad->type ) && 'plain' === $ad->type
44
  wp_kses(
45
  // translators: %s is a URL.
46
  __( 'The AdSense verification and Auto ads code is already activated in the <a href="%s">AdSense settings</a>.', 'advanced-ads' ),
47
- array(
48
- 'a' => array(
49
- 'href' => array(),
50
- ),
51
- )
52
  ),
53
  admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' )
54
  );
19
  // translators: %s is a URL.
20
 
21
  __( 'Ad not showing up? Take a look <a href="%s" target="_blank">here</a>', 'advanced-ads' ),
22
+ [
23
+ 'a' => [
24
+ 'href' => [],
25
+ 'target' => [],
26
+ ],
27
+ ]
28
  ),
29
  esc_url( ADVADS_URL ) . 'manual/ads-not-showing-up/?utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-ad-not-visible'
30
  );
44
  wp_kses(
45
  // translators: %s is a URL.
46
  __( 'The AdSense verification and Auto ads code is already activated in the <a href="%s">AdSense settings</a>.', 'advanced-ads' ),
47
+ [
48
+ 'a' => [
49
+ 'href' => [],
50
+ ],
51
+ ]
52
  ),
53
  admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' )
54
  );
admin/views/placement-types.php CHANGED
@@ -7,19 +7,19 @@
7
  */
8
  ?>
9
  <?php if ( is_array( $placement_types ) ) : ?>
10
- <div class="advads-new-placement-types advads-placements-new-form advads-buttonset">
11
  <?php foreach ( $placement_types as $key => $placement_type ) : ?>
12
- <div class="advads-placement-type">
13
- <label for="advads-placement-type-<?php echo esc_attr( $key ); ?>">
14
  <?php if ( isset( $placement_type['image'] ) ) : ?>
15
  <img src="<?php echo esc_attr( $placement_type['image'] ); ?>" alt="<?php echo esc_attr( $placement_type['title'] ); ?>"/>
16
  <?php else : ?>
17
  <strong><?php echo esc_html( $placement_type['title'] ); ?></strong><br/>
18
- <p class="description"><?php echo esc_html( $placement_type['description'] ); ?></p>';
19
  <?php endif; ?>
20
  </label>
21
- <input type="radio" id="advads-placement-type-<?php echo esc_attr( $key ); ?>" name="advads[placement][type]" value="<?php echo esc_attr( $key ); ?>"/>
22
- <div class="advads-placement-description">
23
  <h4><?php echo esc_html( $placement_type['title'] ); ?></h4>
24
  <?php echo esc_html( $placement_type['description'] ); ?>
25
  </div>
7
  */
8
  ?>
9
  <?php if ( is_array( $placement_types ) ) : ?>
10
+ <div class="advads-form-types advads-buttonset">
11
  <?php foreach ( $placement_types as $key => $placement_type ) : ?>
12
+ <div class="advads-form-type">
13
+ <label for="advads-form-type-<?php echo esc_attr( $key ); ?>">
14
  <?php if ( isset( $placement_type['image'] ) ) : ?>
15
  <img src="<?php echo esc_attr( $placement_type['image'] ); ?>" alt="<?php echo esc_attr( $placement_type['title'] ); ?>"/>
16
  <?php else : ?>
17
  <strong><?php echo esc_html( $placement_type['title'] ); ?></strong><br/>
18
+ <p class="description"><?php echo esc_html( $placement_type['description'] ); ?></p>
19
  <?php endif; ?>
20
  </label>
21
+ <input type="radio" id="advads-form-type-<?php echo esc_attr( $key ); ?>" name="advads[placement][type]" value="<?php echo esc_attr( $key ); ?>"/>
22
+ <div class="advads-form-description">
23
  <h4><?php echo esc_html( $placement_type['title'] ); ?></h4>
24
  <?php echo esc_html( $placement_type['description'] ); ?>
25
  </div>
admin/views/placements.php CHANGED
@@ -6,7 +6,7 @@ defined( 'ABSPATH' ) || exit;
6
  * @var array $placement_types placement types.
7
  */
8
 
9
- $quick_actions = array();
10
  $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag">' . __( 'Delete', 'advanced-ads' ) . '</a>';
11
 
12
  ?>
@@ -37,7 +37,7 @@ $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag
37
  $modal_title = esc_html__( 'New Placement', 'advanced-ads' );
38
  $close_action = esc_html__( 'Save New Placement', 'advanced-ads' );
39
  $close_form = 'advads-placements-new-form';
40
- $close_validation = 'advads_validate_placement_form';
41
  $modal_path = ADVADS_BASE_PATH . 'admin/views/modal.php';
42
  if ( file_exists( $modal_path ) ) {
43
  include $modal_path;
@@ -50,21 +50,21 @@ $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag
50
  <form method="POST" action="" id="advanced-ads-placements-form">
51
 
52
  <?php
53
- $columns = array(
54
- array(
55
  'key' => 'type_name',
56
  'display_name' => esc_html__( 'Type', 'advanced-ads' ) . ' / ' . esc_html__( 'Name', 'advanced-ads' ),
57
  'custom_sort' => true,
58
- ),
59
- array(
60
  'key' => 'options',
61
  'display_name' => esc_html__( 'Output', 'advanced-ads' ),
62
- ),
63
- array(
64
  'key' => 'conditons',
65
  'display_name' => esc_html__( 'Delivery', 'advanced-ads' ),
66
- ),
67
- );
68
  ?>
69
 
70
  <?php if ( isset( $placement_types ) && ! empty( $placement_types ) ) : ?>
@@ -81,7 +81,7 @@ $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag
81
  </div>
82
  <?php endif; ?>
83
 
84
- <table class="wp-list-table advads-placements-table widefat striped posts">
85
  <thead>
86
  <tr>
87
  <?php
@@ -136,7 +136,7 @@ $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag
136
  do_action( 'advanced-ads-placement-options-before-advanced', $_placement_slug, $_placement );
137
 
138
  if ( $_placement['type'] !== 'header' ) :
139
- $type_options = isset( $placement_types[ $_placement['type'] ]['options'] ) ? $placement_types[ $_placement['type'] ]['options'] : array();
140
 
141
  if ( ! isset( $type_options['placement-ad-label'] ) || $type_options['placement-ad-label'] ) {
142
  $_label = isset( $_placement['options']['ad_label'] ) ? $_placement['options']['ad_label'] : 'default';
@@ -240,22 +240,22 @@ $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag
240
  wp_kses(
241
  // Translators: %s is the name of a placement.
242
  __( 'Placement type "%s" is missing and was reset to "default".<br/>Please check if the responsible add-on is activated.', 'advanced-ads' ),
243
- array(
244
- 'br' => array(),
245
- )
246
  ),
247
  esc_html( $missed_type )
248
  );
249
  ?>
250
  </p>
251
  <?php elseif ( isset( $_placement['type'] ) ) : ?>
252
- <div class="advads-placement-type">
253
  <?php if ( isset( $placement_types[ $_placement['type'] ]['image'] ) ) : ?>
254
  <img src="<?php echo esc_url( $placement_types[ $_placement['type'] ]['image'] ); ?>" alt="<?php echo esc_attr( $placement_types[ $_placement['type'] ]['title'] ); ?>"/>
255
- <p class="advads-placement-description">
256
- <strong><?php echo esc_html__( 'Type', 'advanced-ads' ) . ': ' . esc_html( $placement_types[ $_placement['type'] ]['title'] ); ?></strong>
257
  </p>
258
- <div class="advads-placement-name">
259
  <a href="#modal-<?php echo esc_attr( $_placement_slug ); ?>" class="row-title" data-placement="<?php echo esc_attr( $_placement_slug ); ?>">
260
  <?php echo esc_html( $_placement['name'] ); ?>
261
  </a><br/>
@@ -279,13 +279,13 @@ $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag
279
  <?php
280
  echo wp_kses(
281
  $action_link,
282
- array(
283
- 'a' => array(
284
- 'class' => array(),
285
- 'href' => array(),
286
  'style' => 'cursor: pointer',
287
- ),
288
- )
289
  );
290
  ?>
291
  </span>
@@ -359,10 +359,10 @@ $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag
359
  }
360
 
361
  $option_xpath = isset( $_placement['options']['xpath'] ) ? stripslashes( $_placement['options']['xpath'] ) : '';
362
- $positions = array(
363
  'after' => __( 'after', 'advanced-ads' ),
364
  'before' => __( 'before', 'advanced-ads' ),
365
- );
366
  ob_start();
367
  include ADVADS_BASE_PATH . 'admin/views/placements-content-index.php';
368
  if ( ! defined( 'AAP_VERSION' ) ) {
@@ -404,12 +404,12 @@ $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag
404
  wp_kses(
405
  // Translators: %s is a URL.
406
  __( 'Tutorial: <a href="%s" target="_blank">How to place visible ads in the header of your website</a>.', 'advanced-ads' ),
407
- array(
408
- 'a' => array(
409
- 'href' => array(),
410
- 'target' => array(),
411
- ),
412
- )
413
  ),
414
  esc_url( ADVADS_URL ) . 'place-ads-in-website-header/?utm_source=advanced-ads&utm_medium=link&utm_campaign=header-ad-tutorial'
415
  );
6
  * @var array $placement_types placement types.
7
  */
8
 
9
+ $quick_actions = [];
10
  $quick_actions['delete'] = '<a style="cursor: pointer;" class="advads-delete-tag">' . __( 'Delete', 'advanced-ads' ) . '</a>';
11
 
12
  ?>
37
  $modal_title = esc_html__( 'New Placement', 'advanced-ads' );
38
  $close_action = esc_html__( 'Save New Placement', 'advanced-ads' );
39
  $close_form = 'advads-placements-new-form';
40
+ $close_validation = 'advads_validate_new_form';
41
  $modal_path = ADVADS_BASE_PATH . 'admin/views/modal.php';
42
  if ( file_exists( $modal_path ) ) {
43
  include $modal_path;
50
  <form method="POST" action="" id="advanced-ads-placements-form">
51
 
52
  <?php
53
+ $columns = [
54
+ [
55
  'key' => 'type_name',
56
  'display_name' => esc_html__( 'Type', 'advanced-ads' ) . ' / ' . esc_html__( 'Name', 'advanced-ads' ),
57
  'custom_sort' => true,
58
+ ],
59
+ [
60
  'key' => 'options',
61
  'display_name' => esc_html__( 'Output', 'advanced-ads' ),
62
+ ],
63
+ [
64
  'key' => 'conditons',
65
  'display_name' => esc_html__( 'Delivery', 'advanced-ads' ),
66
+ ],
67
+ ];
68
  ?>
69
 
70
  <?php if ( isset( $placement_types ) && ! empty( $placement_types ) ) : ?>
81
  </div>
82
  <?php endif; ?>
83
 
84
+ <table class="wp-list-table advads-placements-table widefat posts advads-table">
85
  <thead>
86
  <tr>
87
  <?php
136
  do_action( 'advanced-ads-placement-options-before-advanced', $_placement_slug, $_placement );
137
 
138
  if ( $_placement['type'] !== 'header' ) :
139
+ $type_options = isset( $placement_types[ $_placement['type'] ]['options'] ) ? $placement_types[ $_placement['type'] ]['options'] : [];
140
 
141
  if ( ! isset( $type_options['placement-ad-label'] ) || $type_options['placement-ad-label'] ) {
142
  $_label = isset( $_placement['options']['ad_label'] ) ? $_placement['options']['ad_label'] : 'default';
240
  wp_kses(
241
  // Translators: %s is the name of a placement.
242
  __( 'Placement type "%s" is missing and was reset to "default".<br/>Please check if the responsible add-on is activated.', 'advanced-ads' ),
243
+ [
244
+ 'br' => [],
245
+ ]
246
  ),
247
  esc_html( $missed_type )
248
  );
249
  ?>
250
  </p>
251
  <?php elseif ( isset( $_placement['type'] ) ) : ?>
252
+ <div class="advads-form-type">
253
  <?php if ( isset( $placement_types[ $_placement['type'] ]['image'] ) ) : ?>
254
  <img src="<?php echo esc_url( $placement_types[ $_placement['type'] ]['image'] ); ?>" alt="<?php echo esc_attr( $placement_types[ $_placement['type'] ]['title'] ); ?>"/>
255
+ <p class="advads-form-description">
256
+ <strong><?php echo esc_html( $placement_types[ $_placement['type'] ]['title'] ); ?></strong>
257
  </p>
258
+ <div class="advads-table-name">
259
  <a href="#modal-<?php echo esc_attr( $_placement_slug ); ?>" class="row-title" data-placement="<?php echo esc_attr( $_placement_slug ); ?>">
260
  <?php echo esc_html( $_placement['name'] ); ?>
261
  </a><br/>
279
  <?php
280
  echo wp_kses(
281
  $action_link,
282
+ [
283
+ 'a' => [
284
+ 'class' => [],
285
+ 'href' => [],
286
  'style' => 'cursor: pointer',
287
+ ],
288
+ ]
289
  );
290
  ?>
291
  </span>
359
  }
360
 
361
  $option_xpath = isset( $_placement['options']['xpath'] ) ? stripslashes( $_placement['options']['xpath'] ) : '';
362
+ $positions = [
363
  'after' => __( 'after', 'advanced-ads' ),
364
  'before' => __( 'before', 'advanced-ads' ),
365
+ ];
366
  ob_start();
367
  include ADVADS_BASE_PATH . 'admin/views/placements-content-index.php';
368
  if ( ! defined( 'AAP_VERSION' ) ) {
404
  wp_kses(
405
  // Translators: %s is a URL.
406
  __( 'Tutorial: <a href="%s" target="_blank">How to place visible ads in the header of your website</a>.', 'advanced-ads' ),
407
+ [
408
+ 'a' => [
409
+ 'href' => [],
410
+ 'target' => [],
411
+ ],
412
+ ]
413
  ),
414
  esc_url( ADVADS_URL ) . 'place-ads-in-website-header/?utm_source=advanced-ads&utm_medium=link&utm_campaign=header-ad-tutorial'
415
  );
admin/views/settings.php CHANGED
@@ -6,14 +6,14 @@
6
  // array with setting tabs for frontend.
7
  $setting_tabs = apply_filters(
8
  'advanced-ads-setting-tabs',
9
- array(
10
- 'general' => array(
11
  'page' => Advanced_Ads_Admin::get_instance()->plugin_screen_hook_suffix,
12
  'group' => ADVADS_SLUG,
13
  'tabid' => 'general',
14
  'title' => __( 'General', 'advanced-ads' ),
15
- ),
16
- )
17
  );
18
  ?><div class="wrap">
19
  <h2 style="display: none;"><!-- There needs to be an empty H2 headline at the top of the page so that WordPress can properly position admin notifications --></h2>
6
  // array with setting tabs for frontend.
7
  $setting_tabs = apply_filters(
8
  'advanced-ads-setting-tabs',
9
+ [
10
+ 'general' => [
11
  'page' => Advanced_Ads_Admin::get_instance()->plugin_screen_hook_suffix,
12
  'group' => ADVADS_SLUG,
13
  'tabid' => 'general',
14
  'title' => __( 'General', 'advanced-ads' ),
15
+ ],
16
+ ]
17
  );
18
  ?><div class="wrap">
19
  <h2 style="display: none;"><!-- There needs to be an empty H2 headline at the top of the page so that WordPress can properly position admin notifications --></h2>
admin/views/settings/general/advanced-js.php CHANGED
@@ -12,12 +12,12 @@ printf(
12
  wp_kses(
13
  // translators: %s is a URL.
14
  __( 'Enable advanced JavaScript functions (<a href="%s" target="_blank">here</a>). Some features and add-ons might override this setting if they need features from this file.', 'advanced-ads' ),
15
- array(
16
- 'a' => array(
17
- 'href' => array(),
18
- 'target' => array(),
19
- ),
20
- )
21
  ),
22
  esc_url( ADVADS_URL . 'javascript-functions/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings' )
23
  );
12
  wp_kses(
13
  // translators: %s is a URL.
14
  __( 'Enable advanced JavaScript functions (<a href="%s" target="_blank">here</a>). Some features and add-ons might override this setting if they need features from this file.', 'advanced-ads' ),
15
+ [
16
+ 'a' => [
17
+ 'href' => [],
18
+ 'target' => [],
19
+ ],
20
+ ]
21
  ),
22
  esc_url( ADVADS_URL . 'javascript-functions/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings' )
23
  );
admin/views/settings/general/editors-manage-ads.php CHANGED
@@ -5,12 +5,12 @@ printf(
5
  wp_kses(
6
  // translators: %s is a URL.
7
  __( 'You can assign different ad-related roles on a user basis with <a href="%s" target="_blank">Advanced Ads Pro</a>.', 'advanced-ads' ),
8
- array(
9
- 'a' => array(
10
- 'href' => array(),
11
- 'target' => array(),
12
- ),
13
- )
14
  ),
15
  esc_url( ADVADS_URL . 'add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings' )
16
  );
5
  wp_kses(
6
  // translators: %s is a URL.
7
  __( 'You can assign different ad-related roles on a user basis with <a href="%s" target="_blank">Advanced Ads Pro</a>.', 'advanced-ads' ),
8
+ [
9
+ 'a' => [
10
+ 'href' => [],
11
+ 'target' => [],
12
+ ],
13
+ ]
14
  ),
15
  esc_url( ADVADS_URL . 'add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings' )
16
  );
admin/views/settings/general/link-target.php CHANGED
@@ -3,4 +3,4 @@
3
  checked( 1, $target );
4
  ?>
5
  />
6
- <p class="description"><?php echo wp_kses( __( 'Open programmatically created links in a new window (use <code>target="_blank"</code>)', 'advanced-ads' ), array( 'code' => array() ) ); ?></p>
3
  checked( 1, $target );
4
  ?>
5
  />
6
+ <p class="description"><?php echo wp_kses( __( 'Open programmatically created links in a new window (use <code>target="_blank"</code>)', 'advanced-ads' ), [ 'code' => [] ] ); ?></p>
admin/views/settings/license/section.php CHANGED
@@ -7,12 +7,12 @@ printf(
7
  wp_kses(
8
  // translators: %s is a URL.
9
  __( 'See also <a href="%s" target="_blank">Issues and questions about licenses</a>.', 'advanced-ads' ),
10
- array(
11
- 'a' => array(
12
- 'href' => array(),
13
- 'target' => array(),
14
- ),
15
- )
16
  ),
17
  esc_url( ADVADS_URL . 'manual/purchase-licenses/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses' )
18
  );
7
  wp_kses(
8
  // translators: %s is a URL.
9
  __( 'See also <a href="%s" target="_blank">Issues and questions about licenses</a>.', 'advanced-ads' ),
10
+ [
11
+ 'a' => [
12
+ 'href' => [],
13
+ 'target' => [],
14
+ ],
15
+ ]
16
  ),
17
  esc_url( ADVADS_URL . 'manual/purchase-licenses/?utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses' )
18
  );
admin/views/support.php CHANGED
@@ -24,12 +24,12 @@
24
  wp_kses(
25
  // translators: %s is a URL.
26
  __( 'Take a look at more common issues or contact us directly through the <a href="%s" target="_blank">support page</a>.', 'advanced-ads' ),
27
- array(
28
- 'a' => array(
29
- 'href' => array(),
30
- 'target' => array(),
31
- ),
32
- )
33
  ),
34
  esc_url( ADVADS_URL ) . 'support/?utm_source=advanced-ads&utm_medium=link&utm_campaign=support'
35
  );
@@ -42,12 +42,12 @@
42
  wp_kses(
43
  // translators: %s is a URL.
44
  __( 'Upgrade to any premium add-on and get <strong>priority email support</strong> or reach out through the <a href="%s" target="_blank">support forum</a> for individual help.', 'advanced-ads' ),
45
- array(
46
- 'a' => array(
47
- 'href' => array(),
48
- 'target' => array(),
49
- ),
50
- )
51
  ),
52
  'https://wordpress.org/support/plugin/advanced-ads'
53
  );
@@ -60,7 +60,7 @@
60
  <?php
61
  echo wp_kses(
62
  implode( '</li><li>', $constants ),
63
- array( 'li' => array() )
64
  );
65
  ?>
66
  </li></ul>
24
  wp_kses(
25
  // translators: %s is a URL.
26
  __( 'Take a look at more common issues or contact us directly through the <a href="%s" target="_blank">support page</a>.', 'advanced-ads' ),
27
+ [
28
+ 'a' => [
29
+ 'href' => [],
30
+ 'target' => [],
31
+ ],
32
+ ]
33
  ),
34
  esc_url( ADVADS_URL ) . 'support/?utm_source=advanced-ads&utm_medium=link&utm_campaign=support'
35
  );
42
  wp_kses(
43
  // translators: %s is a URL.
44
  __( 'Upgrade to any premium add-on and get <strong>priority email support</strong> or reach out through the <a href="%s" target="_blank">support forum</a> for individual help.', 'advanced-ads' ),
45
+ [
46
+ 'a' => [
47
+ 'href' => [],
48
+ 'target' => [],
49
+ ],
50
+ ]
51
  ),
52
  'https://wordpress.org/support/plugin/advanced-ads'
53
  );
60
  <?php
61
  echo wp_kses(
62
  implode( '</li><li>', $constants ),
63
+ [ 'li' => [] ]
64
  );
65
  ?>
66
  </li></ul>
admin/views/upgrades/pro-placements.php CHANGED
@@ -1,63 +1,63 @@
1
  <?php
2
  // todo: move the array somewhere else.
3
- $pro_placements = array(
4
  // ad injection on random position.
5
- 'post_content_random' => array(
6
  'title' => __( 'Random Paragraph', 'advanced-ads' ),
7
  'description' => __( 'After a random paragraph in the main content.', 'advanced-ads' ),
8
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-random.png',
9
- ),
10
  // ad injection above the post headline.
11
- 'post_above_headline' => array(
12
  'title' => __( 'Above Headline', 'advanced-ads' ),
13
  'description' => __( 'Above the main headline on the page (&lt;h1&gt;).', 'advanced-ads' ),
14
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-above-headline.png',
15
- ),
16
  // ad injection in the middle of a post.
17
- 'post_content_middle' => array(
18
  'title' => __( 'Content Middle', 'advanced-ads' ),
19
  'description' => __( 'In the middle of the main content based on the number of paragraphs.', 'advanced-ads' ),
20
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-middle.png',
21
- ),
22
  // ad injection at a hand selected element in the frontend.
23
- 'custom_position' => array(
24
  'title' => __( 'Custom Position', 'advanced-ads' ),
25
  'description' => __( 'Attach the ad to any element in the frontend.', 'advanced-ads' ),
26
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/custom-position.png',
27
- ),
28
  // ad injection between posts on archive and category pages.
29
- 'archive_pages' => array(
30
  'title' => __( 'Post Lists', 'advanced-ads' ),
31
  'description' => __( 'Display the ad between posts on post lists, e.g. home, archives, search etc.', 'advanced-ads' ),
32
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/post-list.png',
33
- ),
34
- 'background' => array(
35
  'title' => __( 'Background Ad', 'advanced-ads' ),
36
  'description' => __( 'Background of the website behind the main wrapper.', 'advanced-ads' ),
37
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/background.png',
38
- ),
39
- );
40
  // BuddyBoss & BuddyPress.
41
  if ( defined( 'BP_PLATFORM_VERSION' ) ) { // BuddyBoss
42
- $pro_placements['buddypress'] = array(
43
  'title' => __( 'BuddyBoss Content', 'advanced-ads' ),
44
  'description' => __( 'Display ads on BuddyBoss related pages.', 'advanced-ads' ),
45
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/buddyboss-icon.png',
46
- );
47
  } elseif ( class_exists( 'BuddyPress', false ) ) { // BuddyPress
48
- $pro_placements['buddypress'] = array(
49
  'title' => __( 'BuddyPress Content', 'advanced-ads' ),
50
  'description' => __( 'Display ads on BuddyPress related pages.', 'advanced-ads' ),
51
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/buddypress-icon.png',
52
- );
53
  }
54
  // bbPress.
55
  if ( class_exists( 'bbPress', false ) ) {
56
- $pro_placements['bbpress'] = array(
57
  'title' => __( 'bbPress Content', 'advanced-ads' ),
58
  'description' => __( 'Display ads in content created with bbPress.', 'advanced-ads' ),
59
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/bbpress-reply.png',
60
- );
61
  }
62
 
63
  ?><h4><?php Advanced_Ads_Admin_Upgrades::pro_feature_link( 'upgrades-pro-placements' ); ?></h4>
@@ -70,13 +70,13 @@ if ( class_exists( 'bbPress', false ) ) {
70
  $image = '<strong>' . $_place['title'] . '</strong><br/><p class="description">' . $_place['description'] . '</p>';
71
  endif;
72
  ?>
73
- <div class="advads-placement-type"><label class="advads-button advads-pro-link"><span class="advads-button-text">
74
  <?php
75
  // phpcs:ignore
76
  echo $image;
77
  ?>
78
- </label></span>
79
- <p class="advads-placement-description">
80
  <strong><?php echo esc_html( $_place['title'] ); ?></strong><br/><?php echo esc_html( $_place['description'] ); ?></p>
81
  </div>
82
  <?php
1
  <?php
2
  // todo: move the array somewhere else.
3
+ $pro_placements = [
4
  // ad injection on random position.
5
+ 'post_content_random' => [
6
  'title' => __( 'Random Paragraph', 'advanced-ads' ),
7
  'description' => __( 'After a random paragraph in the main content.', 'advanced-ads' ),
8
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-random.png',
9
+ ],
10
  // ad injection above the post headline.
11
+ 'post_above_headline' => [
12
  'title' => __( 'Above Headline', 'advanced-ads' ),
13
  'description' => __( 'Above the main headline on the page (&lt;h1&gt;).', 'advanced-ads' ),
14
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-above-headline.png',
15
+ ],
16
  // ad injection in the middle of a post.
17
+ 'post_content_middle' => [
18
  'title' => __( 'Content Middle', 'advanced-ads' ),
19
  'description' => __( 'In the middle of the main content based on the number of paragraphs.', 'advanced-ads' ),
20
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-middle.png',
21
+ ],
22
  // ad injection at a hand selected element in the frontend.
23
+ 'custom_position' => [
24
  'title' => __( 'Custom Position', 'advanced-ads' ),
25
  'description' => __( 'Attach the ad to any element in the frontend.', 'advanced-ads' ),
26
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/custom-position.png',
27
+ ],
28
  // ad injection between posts on archive and category pages.
29
+ 'archive_pages' => [
30
  'title' => __( 'Post Lists', 'advanced-ads' ),
31
  'description' => __( 'Display the ad between posts on post lists, e.g. home, archives, search etc.', 'advanced-ads' ),
32
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/post-list.png',
33
+ ],
34
+ 'background' => [
35
  'title' => __( 'Background Ad', 'advanced-ads' ),
36
  'description' => __( 'Background of the website behind the main wrapper.', 'advanced-ads' ),
37
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/background.png',
38
+ ],
39
+ ];
40
  // BuddyBoss & BuddyPress.
41
  if ( defined( 'BP_PLATFORM_VERSION' ) ) { // BuddyBoss
42
+ $pro_placements['buddypress'] = [
43
  'title' => __( 'BuddyBoss Content', 'advanced-ads' ),
44
  'description' => __( 'Display ads on BuddyBoss related pages.', 'advanced-ads' ),
45
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/buddyboss-icon.png',
46
+ ];
47
  } elseif ( class_exists( 'BuddyPress', false ) ) { // BuddyPress
48
+ $pro_placements['buddypress'] = [
49
  'title' => __( 'BuddyPress Content', 'advanced-ads' ),
50
  'description' => __( 'Display ads on BuddyPress related pages.', 'advanced-ads' ),
51
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/buddypress-icon.png',
52
+ ];
53
  }
54
  // bbPress.
55
  if ( class_exists( 'bbPress', false ) ) {
56
+ $pro_placements['bbpress'] = [
57
  'title' => __( 'bbPress Content', 'advanced-ads' ),
58
  'description' => __( 'Display ads in content created with bbPress.', 'advanced-ads' ),
59
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/bbpress-reply.png',
60
+ ];
61
  }
62
 
63
  ?><h4><?php Advanced_Ads_Admin_Upgrades::pro_feature_link( 'upgrades-pro-placements' ); ?></h4>
70
  $image = '<strong>' . $_place['title'] . '</strong><br/><p class="description">' . $_place['description'] . '</p>';
71
  endif;
72
  ?>
73
+ <div class="advads-form-type"><label class="advads-button advads-pro-link"><span class="advads-button-text">
74
  <?php
75
  // phpcs:ignore
76
  echo $image;
77
  ?>
78
+ </span></label>
79
+ <p class="advads-form-description">
80
  <strong><?php echo esc_html( $_place['title'] ); ?></strong><br/><?php echo esc_html( $_place['description'] ); ?></p>
81
  </div>
82
  <?php
advanced-ads.php CHANGED
@@ -12,7 +12,7 @@
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: https://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
- * Version: 1.37.2
16
  * Author: Thomas Maier, Advanced Ads GmbH
17
  * Author URI: https://wpadvancedads.com
18
  * Text Domain: advanced-ads
@@ -39,7 +39,7 @@ define( 'ADVADS_BASE_DIR', dirname( ADVADS_BASE ) ); // directory of the plugin
39
  // general and global slug, e.g. to store options in WP.
40
  define( 'ADVADS_SLUG', 'advanced-ads' );
41
  define( 'ADVADS_URL', 'https://wpadvancedads.com/' );
42
- define( 'ADVADS_VERSION', '1.37.2' );
43
 
44
  // Autoloading, modules and functions.
45
 
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: https://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
+ * Version: 1.38.0
16
  * Author: Thomas Maier, Advanced Ads GmbH
17
  * Author URI: https://wpadvancedads.com
18
  * Text Domain: advanced-ads
39
  // general and global slug, e.g. to store options in WP.
40
  define( 'ADVADS_SLUG', 'advanced-ads' );
41
  define( 'ADVADS_URL', 'https://wpadvancedads.com/' );
42
+ define( 'ADVADS_VERSION', '1.38.0' );
43
 
44
  // Autoloading, modules and functions.
45
 
changelog.txt CHANGED
@@ -1,5 +1,13 @@
1
  == Changelog ==
2
 
 
 
 
 
 
 
 
 
3
  = 1.37.2 (November 2, 2022) =
4
 
5
  - Improvement: add manual links to display and visitor conditions
1
  == Changelog ==
2
 
3
+ = 1.38.0 (November 22, 2022) =
4
+
5
+ - Improvement: add support for multibyte cookies in "advads.get/set_cookie" functions
6
+ - Improvement: update routine to remove all data on uninstall
7
+ - Improvement: unify the behavior and look of the group and placement lists
8
+ - Fix: serialize post meta in conditions to do string comparisons
9
+ - Fix: ensure the filters for placements work
10
+
11
  = 1.37.2 (November 2, 2022) =
12
 
13
  - Improvement: add manual links to display and visitor conditions
classes/ad-ajax.php CHANGED
@@ -11,11 +11,11 @@ class Advanced_Ads_Ajax {
11
  * Advanced_Ads_Ajax constructor.
12
  */
13
  private function __construct() {
14
- add_action( 'wp_ajax_advads_ad_select', array( $this, 'advads_ajax_ad_select' ) );
15
- add_action( 'wp_ajax_nopriv_advads_ad_select', array( $this, 'advads_ajax_ad_select' ) );
16
- add_action( 'wp_ajax_advads-ad-health-notice-push', array( $this, 'ad_health_notice_push' ) );
17
- add_action( 'wp_ajax_nopriv_advads-ad-health-notice-push', array( $this, 'ad_health_notice_push' ) );
18
- add_action( 'wp_ajax_advads-ad-frontend-notice-update', array( $this, 'frontend_notice_update' ) );
19
  }
20
 
21
  /**
@@ -59,9 +59,9 @@ class Advanced_Ads_Ajax {
59
 
60
  $defered_ads = isset( $_REQUEST['deferedAds'] ) ? $_REQUEST['deferedAds'] : null;
61
  if ( $defered_ads ) { // Load all ajax ads with a single request.
62
- $response = array();
63
 
64
- $requests_by_blog = array();
65
  foreach ( (array) $defered_ads as $request ) {
66
  $blog_id = isset( $request['blog_id'] ) ? $request['blog_id'] : get_current_blog_id();
67
  $requests_by_blog[ $blog_id ][] = $request;
@@ -104,7 +104,7 @@ class Advanced_Ads_Ajax {
104
  $methods = $selector->get_methods();
105
  $method = isset( $request['ad_method'] ) ? (string) $request['ad_method'] : null;
106
  $id = isset( $request['ad_id'] ) ? (string) $request['ad_id'] : null;
107
- $arguments = isset( $request['ad_args'] ) ? $request['ad_args'] : array();
108
  if ( is_string( $arguments ) ) {
109
  $arguments = stripslashes( $arguments );
110
  $arguments = json_decode( $arguments, true );
@@ -116,10 +116,10 @@ class Advanced_Ads_Ajax {
116
 
117
  if ( ! array_key_exists( $method, $methods ) || empty( $id ) ) {
118
  // Report error.
119
- return array(
120
  'status' => 'error',
121
  'message' => 'No valid ID or METHOD found.',
122
- );
123
  }
124
 
125
  /**
@@ -133,33 +133,33 @@ class Advanced_Ads_Ajax {
133
  $advads = Advanced_Ads::get_instance();
134
  $previous_ads = $advads->current_ads;
135
 
136
- add_filter( 'advanced-ads-can-display', array( $this, 'can_display_by_consent' ), 10, 2 );
137
  $content = $selector->get_ad_by_method( $id, $method, $arguments );
138
 
139
  if ( empty( $content ) ) {
140
- return array(
141
  'status' => 'error',
142
  'message' => 'No displayable ad found for privacy settings.',
143
- );
144
  }
145
 
146
- $response = array(
147
  'status' => 'success',
148
  'item' => $content,
149
  'id' => $id,
150
  'method' => $method,
151
  'ads' => array_slice( $advads->current_ads, count( $previous_ads ) ),
152
  'blog_id' => get_current_blog_id(),
153
- );
154
 
155
  return apply_filters(
156
  'advanced-ads-cache-busting-item',
157
  $response,
158
- array(
159
  'id' => $id,
160
  'method' => $method,
161
  'args' => $arguments,
162
- )
163
  );
164
  }
165
 
@@ -175,7 +175,7 @@ class Advanced_Ads_Ajax {
175
  }
176
 
177
  $key = ( ! empty( $_REQUEST['key'] ) ) ? esc_attr( $_REQUEST['key'] ) : false;
178
- $attr = ( ! empty( $_REQUEST['attr'] ) && is_array( $_REQUEST['attr'] ) ) ? $_REQUEST['attr'] : array();
179
 
180
  // Update or new entry?
181
  if ( isset( $attr['mode'] ) && 'update' === $attr['mode'] ) {
@@ -199,7 +199,7 @@ class Advanced_Ads_Ajax {
199
  }
200
 
201
  $key = ( ! empty( $_REQUEST['key'] ) ) ? esc_attr( $_REQUEST['key'] ) : false;
202
- $attr = ( ! empty( $_REQUEST['attr'] ) && is_array( $_REQUEST['attr'] ) ) ? $_REQUEST['attr'] : array();
203
 
204
  // Update or new entry?
205
  if ( isset( $attr['mode'] ) && 'update' === $attr['mode'] ) {
@@ -242,7 +242,7 @@ class Advanced_Ads_Ajax {
242
  $consent_state = sanitize_text_field( $_REQUEST['consent'] );
243
 
244
  // Consent is either given or not needed.
245
- if ( in_array( $consent_state, array( 'not_needed', 'accepted' ), true ) ) {
246
  return true;
247
  }
248
 
11
  * Advanced_Ads_Ajax constructor.
12
  */
13
  private function __construct() {
14
+ add_action( 'wp_ajax_advads_ad_select', [ $this, 'advads_ajax_ad_select' ] );
15
+ add_action( 'wp_ajax_nopriv_advads_ad_select', [ $this, 'advads_ajax_ad_select' ] );
16
+ add_action( 'wp_ajax_advads-ad-health-notice-push', [ $this, 'ad_health_notice_push' ] );
17
+ add_action( 'wp_ajax_nopriv_advads-ad-health-notice-push', [ $this, 'ad_health_notice_push' ] );
18
+ add_action( 'wp_ajax_advads-ad-frontend-notice-update', [ $this, 'frontend_notice_update' ] );
19
  }
20
 
21
  /**
59
 
60
  $defered_ads = isset( $_REQUEST['deferedAds'] ) ? $_REQUEST['deferedAds'] : null;
61
  if ( $defered_ads ) { // Load all ajax ads with a single request.
62
+ $response = [];
63
 
64
+ $requests_by_blog = [];
65
  foreach ( (array) $defered_ads as $request ) {
66
  $blog_id = isset( $request['blog_id'] ) ? $request['blog_id'] : get_current_blog_id();
67
  $requests_by_blog[ $blog_id ][] = $request;
104
  $methods = $selector->get_methods();
105
  $method = isset( $request['ad_method'] ) ? (string) $request['ad_method'] : null;
106
  $id = isset( $request['ad_id'] ) ? (string) $request['ad_id'] : null;
107
+ $arguments = isset( $request['ad_args'] ) ? $request['ad_args'] : [];
108
  if ( is_string( $arguments ) ) {
109
  $arguments = stripslashes( $arguments );
110
  $arguments = json_decode( $arguments, true );
116
 
117
  if ( ! array_key_exists( $method, $methods ) || empty( $id ) ) {
118
  // Report error.
119
+ return [
120
  'status' => 'error',
121
  'message' => 'No valid ID or METHOD found.',
122
+ ];
123
  }
124
 
125
  /**
133
  $advads = Advanced_Ads::get_instance();
134
  $previous_ads = $advads->current_ads;
135
 
136
+ add_filter( 'advanced-ads-can-display', [ $this, 'can_display_by_consent' ], 10, 2 );
137
  $content = $selector->get_ad_by_method( $id, $method, $arguments );
138
 
139
  if ( empty( $content ) ) {
140
+ return [
141
  'status' => 'error',
142
  'message' => 'No displayable ad found for privacy settings.',
143
+ ];
144
  }
145
 
146
+ $response = [
147
  'status' => 'success',
148
  'item' => $content,
149
  'id' => $id,
150
  'method' => $method,
151
  'ads' => array_slice( $advads->current_ads, count( $previous_ads ) ),
152
  'blog_id' => get_current_blog_id(),
153
+ ];
154
 
155
  return apply_filters(
156
  'advanced-ads-cache-busting-item',
157
  $response,
158
+ [
159
  'id' => $id,
160
  'method' => $method,
161
  'args' => $arguments,
162
+ ]
163
  );
164
  }
165
 
175
  }
176
 
177
  $key = ( ! empty( $_REQUEST['key'] ) ) ? esc_attr( $_REQUEST['key'] ) : false;
178
+ $attr = ( ! empty( $_REQUEST['attr'] ) && is_array( $_REQUEST['attr'] ) ) ? $_REQUEST['attr'] : [];
179
 
180
  // Update or new entry?
181
  if ( isset( $attr['mode'] ) && 'update' === $attr['mode'] ) {
199
  }
200
 
201
  $key = ( ! empty( $_REQUEST['key'] ) ) ? esc_attr( $_REQUEST['key'] ) : false;
202
+ $attr = ( ! empty( $_REQUEST['attr'] ) && is_array( $_REQUEST['attr'] ) ) ? $_REQUEST['attr'] : [];
203
 
204
  // Update or new entry?
205
  if ( isset( $attr['mode'] ) && 'update' === $attr['mode'] ) {
242
  $consent_state = sanitize_text_field( $_REQUEST['consent'] );
243
 
244
  // Consent is either given or not needed.
245
+ if ( in_array( $consent_state, [ 'not_needed', 'accepted' ], true ) ) {
246
  return true;
247
  }
248
 
classes/ad-debug.php CHANGED
@@ -26,9 +26,9 @@ class Advanced_Ads_Ad_Debug {
26
  $wrapper_id = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix() . mt_rand();
27
  }
28
 
29
- $content = array();
30
 
31
- if ( $ad->can_display( array( 'ignore_debugmode' => true ) ) ) {
32
  $content[] = __( 'The ad is displayed on the page', 'advanced-ads' );
33
  } else {
34
  $content[] = __( 'The ad is not displayed on the page', 'advanced-ads' );
@@ -146,7 +146,7 @@ class Advanced_Ads_Ad_Debug {
146
 
147
  $conditions = array_values( $options['conditions'] );
148
  $display_conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
149
- $the_query = Advanced_Ads_Display_Conditions::get_instance()->ad_select_args_callback( array() );
150
 
151
  ob_start();
152
  _e( 'Display Conditions', 'advanced-ads' ); ?>
@@ -177,7 +177,7 @@ class Advanced_Ads_Ad_Debug {
177
  break;
178
  case 'check_general':
179
  if ( isset( $the_query['wp_the_query'] ) && is_array( $the_query['wp_the_query'] ) ) {
180
- $ad_vars = ( isset( $_condition['value'] ) && is_array( $_condition['value'] ) ) ? $_condition['value'] : array();
181
 
182
  if ( in_array( 'is_front_page', $ad_vars ) ) {
183
  $ad_vars[] = 'is_home';
26
  $wrapper_id = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix() . mt_rand();
27
  }
28
 
29
+ $content = [];
30
 
31
+ if ( $ad->can_display( [ 'ignore_debugmode' => true ] ) ) {
32
  $content[] = __( 'The ad is displayed on the page', 'advanced-ads' );
33
  } else {
34
  $content[] = __( 'The ad is not displayed on the page', 'advanced-ads' );
146
 
147
  $conditions = array_values( $options['conditions'] );
148
  $display_conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
149
+ $the_query = Advanced_Ads_Display_Conditions::get_instance()->ad_select_args_callback( [] );
150
 
151
  ob_start();
152
  _e( 'Display Conditions', 'advanced-ads' ); ?>
177
  break;
178
  case 'check_general':
179
  if ( isset( $the_query['wp_the_query'] ) && is_array( $the_query['wp_the_query'] ) ) {
180
+ $ad_vars = ( isset( $_condition['value'] ) && is_array( $_condition['value'] ) ) ? $_condition['value'] : [];
181
 
182
  if ( in_array( 'is_front_page', $ad_vars ) ) {
183
  $ad_vars[] = 'is_home';
classes/ad-expiration.php CHANGED
@@ -22,7 +22,7 @@ class Advanced_Ads_Ad_Expiration {
22
  public function __construct( Advanced_Ads_Ad $ad ) {
23
  $this->ad = $ad;
24
 
25
- add_filter( 'advanced-ads-save-options', array( $this, 'save_expiration_date' ), 10, 2 );
26
  }
27
 
28
  /**
@@ -36,7 +36,7 @@ class Advanced_Ads_Ad_Expiration {
36
  }
37
 
38
  // if the ad is not trashed, but has a different status than expired, transition the status.
39
- if ( ! in_array( $this->ad->status, array( self::POST_STATUS, 'trash' ), true ) ) {
40
  $this->transition_post_status();
41
  }
42
 
@@ -69,10 +69,10 @@ class Advanced_Ads_Ad_Expiration {
69
  private function transition_post_status() {
70
  kses_remove_filters();
71
  wp_update_post(
72
- array(
73
  'ID' => $this->ad->id,
74
  'post_status' => self::POST_STATUS,
75
- )
76
  );
77
  kses_init_filters();
78
  }
@@ -81,10 +81,10 @@ class Advanced_Ads_Ad_Expiration {
81
  * Register custom post status for expired ads.
82
  */
83
  public static function register_post_status() {
84
- register_post_status( self::POST_STATUS, array(
85
  'label' => __( 'Expired', 'advanced-ads' ),
86
  'private' => true,
87
- ) );
88
  }
89
 
90
  /**
22
  public function __construct( Advanced_Ads_Ad $ad ) {
23
  $this->ad = $ad;
24
 
25
+ add_filter( 'advanced-ads-save-options', [ $this, 'save_expiration_date' ], 10, 2 );
26
  }
27
 
28
  /**
36
  }
37
 
38
  // if the ad is not trashed, but has a different status than expired, transition the status.
39
+ if ( ! in_array( $this->ad->status, [ self::POST_STATUS, 'trash' ], true ) ) {
40
  $this->transition_post_status();
41
  }
42
 
69
  private function transition_post_status() {
70
  kses_remove_filters();
71
  wp_update_post(
72
+ [
73
  'ID' => $this->ad->id,
74
  'post_status' => self::POST_STATUS,
75
+ ]
76
  );
77
  kses_init_filters();
78
  }
81
  * Register custom post status for expired ads.
82
  */
83
  public static function register_post_status() {
84
+ register_post_status( self::POST_STATUS, [
85
  'label' => __( 'Expired', 'advanced-ads' ),
86
  'private' => true,
87
+ ] );
88
  }
89
 
90
  /**
classes/ad-health-notices.php CHANGED
@@ -41,28 +41,28 @@ class Advanced_Ads_Ad_Health_Notices {
41
  *
42
  * @var array
43
  */
44
- public $notices = array();
45
 
46
  /**
47
  * All ignored notices
48
  *
49
  * @var array
50
  */
51
- public $ignore = array();
52
 
53
  /**
54
  * All displayed notices ($notices minus $hidden)
55
  *
56
  * @var array
57
  */
58
- public $displayed_notices = array();
59
 
60
  /**
61
  * Load default notices
62
  *
63
  * @var array
64
  */
65
- public $default_notices = array();
66
 
67
  /**
68
  * The last notice key saved
@@ -101,7 +101,7 @@ class Advanced_Ads_Ad_Health_Notices {
101
  }
102
 
103
  // load default notices.
104
- if ( array() === $this->default_notices ) {
105
  include ADVADS_BASE_PATH . '/admin/includes/ad-health-notices.php';
106
  $this->default_notices = $advanced_ads_ad_health_notices;
107
  }
@@ -114,10 +114,10 @@ class Advanced_Ads_Ad_Health_Notices {
114
  * needs to run after plugins_loaded with priority 10
115
  * current_screen seems like the perfect hook
116
  */
117
- add_action( 'current_screen', array( $this, 'run_checks' ), 20 );
118
 
119
  // add notification when an ad expires.
120
- add_action( 'advanced-ads-ad-expired', array( $this, 'ad_expired' ), 10, 2 );
121
  }
122
 
123
  /**
@@ -154,7 +154,7 @@ class Advanced_Ads_Ad_Health_Notices {
154
  $options = $this->options();
155
 
156
  // load notices from "notices".
157
- $this->notices = isset( $options['notices'] ) ? $options['notices'] : array();
158
 
159
  /**
160
  * Cleanup notices
@@ -181,7 +181,7 @@ class Advanced_Ads_Ad_Health_Notices {
181
  }
182
 
183
  // check if notice still exists.
184
- if ( array() === $this->get_notice_array_for_key( $_key ) ) {
185
  unset( $this->notices[ $_key ] );
186
  }
187
  }
@@ -191,7 +191,7 @@ class Advanced_Ads_Ad_Health_Notices {
191
  && isset( $_GET['advads-show-hidden-notices'] ) && 'true' === $_GET['advads-show-hidden-notices'] ) {
192
  $this->unignore();
193
  // remove the argument from the URL.
194
- add_filter( 'removable_query_args', array( $this, 'remove_query_vars_after_notice_update' ) );
195
  }
196
 
197
  // load hidden notices.
@@ -331,7 +331,7 @@ class Advanced_Ads_Ad_Health_Notices {
331
  * - append_text text added to the default message
332
  * - ad_id ID of an ad, attaches the link to the ad edit page to the message
333
  */
334
- public function add( $notice_key, $atts = array() ) {
335
 
336
  // stop here if notices are disabled.
337
  if ( empty( $notice_key ) || ! self::notices_enabled() ) {
@@ -348,7 +348,7 @@ class Advanced_Ads_Ad_Health_Notices {
348
  $options_before = $options = $this->options();
349
 
350
  // load notices from "queue".
351
- $notices = isset( $options['notices'] ) ? $options['notices'] : array();
352
 
353
  // check if notice_key was already saved, this prevents the same notice from showing up in different forms.
354
  if ( isset( $notices[ $notice_key ] ) ) {
@@ -356,7 +356,7 @@ class Advanced_Ads_Ad_Health_Notices {
356
  }
357
 
358
  // save the new notice key.
359
- $notices[ $notice_key ] = array();
360
 
361
  // save text, if given.
362
  if ( ! empty( $atts['text'] ) ) {
@@ -407,7 +407,7 @@ class Advanced_Ads_Ad_Health_Notices {
407
  * attributes:
408
  * - append_text – text added to the default message
409
  */
410
- public function update( $notice_key, $atts = array() ) {
411
 
412
  // stop here if notices are disabled.
413
  if ( empty( $notice_key ) || ! self::notices_enabled() ) {
@@ -420,7 +420,7 @@ class Advanced_Ads_Ad_Health_Notices {
420
  $options_before = $options;
421
 
422
  // load notices from "queue".
423
- $notices = isset( $options['notices'] ) ? $options['notices'] : array();
424
 
425
  // check if notice_key was already saved, this prevents the same notice from showing up in different forms.
426
  if ( ! isset( $notices[ $notice_key ] ) ) {
@@ -470,7 +470,7 @@ class Advanced_Ads_Ad_Health_Notices {
470
  // handle notices with a timeout.
471
  // set `closed` timestamp if the notice definition has a timeout information.
472
  if ( isset( $notice_array['timeout'] ) ) {
473
- $this->update( $notice_key, array( 'closed' => current_time( 'timestamp', 0 ) ) );
474
 
475
  return;
476
  }
@@ -536,7 +536,7 @@ class Advanced_Ads_Ad_Health_Notices {
536
  // get options.
537
  $options = $this->options();
538
  $options_before = $options;
539
- $ignored = isset( $options['ignore'] ) && is_array( $options['ignore'] ) ? $options['ignore'] : array();
540
 
541
  // adds notice key to ignore array if it doesn’t exist already.
542
  if ( false === array_search( $notice_key, $ignored, true ) ) {
@@ -565,7 +565,7 @@ class Advanced_Ads_Ad_Health_Notices {
565
  $options_before = $options;
566
 
567
  // empty ignore value.
568
- $options['ignore'] = array();
569
 
570
  // only update if changed.
571
  if ( $options_before !== $options ) {
@@ -613,7 +613,7 @@ class Advanced_Ads_Ad_Health_Notices {
613
  $notice_array = $this->get_notice_array_for_key( $_notice_key );
614
 
615
  // remove the notice if key doesn’t exist anymore.
616
- if ( array() === $notice_array ) {
617
  $this->remove( $_notice_key );
618
  }
619
 
@@ -678,10 +678,10 @@ class Advanced_Ads_Ad_Health_Notices {
678
  */
679
  public function options() {
680
  if ( ! isset( $this->options ) ) {
681
- $this->options = get_option( ADVADS_SLUG . '-ad-health-notices', array() );
682
  }
683
  if ( ! is_array( $this->options ) ) {
684
- $this->options = array();
685
  }
686
 
687
  return $this->options;
@@ -694,7 +694,7 @@ class Advanced_Ads_Ad_Health_Notices {
694
  */
695
  public function update_options( array $options ) {
696
  // do not allow to clear options.
697
- if ( array() === $options ) {
698
  return;
699
  }
700
 
@@ -723,7 +723,7 @@ class Advanced_Ads_Ad_Health_Notices {
723
  $options = $this->options();
724
  $options_before = $options;
725
 
726
- $ignore_before = isset( $options['ignore'] ) ? $options['ignore'] : array();
727
 
728
  // get keys from notices.
729
  $notice_keys = array_keys( $this->notices );
@@ -764,7 +764,7 @@ class Advanced_Ads_Ad_Health_Notices {
764
  public function get_visible_notices_by_type( $type = 'problem' ) {
765
 
766
  // get all notices with a given type.
767
- $notices_by_type = array();
768
 
769
  foreach ( $this->notices as $_key => $_notice ) {
770
  $notice_array = $this->get_notice_array_for_key( $_key );
@@ -822,7 +822,7 @@ class Advanced_Ads_Ad_Health_Notices {
822
  // check if there is an original key.
823
  $orig_key = isset( $this->notices[ $notice_key ]['orig_key'] ) ? $this->notices[ $notice_key ]['orig_key'] : $notice_key;
824
 
825
- return isset( $this->default_notices[ $orig_key ] ) ? $this->default_notices[ $orig_key ] : array();
826
  }
827
 
828
  /**
@@ -835,10 +835,10 @@ class Advanced_Ads_Ad_Health_Notices {
835
  $id = ! empty( $ad_id ) ? absint( $ad_id ) : 0;
836
  $this->update(
837
  'ad_expired',
838
- array(
839
  'append_key' => $id,
840
  'ad_id' => $id,
841
- )
842
  );
843
  }
844
 
41
  *
42
  * @var array
43
  */
44
+ public $notices = [];
45
 
46
  /**
47
  * All ignored notices
48
  *
49
  * @var array
50
  */
51
+ public $ignore = [];
52
 
53
  /**
54
  * All displayed notices ($notices minus $hidden)
55
  *
56
  * @var array
57
  */
58
+ public $displayed_notices = [];
59
 
60
  /**
61
  * Load default notices
62
  *
63
  * @var array
64
  */
65
+ public $default_notices = [];
66
 
67
  /**
68
  * The last notice key saved
101
  }
102
 
103
  // load default notices.
104
+ if ( [] === $this->default_notices ) {
105
  include ADVADS_BASE_PATH . '/admin/includes/ad-health-notices.php';
106
  $this->default_notices = $advanced_ads_ad_health_notices;
107
  }
114
  * needs to run after plugins_loaded with priority 10
115
  * current_screen seems like the perfect hook
116
  */
117
+ add_action( 'current_screen', [ $this, 'run_checks' ], 20 );
118
 
119
  // add notification when an ad expires.
120
+ add_action( 'advanced-ads-ad-expired', [ $this, 'ad_expired' ], 10, 2 );
121
  }
122
 
123
  /**
154
  $options = $this->options();
155
 
156
  // load notices from "notices".
157
+ $this->notices = isset( $options['notices'] ) ? $options['notices'] : [];
158
 
159
  /**
160
  * Cleanup notices
181
  }
182
 
183
  // check if notice still exists.
184
+ if ( [] === $this->get_notice_array_for_key( $_key ) ) {
185
  unset( $this->notices[ $_key ] );
186
  }
187
  }
191
  && isset( $_GET['advads-show-hidden-notices'] ) && 'true' === $_GET['advads-show-hidden-notices'] ) {
192
  $this->unignore();
193
  // remove the argument from the URL.
194
+ add_filter( 'removable_query_args', [ $this, 'remove_query_vars_after_notice_update' ] );
195
  }
196
 
197
  // load hidden notices.
331
  * - append_text text added to the default message
332
  * - ad_id ID of an ad, attaches the link to the ad edit page to the message
333
  */
334
+ public function add( $notice_key, $atts = [] ) {
335
 
336
  // stop here if notices are disabled.
337
  if ( empty( $notice_key ) || ! self::notices_enabled() ) {
348
  $options_before = $options = $this->options();
349
 
350
  // load notices from "queue".
351
+ $notices = isset( $options['notices'] ) ? $options['notices'] : [];
352
 
353
  // check if notice_key was already saved, this prevents the same notice from showing up in different forms.
354
  if ( isset( $notices[ $notice_key ] ) ) {
356
  }
357
 
358
  // save the new notice key.
359
+ $notices[ $notice_key ] = [];
360
 
361
  // save text, if given.
362
  if ( ! empty( $atts['text'] ) ) {
407
  * attributes:
408
  * - append_text – text added to the default message
409
  */
410
+ public function update( $notice_key, $atts = [] ) {
411
 
412
  // stop here if notices are disabled.
413
  if ( empty( $notice_key ) || ! self::notices_enabled() ) {
420
  $options_before = $options;
421
 
422
  // load notices from "queue".
423
+ $notices = isset( $options['notices'] ) ? $options['notices'] : [];
424
 
425
  // check if notice_key was already saved, this prevents the same notice from showing up in different forms.
426
  if ( ! isset( $notices[ $notice_key ] ) ) {
470
  // handle notices with a timeout.
471
  // set `closed` timestamp if the notice definition has a timeout information.
472
  if ( isset( $notice_array['timeout'] ) ) {
473
+ $this->update( $notice_key, [ 'closed' => current_time( 'timestamp', 0 ) ] );
474
 
475
  return;
476
  }
536
  // get options.
537
  $options = $this->options();
538
  $options_before = $options;
539
+ $ignored = isset( $options['ignore'] ) && is_array( $options['ignore'] ) ? $options['ignore'] : [];
540
 
541
  // adds notice key to ignore array if it doesn’t exist already.
542
  if ( false === array_search( $notice_key, $ignored, true ) ) {
565
  $options_before = $options;
566
 
567
  // empty ignore value.
568
+ $options['ignore'] = [];
569
 
570
  // only update if changed.
571
  if ( $options_before !== $options ) {
613
  $notice_array = $this->get_notice_array_for_key( $_notice_key );
614
 
615
  // remove the notice if key doesn’t exist anymore.
616
+ if ( [] === $notice_array ) {
617
  $this->remove( $_notice_key );
618
  }
619
 
678
  */
679
  public function options() {
680
  if ( ! isset( $this->options ) ) {
681
+ $this->options = get_option( ADVADS_SLUG . '-ad-health-notices', [] );
682
  }
683
  if ( ! is_array( $this->options ) ) {
684
+ $this->options = [];
685
  }
686
 
687
  return $this->options;
694
  */
695
  public function update_options( array $options ) {
696
  // do not allow to clear options.
697
+ if ( [] === $options ) {
698
  return;
699
  }
700
 
723
  $options = $this->options();
724
  $options_before = $options;
725
 
726
+ $ignore_before = isset( $options['ignore'] ) ? $options['ignore'] : [];
727
 
728
  // get keys from notices.
729
  $notice_keys = array_keys( $this->notices );
764
  public function get_visible_notices_by_type( $type = 'problem' ) {
765
 
766
  // get all notices with a given type.
767
+ $notices_by_type = [];
768
 
769
  foreach ( $this->notices as $_key => $_notice ) {
770
  $notice_array = $this->get_notice_array_for_key( $_key );
822
  // check if there is an original key.
823
  $orig_key = isset( $this->notices[ $notice_key ]['orig_key'] ) ? $this->notices[ $notice_key ]['orig_key'] : $notice_key;
824
 
825
+ return isset( $this->default_notices[ $orig_key ] ) ? $this->default_notices[ $orig_key ] : [];
826
  }
827
 
828
  /**
835
  $id = ! empty( $ad_id ) ? absint( $ad_id ) : 0;
836
  $this->update(
837
  'ad_expired',
838
+ [
839
  'append_key' => $id,
840
  'ad_id' => $id,
841
+ ]
842
  );
843
  }
844
 
classes/ad-model.php CHANGED
@@ -85,12 +85,12 @@ class Advanced_Ads_Model {
85
  * @param array $args WP_Query arguments that are more specific that default.
86
  * @return array $ads array with post objects.
87
  */
88
- public function get_ads( $args = array() ) {
89
  // add default WP_Query arguments.
90
  $args['post_type'] = Advanced_Ads::POST_TYPE_SLUG;
91
  $args['posts_per_page'] = -1;
92
  if ( empty( $args['post_status'] ) ) {
93
- $args['post_status'] = array( 'publish', 'future' ); }
94
  $ads = new WP_Query( $args );
95
 
96
  return $ads->posts;
@@ -104,7 +104,7 @@ class Advanced_Ads_Model {
104
  * @return array array with ad groups
105
  * @link http://codex.wordpress.org/Function_Reference/get_terms
106
  */
107
- public function get_ad_groups( $args = array() ) {
108
  $args['hide_empty'] = isset( $args['hide_empty'] ) ? $args['hide_empty'] : false; // display groups without any ads.
109
 
110
  return get_terms( Advanced_Ads::AD_GROUP_TAXONOMY, $args );
@@ -119,11 +119,11 @@ class Advanced_Ads_Model {
119
  public function get_ad_placements_array() {
120
 
121
  if ( ! isset( $this->ad_placements ) ) {
122
- $this->ad_placements = get_option( 'advads-ads-placements', array() );
123
 
124
  // load default array if not saved yet.
125
  if ( ! is_array( $this->ad_placements ) ) {
126
- $this->ad_placements = array();
127
  }
128
 
129
  $this->ad_placements = apply_filters( 'advanced-ads-get-ad-placements-array', $this->ad_placements );
85
  * @param array $args WP_Query arguments that are more specific that default.
86
  * @return array $ads array with post objects.
87
  */
88
+ public function get_ads( $args = [] ) {
89
  // add default WP_Query arguments.
90
  $args['post_type'] = Advanced_Ads::POST_TYPE_SLUG;
91
  $args['posts_per_page'] = -1;
92
  if ( empty( $args['post_status'] ) ) {
93
+ $args['post_status'] = [ 'publish', 'future' ]; }
94
  $ads = new WP_Query( $args );
95
 
96
  return $ads->posts;
104
  * @return array array with ad groups
105
  * @link http://codex.wordpress.org/Function_Reference/get_terms
106
  */
107
+ public function get_ad_groups( $args = [] ) {
108
  $args['hide_empty'] = isset( $args['hide_empty'] ) ? $args['hide_empty'] : false; // display groups without any ads.
109
 
110
  return get_terms( Advanced_Ads::AD_GROUP_TAXONOMY, $args );
119
  public function get_ad_placements_array() {
120
 
121
  if ( ! isset( $this->ad_placements ) ) {
122
+ $this->ad_placements = get_option( 'advads-ads-placements', [] );
123
 
124
  // load default array if not saved yet.
125
  if ( ! is_array( $this->ad_placements ) ) {
126
+ $this->ad_placements = [];
127
  }
128
 
129
  $this->ad_placements = apply_filters( 'advanced-ads-get-ad-placements-array', $this->ad_placements );
classes/ad-select.php CHANGED
@@ -52,11 +52,11 @@ class Advanced_Ads_Select {
52
  public function get_methods()
53
  {
54
  if ( ! isset($this->methods) ) {
55
- $methods = array(
56
- self::AD => array( $this, 'get_ad_by_id' ),
57
- self::GROUP => array( $this, 'get_ad_by_group' ),
58
- self::PLACEMENT => array( $this, 'get_ad_by_placement' ),
59
- );
60
 
61
  $this->methods = apply_filters( 'advanced-ads-ad-select-methods', $methods );
62
  }
@@ -72,7 +72,7 @@ class Advanced_Ads_Select {
72
  *
73
  * @return array
74
  */
75
- public function get_ad_arguments( $method, $id, $args = array() )
76
  {
77
  $args = (array) $args;
78
 
@@ -87,7 +87,7 @@ class Advanced_Ads_Select {
87
  return $args;
88
  }
89
 
90
- public function get_ad_by_method( $id, $method, $args = array() ) {
91
 
92
  $methods = $this->get_methods();
93
  if ( ! isset($methods[ $method ]) ) {
52
  public function get_methods()
53
  {
54
  if ( ! isset($this->methods) ) {
55
+ $methods = [
56
+ self::AD => [ $this, 'get_ad_by_id' ],
57
+ self::GROUP => [ $this, 'get_ad_by_group' ],
58
+ self::PLACEMENT => [ $this, 'get_ad_by_placement' ],
59
+ ];
60
 
61
  $this->methods = apply_filters( 'advanced-ads-ad-select-methods', $methods );
62
  }
72
  *
73
  * @return array
74
  */
75
+ public function get_ad_arguments( $method, $id, $args = [] )
76
  {
77
  $args = (array) $args;
78
 
87
  return $args;
88
  }
89
 
90
+ public function get_ad_by_method( $id, $method, $args = [] ) {
91
 
92
  $methods = $this->get_methods();
93
  if ( ! isset($methods[ $method ]) ) {
classes/ad.php CHANGED
@@ -101,7 +101,7 @@ class Advanced_Ads_Ad {
101
  *
102
  * @var array $conditions display and visitor conditions.
103
  */
104
- public $conditions = array();
105
 
106
  /**
107
  * Status of the ad (e.g. publish, pending)
@@ -129,7 +129,7 @@ class Advanced_Ads_Ad {
129
  *
130
  * @var array $args
131
  */
132
- public $args = array();
133
 
134
  /**
135
  * Multidimensional array contains information about the wrapper
@@ -137,7 +137,7 @@ class Advanced_Ads_Ad {
137
  *
138
  * @var array $wrapper options of the ad wrapper.
139
  */
140
- public $wrapper = array();
141
 
142
  /**
143
  * Will the ad be tracked?
@@ -193,9 +193,9 @@ class Advanced_Ads_Ad {
193
  * @param int $id id of the ad.
194
  * @param array $args additional arguments.
195
  */
196
- public function __construct( $id, $args = array() ) {
197
  $this->id = (int) $id;
198
- $this->args = is_array( $args ) ? $args : array();
199
 
200
  // whether the ad will be tracked.
201
  $this->global_output = isset( $this->args['global_output'] ) ? (bool) $this->args['global_output'] : true;
@@ -208,7 +208,7 @@ class Advanced_Ads_Ad {
208
  }
209
 
210
  // dynamically add sanitize filters for condition types.
211
- $_types = array();
212
  // -TODO use model
213
  $advanced_ads_ad_conditions = Advanced_Ads::get_ad_conditions();
214
  foreach ( $advanced_ads_ad_conditions as $_condition ) {
@@ -220,7 +220,7 @@ class Advanced_Ads_Ad {
220
  // -TODO might be faster to use __call() method or isset()-test class method array
221
  $method_name = 'sanitize_condition_' . $_type;
222
  if ( method_exists( $this, $method_name ) ) {
223
- add_filter( 'advanced-ads-sanitize-condition-' . $_type, array( $this, $method_name ), 10, 1 );
224
  } elseif ( function_exists( 'advads_sanitize_condition_' . $_type ) ) {
225
  // check for public function to sanitize this.
226
  add_filter( 'advanced-ads-sanitize-condition-' . $_type, 'advads_sanitize_condition_' . $_type, 10, 1 );
@@ -284,7 +284,7 @@ class Advanced_Ads_Ad {
284
  $this->wrapper = apply_filters( 'advanced-ads-set-wrapper', $this->wrapper, $this );
285
  // add unique wrapper id.
286
  if ( is_array( $this->wrapper )
287
- && array() !== $this->wrapper
288
  && ! isset( $this->wrapper['id'] ) ) {
289
  // create unique id if not yet given.
290
  $this->wrapper['id'] = $this->create_wrapper_id();
@@ -309,7 +309,7 @@ class Advanced_Ads_Ad {
309
  $meta = get_post_meta( $this->id, self::$options_meta_field, true );
310
  if ( $meta && is_array( $meta ) ) {
311
  // merge meta with arguments given on ad load.
312
- $this->options = Advanced_Ads_Utils::merge_deep_array( array( $meta, $this->args ) );
313
  } else {
314
  // load arguments given on ad load.
315
  $this->options = $this->args;
@@ -318,10 +318,10 @@ class Advanced_Ads_Ad {
318
  if ( isset( $this->options['change-ad'] ) ) {
319
  // some options was provided by the user.
320
  $this->options = Advanced_Ads_Utils::merge_deep_array(
321
- array(
322
  $this->options,
323
  $this->options['change-ad'],
324
- )
325
  );
326
  }
327
  }
@@ -388,7 +388,7 @@ class Advanced_Ads_Ad {
388
  * @return string $output ad output
389
  * @since 1.0.0
390
  */
391
- public function output( $output_options = array() ) {
392
  if ( ! $this->is_ad ) {
393
  return '';
394
  }
@@ -411,12 +411,12 @@ class Advanced_Ads_Ad {
411
  // add the ad to the global output array.
412
  $advads = Advanced_Ads::get_instance();
413
  if ( $output_options['global_output'] ) {
414
- $new_ad = array(
415
  'type' => 'ad',
416
  'id' => $this->id,
417
  'title' => $this->title,
418
  'output' => $output,
419
- );
420
  // if ( method_exists( 'Advanced_Ads_Tracking_Plugin' , 'check_ad_tracking_enabled' ) ) {
421
  // if ( class_exists( 'Advanced_Ads_Tracking_Plugin', false ) ) {
422
  if ( defined( 'AAT_VERSION' ) && - 1 < version_compare( AAT_VERSION, '1.4.2' ) ) {
@@ -446,13 +446,13 @@ class Advanced_Ads_Ad {
446
  * @return bool $can_display true if can be displayed in frontend
447
  * @since 1.0.0
448
  */
449
- public function can_display( $check_options = array() ) {
450
  $check_options = wp_parse_args(
451
  $check_options,
452
- array(
453
  'passive_cache_busting' => false,
454
  'ignore_debugmode' => false,
455
- )
456
  );
457
 
458
  // prevent ad to show up through wp_head, if this is not a header placement.
@@ -503,7 +503,7 @@ class Advanced_Ads_Ad {
503
  return true;
504
  }
505
 
506
- $visitor_conditions = $this->options( 'visitors', array() );
507
  if ( empty( $visitor_conditions ) ) {
508
  return true;
509
  }
@@ -571,8 +571,8 @@ class Advanced_Ads_Ad {
571
  // remove slashes from content.
572
  $this->content = $this->prepare_content_to_save();
573
 
574
- $where = array( 'ID' => $this->id );
575
- $wpdb->update( $wpdb->posts, array( 'post_content' => $this->content ), $where );
576
 
577
  // clean post from object cache.
578
  clean_post_cache( $this->id );
@@ -619,7 +619,7 @@ class Advanced_Ads_Ad {
619
  public static function save_ad_options( $ad_id, array $options ) {
620
 
621
  // don’t allow to clear options by accident.
622
- if ( array() === $options ) {
623
  return;
624
  }
625
 
@@ -720,28 +720,28 @@ class Advanced_Ads_Ad {
720
  * @return array with sanitized conditions
721
  * @since 1.0.0
722
  */
723
- public function sanitize_conditions_on_save( $conditions = array() ) {
724
 
725
  global $advanced_ads_ad_conditions;
726
 
727
- if ( ! is_array( $conditions ) || array() === $conditions ) {
728
- return array();
729
  }
730
 
731
  foreach ( $conditions as $_key => $_condition ) {
732
  if ( 'postids' === $_key ) {
733
  // sanitize single post conditions
734
  if ( empty( $_condition['ids'] ) ) { // remove, if empty.
735
- $_condition['include'] = array();
736
- $_condition['exclude'] = array();
737
  } elseif ( isset( $_condition['method'] ) ) {
738
  switch ( $_condition['method'] ) {
739
  case 'include':
740
  $_condition['include'] = $_condition['ids'];
741
- $_condition['exclude'] = array();
742
  break;
743
  case 'exclude':
744
- $_condition['include'] = array();
745
  $_condition['exclude'] = $_condition['ids'];
746
  break;
747
  }
@@ -827,7 +827,7 @@ class Advanced_Ads_Ad {
827
  * @since 1.3
828
  */
829
  protected function load_wrapper_options() {
830
- $wrapper = array();
831
 
832
  $position = $this->options( 'output.position', '' );
833
  $use_placement_pos = false;
@@ -925,7 +925,7 @@ class Advanced_Ads_Ad {
925
 
926
  if ( $this->label && ! empty( $wrapper_options['style']['height'] ) ) {
927
  // Create another wrapper so that the label does not reduce the height of the ad wrapper.
928
- $height = array( 'style' => array( 'height' => $wrapper_options['style']['height'] ) );
929
  unset( $wrapper_options['style']['height'] );
930
  $ad_content = '<div' . Advanced_Ads_Utils::build_html_attributes( $height ) . '>' . $ad_content . '</div>';
931
  }
@@ -948,7 +948,7 @@ class Advanced_Ads_Ad {
948
  }
949
 
950
  if ( ( ! isset( $this->output['wrapper-id'] ) || '' === $this->output['wrapper-id'] )
951
- && array() === $wrapper_options || ! is_array( $wrapper_options ) ) {
952
  return $this->label . $ad_content;
953
  }
954
 
@@ -963,7 +963,7 @@ class Advanced_Ads_Ad {
963
  // build the box
964
  $wrapper = '<' . $wrapper_element . Advanced_Ads_Utils::build_html_attributes( array_merge(
965
  $wrapper_options,
966
- isset( $this->output['wrapper_attrs'] ) ? $this->output['wrapper_attrs'] : array()
967
  ) ) . '>';
968
  $wrapper .= $this->label;
969
  $wrapper .= apply_filters( 'advanced-ads-output-wrapper-before-content', '', $this );
@@ -1022,12 +1022,12 @@ class Advanced_Ads_Ad {
1022
  if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
1023
  // Remove placeholders.
1024
  $this->url = str_replace(
1025
- array(
1026
  '[POST_ID]',
1027
  '[POST_SLUG]',
1028
  '[CAT_SLUG]',
1029
  '[AD_ID]',
1030
- ),
1031
  '',
1032
  $this->url
1033
  );
101
  *
102
  * @var array $conditions display and visitor conditions.
103
  */
104
+ public $conditions = [];
105
 
106
  /**
107
  * Status of the ad (e.g. publish, pending)
129
  *
130
  * @var array $args
131
  */
132
+ public $args = [];
133
 
134
  /**
135
  * Multidimensional array contains information about the wrapper
137
  *
138
  * @var array $wrapper options of the ad wrapper.
139
  */
140
+ public $wrapper = [];
141
 
142
  /**
143
  * Will the ad be tracked?
193
  * @param int $id id of the ad.
194
  * @param array $args additional arguments.
195
  */
196
+ public function __construct( $id, $args = [] ) {
197
  $this->id = (int) $id;
198
+ $this->args = is_array( $args ) ? $args : [];
199
 
200
  // whether the ad will be tracked.
201
  $this->global_output = isset( $this->args['global_output'] ) ? (bool) $this->args['global_output'] : true;
208
  }
209
 
210
  // dynamically add sanitize filters for condition types.
211
+ $_types = [];
212
  // -TODO use model
213
  $advanced_ads_ad_conditions = Advanced_Ads::get_ad_conditions();
214
  foreach ( $advanced_ads_ad_conditions as $_condition ) {
220
  // -TODO might be faster to use __call() method or isset()-test class method array
221
  $method_name = 'sanitize_condition_' . $_type;
222
  if ( method_exists( $this, $method_name ) ) {
223
+ add_filter( 'advanced-ads-sanitize-condition-' . $_type, [ $this, $method_name ], 10, 1 );
224
  } elseif ( function_exists( 'advads_sanitize_condition_' . $_type ) ) {
225
  // check for public function to sanitize this.
226
  add_filter( 'advanced-ads-sanitize-condition-' . $_type, 'advads_sanitize_condition_' . $_type, 10, 1 );
284
  $this->wrapper = apply_filters( 'advanced-ads-set-wrapper', $this->wrapper, $this );
285
  // add unique wrapper id.
286
  if ( is_array( $this->wrapper )
287
+ && [] !== $this->wrapper
288
  && ! isset( $this->wrapper['id'] ) ) {
289
  // create unique id if not yet given.
290
  $this->wrapper['id'] = $this->create_wrapper_id();
309
  $meta = get_post_meta( $this->id, self::$options_meta_field, true );
310
  if ( $meta && is_array( $meta ) ) {
311
  // merge meta with arguments given on ad load.
312
+ $this->options = Advanced_Ads_Utils::merge_deep_array( [ $meta, $this->args ] );
313
  } else {
314
  // load arguments given on ad load.
315
  $this->options = $this->args;
318
  if ( isset( $this->options['change-ad'] ) ) {
319
  // some options was provided by the user.
320
  $this->options = Advanced_Ads_Utils::merge_deep_array(
321
+ [
322
  $this->options,
323
  $this->options['change-ad'],
324
+ ]
325
  );
326
  }
327
  }
388
  * @return string $output ad output
389
  * @since 1.0.0
390
  */
391
+ public function output( $output_options = [] ) {
392
  if ( ! $this->is_ad ) {
393
  return '';
394
  }
411
  // add the ad to the global output array.
412
  $advads = Advanced_Ads::get_instance();
413
  if ( $output_options['global_output'] ) {
414
+ $new_ad = [
415
  'type' => 'ad',
416
  'id' => $this->id,
417
  'title' => $this->title,
418
  'output' => $output,
419
+ ];
420
  // if ( method_exists( 'Advanced_Ads_Tracking_Plugin' , 'check_ad_tracking_enabled' ) ) {
421
  // if ( class_exists( 'Advanced_Ads_Tracking_Plugin', false ) ) {
422
  if ( defined( 'AAT_VERSION' ) && - 1 < version_compare( AAT_VERSION, '1.4.2' ) ) {
446
  * @return bool $can_display true if can be displayed in frontend
447
  * @since 1.0.0
448
  */
449
+ public function can_display( $check_options = [] ) {
450
  $check_options = wp_parse_args(
451
  $check_options,
452
+ [
453
  'passive_cache_busting' => false,
454
  'ignore_debugmode' => false,
455
+ ]
456
  );
457
 
458
  // prevent ad to show up through wp_head, if this is not a header placement.
503
  return true;
504
  }
505
 
506
+ $visitor_conditions = $this->options( 'visitors', [] );
507
  if ( empty( $visitor_conditions ) ) {
508
  return true;
509
  }
571
  // remove slashes from content.
572
  $this->content = $this->prepare_content_to_save();
573
 
574
+ $where = [ 'ID' => $this->id ];
575
+ $wpdb->update( $wpdb->posts, [ 'post_content' => $this->content ], $where );
576
 
577
  // clean post from object cache.
578
  clean_post_cache( $this->id );
619
  public static function save_ad_options( $ad_id, array $options ) {
620
 
621
  // don’t allow to clear options by accident.
622
+ if ( [] === $options ) {
623
  return;
624
  }
625
 
720
  * @return array with sanitized conditions
721
  * @since 1.0.0
722
  */
723
+ public function sanitize_conditions_on_save( $conditions = [] ) {
724
 
725
  global $advanced_ads_ad_conditions;
726
 
727
+ if ( ! is_array( $conditions ) || [] === $conditions ) {
728
+ return [];
729
  }
730
 
731
  foreach ( $conditions as $_key => $_condition ) {
732
  if ( 'postids' === $_key ) {
733
  // sanitize single post conditions
734
  if ( empty( $_condition['ids'] ) ) { // remove, if empty.
735
+ $_condition['include'] = [];
736
+ $_condition['exclude'] = [];
737
  } elseif ( isset( $_condition['method'] ) ) {
738
  switch ( $_condition['method'] ) {
739
  case 'include':
740
  $_condition['include'] = $_condition['ids'];
741
+ $_condition['exclude'] = [];
742
  break;
743
  case 'exclude':
744
+ $_condition['include'] = [];
745
  $_condition['exclude'] = $_condition['ids'];
746
  break;
747
  }
827
  * @since 1.3
828
  */
829
  protected function load_wrapper_options() {
830
+ $wrapper = [];
831
 
832
  $position = $this->options( 'output.position', '' );
833
  $use_placement_pos = false;
925
 
926
  if ( $this->label && ! empty( $wrapper_options['style']['height'] ) ) {
927
  // Create another wrapper so that the label does not reduce the height of the ad wrapper.
928
+ $height = [ 'style' => [ 'height' => $wrapper_options['style']['height'] ] ];
929
  unset( $wrapper_options['style']['height'] );
930
  $ad_content = '<div' . Advanced_Ads_Utils::build_html_attributes( $height ) . '>' . $ad_content . '</div>';
931
  }
948
  }
949
 
950
  if ( ( ! isset( $this->output['wrapper-id'] ) || '' === $this->output['wrapper-id'] )
951
+ && [] === $wrapper_options || ! is_array( $wrapper_options ) ) {
952
  return $this->label . $ad_content;
953
  }
954
 
963
  // build the box
964
  $wrapper = '<' . $wrapper_element . Advanced_Ads_Utils::build_html_attributes( array_merge(
965
  $wrapper_options,
966
+ isset( $this->output['wrapper_attrs'] ) ? $this->output['wrapper_attrs'] : []
967
  ) ) . '>';
968
  $wrapper .= $this->label;
969
  $wrapper .= apply_filters( 'advanced-ads-output-wrapper-before-content', '', $this );
1022
  if ( 'post.php' !== $pagenow && 'post-new.php' !== $pagenow ) {
1023
  // Remove placeholders.
1024
  $this->url = str_replace(
1025
+ [
1026
  '[POST_ID]',
1027
  '[POST_SLUG]',
1028
  '[CAT_SLUG]',
1029
  '[AD_ID]',
1030
+ ],
1031
  '',
1032
  $this->url
1033
  );
classes/ad_ajax_callbacks.php CHANGED
@@ -24,27 +24,27 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
24
  public function __construct() {
25
 
26
  // admin only!
27
- add_action( 'wp_ajax_load_ad_parameters_metabox', array( $this, 'load_ad_parameters_metabox' ) );
28
- add_action( 'wp_ajax_load_visitor_conditions_metabox', array( $this, 'load_visitor_condition' ) );
29
- add_action( 'wp_ajax_load_display_conditions_metabox', array( $this, 'load_display_condition' ) );
30
- add_action( 'wp_ajax_advads-terms-search', array( $this, 'search_terms' ) );
31
- add_action( 'wp_ajax_advads-close-notice', array( $this, 'close_notice' ) );
32
- add_action( 'wp_ajax_advads-hide-notice', array( $this, 'hide_notice' ) );
33
- add_action( 'wp_ajax_advads-subscribe-notice', array( $this, 'subscribe' ) );
34
- add_action( 'wp_ajax_advads-activate-license', array( $this, 'activate_license' ) );
35
- add_action( 'wp_ajax_advads-deactivate-license', array( $this, 'deactivate_license' ) );
36
- add_action( 'wp_ajax_advads-adblock-rebuild-assets', array( $this, 'adblock_rebuild_assets' ) );
37
- add_action( 'wp_ajax_advads-post-search', array( $this, 'post_search' ) );
38
- add_action( 'wp_ajax_advads-ad-injection-content', array( $this, 'inject_placement' ) );
39
- add_action( 'wp_ajax_advads-save-hide-wizard-state', array( $this, 'save_wizard_state' ) );
40
- add_action( 'wp_ajax_advads-adsense-enable-pla', array( $this, 'adsense_enable_pla' ) );
41
- add_action( 'wp_ajax_advads-ad-health-notice-display', array( $this, 'ad_health_notice_display' ) );
42
- add_action( 'wp_ajax_advads-ad-health-notice-push-adminui', array( $this, 'ad_health_notice_push' ) );
43
- add_action( 'wp_ajax_advads-ad-health-notice-hide', array( $this, 'ad_health_notice_hide' ) );
44
- add_action( 'wp_ajax_advads-ad-health-notice-unignore', array( $this, 'ad_health_notice_unignore' ) );
45
- add_action( 'wp_ajax_advads-ad-health-notice-solved', array( $this, 'ad_health_notice_solved' ) );
46
- add_action( 'wp_ajax_advads-update-frontend-element', array( $this, 'update_frontend_element' ) );
47
- add_action( 'wp_ajax_advads-get-block-hints', array( $this, 'get_block_hints' ) );
48
 
49
  }
50
 
@@ -73,7 +73,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
73
  $type = $types[ $type_string ];
74
  $type->render_parameters( $ad );
75
 
76
- $types_without_size = array( 'dummy' );
77
  $types_without_size = apply_filters( 'advanced-ads-types-without-size', $types_without_size );
78
  if ( ! in_array( $type_string, $types_without_size ) ) {
79
  include ADVADS_BASE_PATH . 'admin/views/ad-parameters-size.php';
@@ -109,7 +109,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
109
 
110
  // get visitor condition types.
111
  $visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
112
- $condition = array();
113
  $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
114
  $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
115
 
@@ -122,7 +122,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
122
  }
123
 
124
  if ( method_exists( $metabox[0], $metabox[1] ) ) {
125
- call_user_func( array( $metabox[0], $metabox[1] ), $condition, $index, $form_name );
126
  }
127
 
128
  die();
@@ -143,7 +143,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
143
 
144
  // get display condition types.
145
  $conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
146
- $condition = array();
147
  $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
148
  $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
149
 
@@ -156,7 +156,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
156
  }
157
 
158
  if ( method_exists( $metabox[0], $metabox[1] ) ) {
159
- call_user_func( array( $metabox[0], $metabox[1] ), $condition, $index, $form_name );
160
  }
161
 
162
  die();
@@ -175,12 +175,12 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
175
  return;
176
  }
177
 
178
- $args = array();
179
  $taxonomy = $_POST['tax'];
180
- $args = array(
181
  'hide_empty' => false,
182
  'number' => 20,
183
- );
184
 
185
  if ( ! isset( $_POST['search'] ) || '' === $_POST['search'] ) {
186
  die();
@@ -188,7 +188,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
188
 
189
  // if search is an id, search for the term id, else do a full text search.
190
  if ( 0 !== absint( $_POST['search'] ) && strlen( $_POST['search'] ) === strlen( absint( $_POST['search'] ) ) ) {
191
- $args['include'] = array( absint( $_POST['search'] ) );
192
  } else {
193
  $args['search'] = $_POST['search'];
194
  }
@@ -254,15 +254,15 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
254
  if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ) ) || empty( $_POST['notice'] )
255
  ) {
256
  wp_send_json_error(
257
- array(
258
  // translators: %s is a URL.
259
  'message' => sprintf( __( 'An error occurred. Please use <a href="%s" target="_blank">this form</a> to sign up.', 'advanced-ads' ), 'http://eepurl.com/bk4z4P' ),
260
- ),
261
  400
262
  );
263
  }
264
 
265
- wp_send_json_success( array( 'message' => Advanced_Ads_Admin_Notices::get_instance()->subscribe( $_POST['notice'] ) ) );
266
  }
267
 
268
  /**
@@ -337,8 +337,8 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
337
  return;
338
  }
339
 
340
- add_filter( 'wp_link_query_args', array( 'Advanced_Ads_Display_Conditions', 'modify_post_search' ) );
341
- add_filter( 'posts_search', array( 'Advanced_Ads_Display_Conditions', 'modify_post_search_sql' ) );
342
 
343
  wp_ajax_wp_link_ajax();
344
  }
@@ -387,7 +387,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
387
 
388
  $item = 'ad_' . $ad_id;
389
 
390
- $options = array();
391
 
392
  // check type.
393
  $placement_types = Advanced_Ads_Placements::get_placement_types();
@@ -397,20 +397,20 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
397
 
398
  $title = $placement_types[ $type ]['title'];
399
 
400
- $new_placement = array(
401
  'type' => $type,
402
  'item' => $item,
403
  'name' => $title,
404
- );
405
 
406
  // set content specific options.
407
  if ( 'post_content' === $type ) {
408
  $index = isset( $_REQUEST['options']['index'] ) ? absint( $_REQUEST['options']['index'] ) : 1;
409
- $new_placement['options'] = array(
410
  'position' => 'after',
411
  'index' => $index,
412
  'tag' => 'p',
413
- );
414
  }
415
 
416
  $slug = Advanced_Ads_Placements::save_new_placement( $new_placement );
@@ -457,7 +457,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
457
  return;
458
  }
459
 
460
- $options = get_option( GADSENSE_OPT_NAME, array() );
461
  $options['page-level-enabled'] = true;
462
  update_option( GADSENSE_OPT_NAME, $options );
463
  die();
@@ -490,7 +490,7 @@ class Advanced_Ads_Ad_Ajax_Callbacks {
490
  }
491
 
492
  $key = ( ! empty( $_REQUEST['key'] ) ) ? esc_attr( $_REQUEST['key'] ) : false;
493
- $attr = ( ! empty( $_REQUEST['attr'] ) && is_array( $_REQUEST['attr'] ) ) ? $_REQUEST['attr'] : array();
494
 
495
  // update or new entry?
496
  if ( isset( $attr['mode'] ) && 'update' === $attr['mode'] ) {
24
  public function __construct() {
25
 
26
  // admin only!
27
+ add_action( 'wp_ajax_load_ad_parameters_metabox', [ $this, 'load_ad_parameters_metabox' ] );
28
+ add_action( 'wp_ajax_load_visitor_conditions_metabox', [ $this, 'load_visitor_condition' ] );
29
+ add_action( 'wp_ajax_load_display_conditions_metabox', [ $this, 'load_display_condition' ] );
30
+ add_action( 'wp_ajax_advads-terms-search', [ $this, 'search_terms' ] );
31
+ add_action( 'wp_ajax_advads-close-notice', [ $this, 'close_notice' ] );
32
+ add_action( 'wp_ajax_advads-hide-notice', [ $this, 'hide_notice' ] );
33
+ add_action( 'wp_ajax_advads-subscribe-notice', [ $this, 'subscribe' ] );
34
+ add_action( 'wp_ajax_advads-activate-license', [ $this, 'activate_license' ] );
35
+ add_action( 'wp_ajax_advads-deactivate-license', [ $this, 'deactivate_license' ] );
36
+ add_action( 'wp_ajax_advads-adblock-rebuild-assets', [ $this, 'adblock_rebuild_assets' ] );
37
+ add_action( 'wp_ajax_advads-post-search', [ $this, 'post_search' ] );
38
+ add_action( 'wp_ajax_advads-ad-injection-content', [ $this, 'inject_placement' ] );
39
+ add_action( 'wp_ajax_advads-save-hide-wizard-state', [ $this, 'save_wizard_state' ] );
40
+ add_action( 'wp_ajax_advads-adsense-enable-pla', [ $this, 'adsense_enable_pla' ] );
41
+ add_action( 'wp_ajax_advads-ad-health-notice-display', [ $this, 'ad_health_notice_display' ] );
42
+ add_action( 'wp_ajax_advads-ad-health-notice-push-adminui', [ $this, 'ad_health_notice_push' ] );
43
+ add_action( 'wp_ajax_advads-ad-health-notice-hide', [ $this, 'ad_health_notice_hide' ] );
44
+ add_action( 'wp_ajax_advads-ad-health-notice-unignore', [ $this, 'ad_health_notice_unignore' ] );
45
+ add_action( 'wp_ajax_advads-ad-health-notice-solved', [ $this, 'ad_health_notice_solved' ] );
46
+ add_action( 'wp_ajax_advads-update-frontend-element', [ $this, 'update_frontend_element' ] );
47
+ add_action( 'wp_ajax_advads-get-block-hints', [ $this, 'get_block_hints' ] );
48
 
49
  }
50
 
73
  $type = $types[ $type_string ];
74
  $type->render_parameters( $ad );
75
 
76
+ $types_without_size = [ 'dummy' ];
77
  $types_without_size = apply_filters( 'advanced-ads-types-without-size', $types_without_size );
78
  if ( ! in_array( $type_string, $types_without_size ) ) {
79
  include ADVADS_BASE_PATH . 'admin/views/ad-parameters-size.php';
109
 
110
  // get visitor condition types.
111
  $visitor_conditions = Advanced_Ads_Visitor_Conditions::get_instance()->conditions;
112
+ $condition = [];
113
  $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
114
  $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
115
 
122
  }
123
 
124
  if ( method_exists( $metabox[0], $metabox[1] ) ) {
125
+ call_user_func( [ $metabox[0], $metabox[1] ], $condition, $index, $form_name );
126
  }
127
 
128
  die();
143
 
144
  // get display condition types.
145
  $conditions = Advanced_Ads_Display_Conditions::get_instance()->conditions;
146
+ $condition = [];
147
  $condition['type'] = isset( $_POST['type'] ) ? $_POST['type'] : '';
148
  $index = isset( $_POST['index'] ) ? $_POST['index'] : 0;
149
 
156
  }
157
 
158
  if ( method_exists( $metabox[0], $metabox[1] ) ) {
159
+ call_user_func( [ $metabox[0], $metabox[1] ], $condition, $index, $form_name );
160
  }
161
 
162
  die();
175
  return;
176
  }
177
 
178
+ $args = [];
179
  $taxonomy = $_POST['tax'];
180
+ $args = [
181
  'hide_empty' => false,
182
  'number' => 20,
183
+ ];
184
 
185
  if ( ! isset( $_POST['search'] ) || '' === $_POST['search'] ) {
186
  die();
188
 
189
  // if search is an id, search for the term id, else do a full text search.
190
  if ( 0 !== absint( $_POST['search'] ) && strlen( $_POST['search'] ) === strlen( absint( $_POST['search'] ) ) ) {
191
+ $args['include'] = [ absint( $_POST['search'] ) ];
192
  } else {
193
  $args['search'] = $_POST['search'];
194
  }
254
  if ( ! current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_see_interface' ) ) || empty( $_POST['notice'] )
255
  ) {
256
  wp_send_json_error(
257
+ [
258
  // translators: %s is a URL.
259
  'message' => sprintf( __( 'An error occurred. Please use <a href="%s" target="_blank">this form</a> to sign up.', 'advanced-ads' ), 'http://eepurl.com/bk4z4P' ),
260
+ ],
261
  400
262
  );
263
  }
264
 
265
+ wp_send_json_success( [ 'message' => Advanced_Ads_Admin_Notices::get_instance()->subscribe( $_POST['notice'] ) ] );
266
  }
267
 
268
  /**
337
  return;
338
  }
339
 
340
+ add_filter( 'wp_link_query_args', [ 'Advanced_Ads_Display_Conditions', 'modify_post_search' ] );
341
+ add_filter( 'posts_search', [ 'Advanced_Ads_Display_Conditions', 'modify_post_search_sql' ] );
342
 
343
  wp_ajax_wp_link_ajax();
344
  }
387
 
388
  $item = 'ad_' . $ad_id;
389
 
390
+ $options = [];
391
 
392
  // check type.
393
  $placement_types = Advanced_Ads_Placements::get_placement_types();
397
 
398
  $title = $placement_types[ $type ]['title'];
399
 
400
+ $new_placement = [
401
  'type' => $type,
402
  'item' => $item,
403
  'name' => $title,
404
+ ];
405
 
406
  // set content specific options.
407
  if ( 'post_content' === $type ) {
408
  $index = isset( $_REQUEST['options']['index'] ) ? absint( $_REQUEST['options']['index'] ) : 1;
409
+ $new_placement['options'] = [
410
  'position' => 'after',
411
  'index' => $index,
412
  'tag' => 'p',
413
+ ];
414
  }
415
 
416
  $slug = Advanced_Ads_Placements::save_new_placement( $new_placement );
457
  return;
458
  }
459
 
460
+ $options = get_option( GADSENSE_OPT_NAME, [] );
461
  $options['page-level-enabled'] = true;
462
  update_option( GADSENSE_OPT_NAME, $options );
463
  die();
490
  }
491
 
492
  $key = ( ! empty( $_REQUEST['key'] ) ) ? esc_attr( $_REQUEST['key'] ) : false;
493
+ $attr = ( ! empty( $_REQUEST['attr'] ) && is_array( $_REQUEST['attr'] ) ) ? $_REQUEST['attr'] : [];
494
 
495
  // update or new entry?
496
  if ( isset( $attr['mode'] ) && 'update' === $attr['mode'] ) {
classes/ad_group.php CHANGED
@@ -76,14 +76,14 @@ class Advanced_Ads_Group {
76
  *
77
  * @since 1.5.5
78
  */
79
- public $options = array();
80
 
81
  /**
82
  * Optional arguments passed to ads.
83
  *
84
  * @var array
85
  */
86
- public $ad_args = array();
87
 
88
  /**
89
  * Containing ad weights
@@ -93,7 +93,7 @@ class Advanced_Ads_Group {
93
  /**
94
  * Array with post type objects (ads)
95
  */
96
- private $ads = array();
97
 
98
  /**
99
  * Multidimensional array contains information about the wrapper
@@ -101,7 +101,7 @@ class Advanced_Ads_Group {
101
  *
102
  * @since untagged
103
  */
104
- public $wrapper = array();
105
 
106
  /**
107
  * Displayed above the ad.
@@ -115,7 +115,7 @@ class Advanced_Ads_Group {
115
  * @param int|obj $group either id of the ad group (= taxonomy id) or term object
116
  * @param array $ad_args optional arguments passed to ads
117
  */
118
- public function __construct( $group, $ad_args = array() ) {
119
  $this->taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
120
 
121
  $group = get_term( $group, $this->taxonomy );
@@ -158,13 +158,13 @@ class Advanced_Ads_Group {
158
  */
159
  protected function load_additional_attributes() {
160
  // -TODO should abstract (i.e. only call once per request)
161
- $all_groups = get_option( 'advads-ad-groups', array() );
162
 
163
  if ( ! isset( $all_groups[ $this->id ] ) || ! is_array( $all_groups[ $this->id ] ) ) { return; }
164
 
165
  if ( isset( $this->ad_args['change-group'] ) ) {
166
  // some options was provided by the user
167
- $group_data = Advanced_Ads_Utils::merge_deep_array( array( $all_groups[ $this->id ], $this->ad_args['change-group'] ) ) ;
168
  } else {
169
  $group_data = $all_groups[ $this->id ];
170
  }
@@ -179,7 +179,7 @@ class Advanced_Ads_Group {
179
  }
180
 
181
  if ( isset( $group_data['options'] ) ) {
182
- $this->options = isset( $group_data['options'] ) ? $group_data['options'] : array();
183
  }
184
  }
185
 
@@ -197,19 +197,19 @@ class Advanced_Ads_Group {
197
  }
198
 
199
  // load the ad output
200
- $output = array();
201
  $ads_displayed = 0;
202
  $ad_count = apply_filters( 'advanced-ads-group-ad-count', $this->ad_count, $this );
203
 
204
  $ad_select = Advanced_Ads_Select::get_instance();
205
 
206
  // the Advanced_Ads_Ad obj can access this info
207
- $this->ad_args['group_info'] = array(
208
  'id' => $this->id,
209
  'name' => $this->name,
210
  'type' => $this->type,
211
  'refresh_enabled' => ! empty( $this->options['refresh']['enabled'] ),
212
- );
213
  $this->ad_args['ad_label'] = 'disabled';
214
 
215
  if( is_array( $ordered_ad_ids ) ){
@@ -234,10 +234,10 @@ class Advanced_Ads_Group {
234
  if ( $global_output ) {
235
  // add the group to the global output array
236
  $advads = Advanced_Ads::get_instance();
237
- $advads->current_ads[] = array('type' => 'group', 'id' => $this->id, 'title' => $this->name);
238
  }
239
 
240
- if ( $output === array() || ! is_array( $output ) ) {
241
  return '';
242
  }
243
 
@@ -245,7 +245,7 @@ class Advanced_Ads_Group {
245
  $output_array = apply_filters( 'advanced-ads-group-output-array', $output, $this );
246
 
247
  // make sure the right format comes through the filter
248
- if ( $output_array === array() || ! is_array( $output_array ) ) {
249
  return '';
250
  }
251
 
@@ -257,7 +257,7 @@ class Advanced_Ads_Group {
257
  $this->wrapper = $inline_css->add_css( $this->wrapper, $this->ad_args['inline-css'], $global_output );
258
  }
259
 
260
- if ( ! $this->is_head_placement && $this->wrapper !== array() ) {
261
  $output_string = '<div' . Advanced_Ads_Utils::build_html_attributes( $this->wrapper ) . '>'
262
  . $this->label
263
  . apply_filters( 'advanced-ads-output-wrapper-before-content-group', '', $this )
@@ -283,7 +283,7 @@ class Advanced_Ads_Group {
283
  // load ads
284
  $ads = $this->load_all_ads();
285
  if ( ! is_array( $ads ) ) {
286
- return array();
287
  }
288
 
289
  // get ad weights serving as an order here
@@ -331,21 +331,21 @@ class Advanced_Ads_Group {
331
  private function load_all_ads() {
332
 
333
  if ( ! $this->id ) {
334
- return array();
335
  }
336
 
337
  // reset
338
- $this->ads = array();
339
 
340
  // much more complex than needed: one of the three queries is not needed and the last query gets slow quiet fast
341
- $args = array(
342
  'post_type' => $this->post_type,
343
  'post_status' => 'publish',
344
  'posts_per_page' => -1,
345
  'taxonomy' => $this->taxonomy,
346
  'term' => $this->slug,
347
  'orderby' => 'id' // might want to avoid sorting as not needed for most calls and fast in PHP; slight I/O blocking concern
348
- );
349
 
350
  $found = false;
351
  $key = 'ad_group_all_ads_' . $this->post_type . '_' . $this->taxonomy . '_' . $this->slug;
@@ -374,7 +374,7 @@ class Advanced_Ads_Group {
374
  */
375
  private function add_post_ids(array $ads){
376
 
377
- $ads_with_id = array();
378
  foreach ( $ads as $_ad ){
379
  $ads_with_id[$_ad->ID] = $_ad;
380
  }
@@ -393,7 +393,7 @@ class Advanced_Ads_Group {
393
  */
394
  public function shuffle_ads( $ads, $weights ) {
395
  // get a random ad for every ad there is
396
- $shuffled_ads = array();
397
  // while non-zero weights are set select random next
398
  // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- prevents code duplication.
399
  while ( null !== ( $random_ad_id = $this->get_random_ad_by_weight( $weights ) ) ) {
@@ -474,13 +474,13 @@ class Advanced_Ads_Group {
474
  *
475
  * @return array
476
  */
477
- public function get_ad_weights( $ad_ids = array() ) {
478
  if ( is_array( $this->ad_weights ) ) {
479
  return $this->ad_weights;
480
  }
481
 
482
- $weights = get_option( 'advads-ad-weights', array() );
483
- $this->ad_weights = array();
484
  if ( array_key_exists( $this->id, $weights ) ) {
485
  $this->ad_weights = $weights[ $this->id ];
486
  }
@@ -502,13 +502,13 @@ class Advanced_Ads_Group {
502
  * @since 1.4.8
503
  * @param arr $args group arguments
504
  */
505
- public function save($args = array()) {
506
 
507
- $defaults = array( 'type' => 'default', 'ad_count' => 1, 'options' => array() );
508
  $args = wp_parse_args($args, $defaults);
509
 
510
  // get global ad group option
511
- $groups = get_option( 'advads-ad-groups', array() );
512
 
513
  $groups[$this->id] = $args;
514
 
@@ -521,7 +521,7 @@ class Advanced_Ads_Group {
521
  * @since 1.0.0
522
  */
523
  public static function delete_ad_weights($group_id){
524
- $all_weights = get_option( 'advads-ad-weights', array() );
525
  if ($all_weights && isset($all_weights[$group_id])){
526
  unset($all_weights[$group_id]);
527
  update_option( 'advads-ad-weights', $all_weights );
@@ -532,7 +532,7 @@ class Advanced_Ads_Group {
532
  * Create a wrapper to place around the group.
533
  */
534
  private function create_wrapper() {
535
- $this->wrapper = array();
536
 
537
  if ( $this->ad_args['is_top_level'] ) {
538
  // Add label.
@@ -568,7 +568,7 @@ class Advanced_Ads_Group {
568
 
569
  $this->wrapper = (array) apply_filters( 'advanced-ads-output-wrapper-options-group', $this->wrapper, $this );
570
 
571
- if ( ( $this->wrapper !== array() || $this->label ) && ! isset( $this->wrapper['id'] ) ) {
572
  $prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
573
  $this->wrapper['id'] = $prefix . mt_rand();
574
  }
@@ -603,7 +603,7 @@ class Advanced_Ads_Group {
603
  * @return string[] Group hints (escaped strings).
604
  */
605
  public static function get_hints( Advanced_Ads_Group $group ) {
606
- $hints = array();
607
 
608
  if (
609
  ! Advanced_Ads_Checks::cache()
@@ -627,12 +627,12 @@ class Advanced_Ads_Group {
627
  wp_kses(
628
  // translators: %1$s is an URL, %2$s is a URL text
629
  __( 'It seems that a caching plugin is activated. Your ads might not rotate properly. The cache busting in Advanced Ads Pro will solve that. <a href="%1$s" target="_blank">%2$s.</a>', 'advanced-ads' ),
630
- array(
631
- 'a' => array(
632
- 'href' => array(),
633
- 'target' => array(),
634
- ),
635
- )
636
  ),
637
  $link,
638
  $link_title
76
  *
77
  * @since 1.5.5
78
  */
79
+ public $options = [];
80
 
81
  /**
82
  * Optional arguments passed to ads.
83
  *
84
  * @var array
85
  */
86
+ public $ad_args = [];
87
 
88
  /**
89
  * Containing ad weights
93
  /**
94
  * Array with post type objects (ads)
95
  */
96
+ private $ads = [];
97
 
98
  /**
99
  * Multidimensional array contains information about the wrapper
101
  *
102
  * @since untagged
103
  */
104
+ public $wrapper = [];
105
 
106
  /**
107
  * Displayed above the ad.
115
  * @param int|obj $group either id of the ad group (= taxonomy id) or term object
116
  * @param array $ad_args optional arguments passed to ads
117
  */
118
+ public function __construct( $group, $ad_args = [] ) {
119
  $this->taxonomy = Advanced_Ads::AD_GROUP_TAXONOMY;
120
 
121
  $group = get_term( $group, $this->taxonomy );
158
  */
159
  protected function load_additional_attributes() {
160
  // -TODO should abstract (i.e. only call once per request)
161
+ $all_groups = get_option( 'advads-ad-groups', [] );
162
 
163
  if ( ! isset( $all_groups[ $this->id ] ) || ! is_array( $all_groups[ $this->id ] ) ) { return; }
164
 
165
  if ( isset( $this->ad_args['change-group'] ) ) {
166
  // some options was provided by the user
167
+ $group_data = Advanced_Ads_Utils::merge_deep_array( [ $all_groups[ $this->id ], $this->ad_args['change-group'] ] ) ;
168
  } else {
169
  $group_data = $all_groups[ $this->id ];
170
  }
179
  }
180
 
181
  if ( isset( $group_data['options'] ) ) {
182
+ $this->options = isset( $group_data['options'] ) ? $group_data['options'] : [];
183
  }
184
  }
185
 
197
  }
198
 
199
  // load the ad output
200
+ $output = [];
201
  $ads_displayed = 0;
202
  $ad_count = apply_filters( 'advanced-ads-group-ad-count', $this->ad_count, $this );
203
 
204
  $ad_select = Advanced_Ads_Select::get_instance();
205
 
206
  // the Advanced_Ads_Ad obj can access this info
207
+ $this->ad_args['group_info'] = [
208
  'id' => $this->id,
209
  'name' => $this->name,
210
  'type' => $this->type,
211
  'refresh_enabled' => ! empty( $this->options['refresh']['enabled'] ),
212
+ ];
213
  $this->ad_args['ad_label'] = 'disabled';
214
 
215
  if( is_array( $ordered_ad_ids ) ){
234
  if ( $global_output ) {
235
  // add the group to the global output array
236
  $advads = Advanced_Ads::get_instance();
237
+ $advads->current_ads[] = ['type' => 'group', 'id' => $this->id, 'title' => $this->name];
238
  }
239
 
240
+ if ( $output === [] || ! is_array( $output ) ) {
241
  return '';
242
  }
243
 
245
  $output_array = apply_filters( 'advanced-ads-group-output-array', $output, $this );
246
 
247
  // make sure the right format comes through the filter
248
+ if ( $output_array === [] || ! is_array( $output_array ) ) {
249
  return '';
250
  }
251
 
257
  $this->wrapper = $inline_css->add_css( $this->wrapper, $this->ad_args['inline-css'], $global_output );
258
  }
259
 
260
+ if ( ! $this->is_head_placement && $this->wrapper !== [] ) {
261
  $output_string = '<div' . Advanced_Ads_Utils::build_html_attributes( $this->wrapper ) . '>'
262
  . $this->label
263
  . apply_filters( 'advanced-ads-output-wrapper-before-content-group', '', $this )
283
  // load ads
284
  $ads = $this->load_all_ads();
285
  if ( ! is_array( $ads ) ) {
286
+ return [];
287
  }
288
 
289
  // get ad weights serving as an order here
331
  private function load_all_ads() {
332
 
333
  if ( ! $this->id ) {
334
+ return [];
335
  }
336
 
337
  // reset
338
+ $this->ads = [];
339
 
340
  // much more complex than needed: one of the three queries is not needed and the last query gets slow quiet fast
341
+ $args = [
342
  'post_type' => $this->post_type,
343
  'post_status' => 'publish',
344
  'posts_per_page' => -1,
345
  'taxonomy' => $this->taxonomy,
346
  'term' => $this->slug,
347
  'orderby' => 'id' // might want to avoid sorting as not needed for most calls and fast in PHP; slight I/O blocking concern
348
+ ];
349
 
350
  $found = false;
351
  $key = 'ad_group_all_ads_' . $this->post_type . '_' . $this->taxonomy . '_' . $this->slug;
374
  */
375
  private function add_post_ids(array $ads){
376
 
377
+ $ads_with_id = [];
378
  foreach ( $ads as $_ad ){
379
  $ads_with_id[$_ad->ID] = $_ad;
380
  }
393
  */
394
  public function shuffle_ads( $ads, $weights ) {
395
  // get a random ad for every ad there is
396
+ $shuffled_ads = [];
397
  // while non-zero weights are set select random next
398
  // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- prevents code duplication.
399
  while ( null !== ( $random_ad_id = $this->get_random_ad_by_weight( $weights ) ) ) {
474
  *
475
  * @return array
476
  */
477
+ public function get_ad_weights( $ad_ids = [] ) {
478
  if ( is_array( $this->ad_weights ) ) {
479
  return $this->ad_weights;
480
  }
481
 
482
+ $weights = get_option( 'advads-ad-weights', [] );
483
+ $this->ad_weights = [];
484
  if ( array_key_exists( $this->id, $weights ) ) {
485
  $this->ad_weights = $weights[ $this->id ];
486
  }
502
  * @since 1.4.8
503
  * @param arr $args group arguments
504
  */
505
+ public function save($args = []) {
506
 
507
+ $defaults = [ 'type' => 'default', 'ad_count' => 1, 'options' => [] ];
508
  $args = wp_parse_args($args, $defaults);
509
 
510
  // get global ad group option
511
+ $groups = get_option( 'advads-ad-groups', [] );
512
 
513
  $groups[$this->id] = $args;
514
 
521
  * @since 1.0.0
522
  */
523
  public static function delete_ad_weights($group_id){
524
+ $all_weights = get_option( 'advads-ad-weights', [] );
525
  if ($all_weights && isset($all_weights[$group_id])){
526
  unset($all_weights[$group_id]);
527
  update_option( 'advads-ad-weights', $all_weights );
532
  * Create a wrapper to place around the group.
533
  */
534
  private function create_wrapper() {
535
+ $this->wrapper = [];
536
 
537
  if ( $this->ad_args['is_top_level'] ) {
538
  // Add label.
568
 
569
  $this->wrapper = (array) apply_filters( 'advanced-ads-output-wrapper-options-group', $this->wrapper, $this );
570
 
571
+ if ( ( $this->wrapper !== [] || $this->label ) && ! isset( $this->wrapper['id'] ) ) {
572
  $prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
573
  $this->wrapper['id'] = $prefix . mt_rand();
574
  }
603
  * @return string[] Group hints (escaped strings).
604
  */
605
  public static function get_hints( Advanced_Ads_Group $group ) {
606
+ $hints = [];
607
 
608
  if (
609
  ! Advanced_Ads_Checks::cache()
627
  wp_kses(
628
  // translators: %1$s is an URL, %2$s is a URL text
629
  __( 'It seems that a caching plugin is activated. Your ads might not rotate properly. The cache busting in Advanced Ads Pro will solve that. <a href="%1$s" target="_blank">%2$s.</a>', 'advanced-ads' ),
630
+ [
631
+ 'a' => [
632
+ 'href' => [],
633
+ 'target' => [],
634
+ ],
635
+ ]
636
  ),
637
  $link,
638
  $link_title
classes/ad_placements.php CHANGED
@@ -24,15 +24,15 @@ class Advanced_Ads_Placements {
24
  *
25
  * @var array $ads_for_placeholders
26
  */
27
- private static $ads_for_placeholders = array();
28
  /**
29
  * Temporarily change content during processing
30
  *
31
  * @var array $placements
32
  */
33
- private static $replacements = array(
34
  'gcse:search' => 'gcse__search', // Google custom search namespaced tags.
35
- );
36
 
37
  /**
38
  * Get placement types
@@ -41,79 +41,79 @@ class Advanced_Ads_Placements {
41
  * @since 1.2.1
42
  */
43
  public static function get_placement_types() {
44
- $types = array(
45
- 'post_top' => array(
46
  'title' => __( 'Before Content', 'advanced-ads' ),
47
  'description' => __( 'Injected before the post content.', 'advanced-ads' ),
48
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-before.png',
49
  'order' => 20,
50
- 'options' => array(
51
  'show_position' => true,
52
  'show_lazy_load' => true,
53
  'uses_the_content' => true,
54
  'amp' => true,
55
- ),
56
- ),
57
- 'post_content' => array(
58
  'title' => __( 'Content', 'advanced-ads' ),
59
  'description' => __( 'Injected into the content. You can choose the paragraph after which the ad content is displayed.', 'advanced-ads' ),
60
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-within.png',
61
  'order' => 21,
62
- 'options' => array(
63
  'show_position' => true,
64
  'show_lazy_load' => true,
65
  'uses_the_content' => true,
66
  'amp' => true,
67
- ),
68
- ),
69
- 'post_bottom' => array(
70
  'title' => __( 'After Content', 'advanced-ads' ),
71
  'description' => __( 'Injected after the post content.', 'advanced-ads' ),
72
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-after.png',
73
  'order' => 35,
74
- 'options' => array(
75
  'show_position' => true,
76
  'show_lazy_load' => true,
77
  'uses_the_content' => true,
78
  'amp' => true,
79
- ),
80
- ),
81
- 'sidebar_widget' => array(
82
  'title' => __( 'Sidebar Widget', 'advanced-ads' ),
83
  'description' => __( 'Create a sidebar widget with an ad. Can be placed and used like any other widget.', 'advanced-ads' ),
84
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/widget.png',
85
  'order' => 50,
86
- 'options' => array(
87
  'show_position' => true,
88
  'show_lazy_load' => true,
89
  'amp' => true,
90
- ),
91
- ),
92
- 'default' => array(
93
  'title' => __( 'Manual Placement', 'advanced-ads' ),
94
  'description' => __( 'Manual placement to use as function or shortcode.', 'advanced-ads' ),
95
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/manual.png',
96
  'order' => 80,
97
- 'options' => array(
98
  'show_position' => true,
99
  'show_lazy_load' => true,
100
  'amp' => true,
101
- ),
102
- ),
103
- 'header' => array(
104
  'title' => __( 'Header Code', 'advanced-ads' ),
105
  'description' => __( 'Injected in Header (before closing &lt;/head&gt; Tag, often not visible).', 'advanced-ads' ),
106
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/header.png',
107
  'order' => 3,
108
- ),
109
- 'footer' => array(
110
  'title' => __( 'Footer Code', 'advanced-ads' ),
111
  'description' => __( 'Injected in Footer (before closing &lt;/body&gt; Tag).', 'advanced-ads' ),
112
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/footer.png',
113
  'order' => 95,
114
- 'options' => array( 'amp' => true ),
115
- ),
116
- );
117
 
118
  return apply_filters( 'advanced-ads-placement-types', $types );
119
  }
@@ -147,7 +147,7 @@ class Advanced_Ads_Placements {
147
 
148
  if ( isset( $success ) ) {
149
  $message = $success ? 'updated' : 'error';
150
- wp_redirect( esc_url_raw( add_query_arg( array( 'message' => $message ) ) ) . $hook );
151
  }
152
  }
153
 
@@ -193,11 +193,11 @@ class Advanced_Ads_Placements {
193
  $new_placement['name'] = esc_attr( $new_placement['name'] );
194
 
195
  // add new place to all placements.
196
- $placements[ $new_placement['slug'] ] = array(
197
  'type' => $new_placement['type'],
198
  'name' => $new_placement['name'],
199
  'item' => $new_placement['item'],
200
- );
201
 
202
  // add index options.
203
  if ( isset( $new_placement['options'] ) ) {
@@ -243,7 +243,7 @@ class Advanced_Ads_Placements {
243
  $placements[ $_placement_slug ]['options']['index'] = absint( $placements[ $_placement_slug ]['options']['index'] );
244
  }
245
  } else {
246
- $placements[ $_placement_slug ]['options'] = array();
247
  }
248
  }
249
 
@@ -260,7 +260,7 @@ class Advanced_Ads_Placements {
260
  * @since 1.1
261
  */
262
  public static function items_for_select() {
263
- $select = array();
264
  $model = Advanced_Ads::get_instance()->get_model();
265
 
266
  // load all ad groups.
@@ -271,10 +271,10 @@ class Advanced_Ads_Placements {
271
 
272
  // load all ads.
273
  $ads = $model->get_ads(
274
- array(
275
  'orderby' => 'title',
276
  'order' => 'ASC',
277
- )
278
  );
279
  foreach ( $ads as $_ad ) {
280
  $select['ads'][ 'ad_' . $_ad->ID ] = $_ad->post_title;
@@ -290,12 +290,12 @@ class Advanced_Ads_Placements {
290
  * @since 1.3.5
291
  */
292
  public static function tags_for_content_injection() {
293
- $headline_tags = apply_filters( 'advanced-ads-headlines-for-ad-injection', array( 'h2', 'h3', 'h4' ) );
294
  $headline_tags_imploded = '&lt;' . implode( '&gt;, &lt;', $headline_tags ) . '&gt;';
295
 
296
  $tags = apply_filters(
297
  'advanced-ads-tags-for-injection',
298
- array(
299
  // translators: %s is an html tag.
300
  'p' => sprintf( __( 'paragraph (%s)', 'advanced-ads' ), '&lt;p&gt;' ),
301
  // translators: %s is an html tag.
@@ -324,7 +324,7 @@ class Advanced_Ads_Placements {
324
  'anyelement' => __( 'any element', 'advanced-ads' ),
325
  // custom
326
  'custom' => _x( 'custom', 'for the "custom" content placement option', 'advanced-ads' ),
327
- )
328
  );
329
 
330
  return $tags;
@@ -338,18 +338,18 @@ class Advanced_Ads_Placements {
338
  *
339
  * @return string
340
  */
341
- public static function output( $id = '', $args = array() ) {
342
  // get placement data for the slug.
343
  if ( '' == $id ) {
344
  return;
345
  }
346
 
347
  $placements = Advanced_Ads::get_ad_placements_array();
348
- $placement = ( isset( $placements[ $id ] ) && is_array( $placements[ $id ] ) ) ? $placements[ $id ] : array();
349
 
350
  if ( isset( $args['change-placement'] ) ) {
351
  // some options was provided by the user.
352
- $placement = Advanced_Ads_Utils::merge_deep_array( array( $placement, $args['change-placement'] ) );
353
  }
354
 
355
  if ( isset( $placement['item'] ) && '' !== $placement['item'] ) {
@@ -383,10 +383,10 @@ class Advanced_Ads_Placements {
383
  // create class from placement id (not if header injection).
384
  if ( ! isset( $placement['type'] ) || 'header' !== $placement['type'] ) {
385
  if ( ! isset( $args['output'] ) ) {
386
- $args['output'] = array();
387
  }
388
  if ( ! isset( $args['output']['class'] ) ) {
389
- $args['output']['class'] = array();
390
  }
391
  $class = $prefix . $id;
392
  if ( ! in_array( $class, $args['output']['class'] ) ) {
@@ -436,11 +436,11 @@ class Advanced_Ads_Placements {
436
  $result = Advanced_Ads_Select::get_instance()->get_ad_by_method( (int) $_item[1], $_item[0], $args );
437
 
438
  if ( $result && ( ! isset( $args['global_output'] ) || $args['global_output'] ) ) {
439
- $advads->current_ads[] = array(
440
  'type' => 'placement',
441
  'id' => $id,
442
  'title' => $name,
443
- );
444
  }
445
 
446
  return $result;
@@ -488,7 +488,7 @@ class Advanced_Ads_Placements {
488
  * @return array
489
  */
490
  public static function get_placements_by( $type, $id ) {
491
- $result = array();
492
 
493
  $placements = Advanced_Ads::get_ad_placements_array();
494
  foreach ( $placements as $_id => $_placement ) {
@@ -510,11 +510,11 @@ class Advanced_Ads_Placements {
510
  private static function get_ancestors_to_limit( $xpath ) {
511
  $query = self::get_ancestors_to_limit_query();
512
  if ( ! $query ) {
513
- return array();
514
  }
515
 
516
  $node_list = $xpath->query( $query );
517
- $ancestors_to_limit = array();
518
 
519
  foreach ( $node_list as $a ) {
520
  $ancestors_to_limit[] = $a->getNodePath();
@@ -533,7 +533,7 @@ class Advanced_Ads_Placements {
533
  * @return array $new_paragraphs An array of `DOMNode` objects to insert ads before or after.
534
  */
535
  private static function filter_by_ancestors_to_limit( $paragraphs, $ancestors_to_limit ) {
536
- $new_paragraphs = array();
537
 
538
  foreach ( $paragraphs as $k => $paragraph ) {
539
  foreach ( $ancestors_to_limit as $a ) {
@@ -572,31 +572,31 @@ class Advanced_Ads_Placements {
572
  */
573
  $items = apply_filters(
574
  'advanced-ads-content-injection-nodes-without-ads',
575
- array(
576
- array(
577
  // a class anyone can use to prevent automatic ad injection into a specific element.
578
  'node' => '.advads-stop-injection',
579
  'type' => 'ancestor',
580
- ),
581
- array(
582
  // Product Slider for Beaver Builder by WooPack.
583
  'node' => '.woopack-product-carousel',
584
  'type' => 'ancestor',
585
- ),
586
- array(
587
  // WP Author Box Lite.
588
  'node' => '#wpautbox-%',
589
  'type' => 'ancestor',
590
- ),
591
- array(
592
  // GeoDirectory Post Slider.
593
  'node' => '.geodir-post-slider',
594
  'type' => 'ancestor',
595
- ),
596
- )
597
  );
598
 
599
- $query = array();
600
  foreach ( $items as $p ) {
601
  $sel = $p['node'];
602
 
@@ -639,13 +639,13 @@ class Advanced_Ads_Placements {
639
  */
640
  public static function sort( $placements, $orderby = 'name' ) {
641
  if ( ! is_array( $placements ) ) {
642
- return array();
643
  }
644
  if ( 'name' === $orderby ) {
645
  ksort( $placements, SORT_NATURAL );
646
  return $placements;
647
  }
648
- uasort( $placements, array( 'Advanced_Ads_Placements', 'sort_by_type_callback' ) );
649
  return $placements;
650
 
651
  }
24
  *
25
  * @var array $ads_for_placeholders
26
  */
27
+ private static $ads_for_placeholders = [];
28
  /**
29
  * Temporarily change content during processing
30
  *
31
  * @var array $placements
32
  */
33
+ private static $replacements = [
34
  'gcse:search' => 'gcse__search', // Google custom search namespaced tags.
35
+ ];
36
 
37
  /**
38
  * Get placement types
41
  * @since 1.2.1
42
  */
43
  public static function get_placement_types() {
44
+ $types = [
45
+ 'post_top' => [
46
  'title' => __( 'Before Content', 'advanced-ads' ),
47
  'description' => __( 'Injected before the post content.', 'advanced-ads' ),
48
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-before.png',
49
  'order' => 20,
50
+ 'options' => [
51
  'show_position' => true,
52
  'show_lazy_load' => true,
53
  'uses_the_content' => true,
54
  'amp' => true,
55
+ ],
56
+ ],
57
+ 'post_content' => [
58
  'title' => __( 'Content', 'advanced-ads' ),
59
  'description' => __( 'Injected into the content. You can choose the paragraph after which the ad content is displayed.', 'advanced-ads' ),
60
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-within.png',
61
  'order' => 21,
62
+ 'options' => [
63
  'show_position' => true,
64
  'show_lazy_load' => true,
65
  'uses_the_content' => true,
66
  'amp' => true,
67
+ ],
68
+ ],
69
+ 'post_bottom' => [
70
  'title' => __( 'After Content', 'advanced-ads' ),
71
  'description' => __( 'Injected after the post content.', 'advanced-ads' ),
72
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/content-after.png',
73
  'order' => 35,
74
+ 'options' => [
75
  'show_position' => true,
76
  'show_lazy_load' => true,
77
  'uses_the_content' => true,
78
  'amp' => true,
79
+ ],
80
+ ],
81
+ 'sidebar_widget' => [
82
  'title' => __( 'Sidebar Widget', 'advanced-ads' ),
83
  'description' => __( 'Create a sidebar widget with an ad. Can be placed and used like any other widget.', 'advanced-ads' ),
84
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/widget.png',
85
  'order' => 50,
86
+ 'options' => [
87
  'show_position' => true,
88
  'show_lazy_load' => true,
89
  'amp' => true,
90
+ ],
91
+ ],
92
+ 'default' => [
93
  'title' => __( 'Manual Placement', 'advanced-ads' ),
94
  'description' => __( 'Manual placement to use as function or shortcode.', 'advanced-ads' ),
95
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/manual.png',
96
  'order' => 80,
97
+ 'options' => [
98
  'show_position' => true,
99
  'show_lazy_load' => true,
100
  'amp' => true,
101
+ ],
102
+ ],
103
+ 'header' => [
104
  'title' => __( 'Header Code', 'advanced-ads' ),
105
  'description' => __( 'Injected in Header (before closing &lt;/head&gt; Tag, often not visible).', 'advanced-ads' ),
106
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/header.png',
107
  'order' => 3,
108
+ ],
109
+ 'footer' => [
110
  'title' => __( 'Footer Code', 'advanced-ads' ),
111
  'description' => __( 'Injected in Footer (before closing &lt;/body&gt; Tag).', 'advanced-ads' ),
112
  'image' => ADVADS_BASE_URL . 'admin/assets/img/placements/footer.png',
113
  'order' => 95,
114
+ 'options' => [ 'amp' => true ],
115
+ ],
116
+ ];
117
 
118
  return apply_filters( 'advanced-ads-placement-types', $types );
119
  }
147
 
148
  if ( isset( $success ) ) {
149
  $message = $success ? 'updated' : 'error';
150
+ wp_redirect( esc_url_raw( add_query_arg( [ 'message' => $message ] ) ) . $hook );
151
  }
152
  }
153
 
193
  $new_placement['name'] = esc_attr( $new_placement['name'] );
194
 
195
  // add new place to all placements.
196
+ $placements[ $new_placement['slug'] ] = [
197
  'type' => $new_placement['type'],
198
  'name' => $new_placement['name'],
199
  'item' => $new_placement['item'],
200
+ ];
201
 
202
  // add index options.
203
  if ( isset( $new_placement['options'] ) ) {
243
  $placements[ $_placement_slug ]['options']['index'] = absint( $placements[ $_placement_slug ]['options']['index'] );
244
  }
245
  } else {
246
+ $placements[ $_placement_slug ]['options'] = [];
247
  }
248
  }
249
 
260
  * @since 1.1
261
  */
262
  public static function items_for_select() {
263
+ $select = [];
264
  $model = Advanced_Ads::get_instance()->get_model();
265
 
266
  // load all ad groups.
271
 
272
  // load all ads.
273
  $ads = $model->get_ads(
274
+ [
275
  'orderby' => 'title',
276
  'order' => 'ASC',
277
+ ]
278
  );
279
  foreach ( $ads as $_ad ) {
280
  $select['ads'][ 'ad_' . $_ad->ID ] = $_ad->post_title;
290
  * @since 1.3.5
291
  */
292
  public static function tags_for_content_injection() {
293
+ $headline_tags = apply_filters( 'advanced-ads-headlines-for-ad-injection', [ 'h2', 'h3', 'h4' ] );
294
  $headline_tags_imploded = '&lt;' . implode( '&gt;, &lt;', $headline_tags ) . '&gt;';
295
 
296
  $tags = apply_filters(
297
  'advanced-ads-tags-for-injection',
298
+ [
299
  // translators: %s is an html tag.
300
  'p' => sprintf( __( 'paragraph (%s)', 'advanced-ads' ), '&lt;p&gt;' ),
301
  // translators: %s is an html tag.
324
  'anyelement' => __( 'any element', 'advanced-ads' ),
325
  // custom
326
  'custom' => _x( 'custom', 'for the "custom" content placement option', 'advanced-ads' ),
327
+ ]
328
  );
329
 
330
  return $tags;
338
  *
339
  * @return string
340
  */
341
+ public static function output( $id = '', $args = [] ) {
342
  // get placement data for the slug.
343
  if ( '' == $id ) {
344
  return;
345
  }
346
 
347
  $placements = Advanced_Ads::get_ad_placements_array();
348
+ $placement = ( isset( $placements[ $id ] ) && is_array( $placements[ $id ] ) ) ? $placements[ $id ] : [];
349
 
350
  if ( isset( $args['change-placement'] ) ) {
351
  // some options was provided by the user.
352
+ $placement = Advanced_Ads_Utils::merge_deep_array( [ $placement, $args['change-placement'] ] );
353
  }
354
 
355
  if ( isset( $placement['item'] ) && '' !== $placement['item'] ) {
383
  // create class from placement id (not if header injection).
384
  if ( ! isset( $placement['type'] ) || 'header' !== $placement['type'] ) {
385
  if ( ! isset( $args['output'] ) ) {
386
+ $args['output'] = [];
387
  }
388
  if ( ! isset( $args['output']['class'] ) ) {
389
+ $args['output']['class'] = [];
390
  }
391
  $class = $prefix . $id;
392
  if ( ! in_array( $class, $args['output']['class'] ) ) {
436
  $result = Advanced_Ads_Select::get_instance()->get_ad_by_method( (int) $_item[1], $_item[0], $args );
437
 
438
  if ( $result && ( ! isset( $args['global_output'] ) || $args['global_output'] ) ) {
439
+ $advads->current_ads[] = [
440
  'type' => 'placement',
441
  'id' => $id,
442
  'title' => $name,
443
+ ];
444
  }
445
 
446
  return $result;
488
  * @return array
489
  */
490
  public static function get_placements_by( $type, $id ) {
491
+ $result = [];
492
 
493
  $placements = Advanced_Ads::get_ad_placements_array();
494
  foreach ( $placements as $_id => $_placement ) {
510
  private static function get_ancestors_to_limit( $xpath ) {
511
  $query = self::get_ancestors_to_limit_query();
512
  if ( ! $query ) {
513
+ return [];
514
  }
515
 
516
  $node_list = $xpath->query( $query );
517
+ $ancestors_to_limit = [];
518
 
519
  foreach ( $node_list as $a ) {
520
  $ancestors_to_limit[] = $a->getNodePath();
533
  * @return array $new_paragraphs An array of `DOMNode` objects to insert ads before or after.
534
  */
535
  private static function filter_by_ancestors_to_limit( $paragraphs, $ancestors_to_limit ) {
536
+ $new_paragraphs = [];
537
 
538
  foreach ( $paragraphs as $k => $paragraph ) {
539
  foreach ( $ancestors_to_limit as $a ) {
572
  */
573
  $items = apply_filters(
574
  'advanced-ads-content-injection-nodes-without-ads',
575
+ [
576
+ [
577
  // a class anyone can use to prevent automatic ad injection into a specific element.
578
  'node' => '.advads-stop-injection',
579
  'type' => 'ancestor',
580
+ ],
581
+ [
582
  // Product Slider for Beaver Builder by WooPack.
583
  'node' => '.woopack-product-carousel',
584
  'type' => 'ancestor',
585
+ ],
586
+ [
587
  // WP Author Box Lite.
588
  'node' => '#wpautbox-%',
589
  'type' => 'ancestor',
590
+ ],
591
+ [
592
  // GeoDirectory Post Slider.
593
  'node' => '.geodir-post-slider',
594
  'type' => 'ancestor',
595
+ ],
596
+ ]
597
  );
598
 
599
+ $query = [];
600
  foreach ( $items as $p ) {
601
  $sel = $p['node'];
602
 
639
  */
640
  public static function sort( $placements, $orderby = 'name' ) {
641
  if ( ! is_array( $placements ) ) {
642
+ return [];
643
  }
644
  if ( 'name' === $orderby ) {
645
  ksort( $placements, SORT_NATURAL );
646
  return $placements;
647
  }
648
+ uasort( $placements, [ 'Advanced_Ads_Placements', 'sort_by_type_callback' ] );
649
  return $placements;
650
 
651
  }
classes/ad_type_abstract.php CHANGED
@@ -48,7 +48,7 @@ class Advanced_Ads_Ad_Type_Abstract {
48
  *
49
  * defaults are set in construct
50
  */
51
- public $parameters = array();
52
 
53
  /**
54
  * Output for the ad parameters metabox
@@ -93,7 +93,7 @@ class Advanced_Ads_Ad_Type_Abstract {
93
  * @return array sanitized ad options.
94
  * @since 1.0.0
95
  */
96
- public function sanitize_options( $options = array() ) {
97
  return $options;
98
  }
99
 
48
  *
49
  * defaults are set in construct
50
  */
51
+ public $parameters = [];
52
 
53
  /**
54
  * Output for the ad parameters metabox
93
  * @return array sanitized ad options.
94
  * @since 1.0.0
95
  */
96
+ public function sanitize_options( $options = [] ) {
97
  return $options;
98
  }
99
 
classes/ad_type_content.php CHANGED
@@ -34,9 +34,9 @@ class Advanced_Ads_Ad_Type_Content extends Advanced_Ads_Ad_Type_Abstract{
34
  public function __construct() {
35
  $this->title = __( 'Rich Content', 'advanced-ads' );
36
  $this->description = __( 'The full content editor from WordPress with all features like shortcodes, image upload or styling, but also simple text/html mode for scripts and code.', 'advanced-ads' );
37
- $this->parameters = array(
38
  'content' => ''
39
- );
40
  }
41
 
42
 
@@ -67,11 +67,11 @@ class Advanced_Ads_Ad_Type_Content extends Advanced_Ads_Ad_Type_Abstract{
67
  if ( ! user_can_richedit() ) {
68
  $content = esc_textarea( $content );
69
  }
70
- $args = array(
71
  'textarea_name' => 'advanced_ad[content]',
72
  'textarea_rows' => 10,
73
  'drag_drop_upload' => true
74
- );
75
  wp_editor( $content, 'advanced-ad-parameters-content', $args );
76
  }
77
  ?>
34
  public function __construct() {
35
  $this->title = __( 'Rich Content', 'advanced-ads' );
36
  $this->description = __( 'The full content editor from WordPress with all features like shortcodes, image upload or styling, but also simple text/html mode for scripts and code.', 'advanced-ads' );
37
+ $this->parameters = [
38
  'content' => ''
39
+ ];
40
  }
41
 
42
 
67
  if ( ! user_can_richedit() ) {
68
  $content = esc_textarea( $content );
69
  }
70
+ $args = [
71
  'textarea_name' => 'advanced_ad[content]',
72
  'textarea_rows' => 10,
73
  'drag_drop_upload' => true
74
+ ];
75
  wp_editor( $content, 'advanced-ad-parameters-content', $args );
76
  }
77
  ?>
classes/ad_type_group.php CHANGED
@@ -29,12 +29,12 @@ class Advanced_Ads_Ad_Type_Group extends Advanced_Ads_Ad_Type_Abstract{
29
  public function __construct() {
30
  $this->title = __( 'Ad Group', 'advanced-ads' );
31
  $this->description = __( 'Choose an existing ad group. Use this type when you want to assign the same display and visitor conditions to all ads in that group.', 'advanced-ads' );
32
- $this->parameters = array(
33
  'group_id' => 0
34
- );
35
 
36
  // on save, remove the group in which the ad is itself to prevent infinite loops
37
- add_action( 'save_post_advanced_ads', array($this, 'remove_from_ad_group'), 1 );
38
  }
39
 
40
  /**
@@ -76,7 +76,7 @@ class Advanced_Ads_Ad_Type_Group extends Advanced_Ads_Ad_Type_Abstract{
76
 
77
  $group_id = ( isset( $ad->output['group_id'] ) ) ? $ad->output['group_id'] : '';
78
 
79
- $select = array();
80
  $model = Advanced_Ads::get_instance()->get_model();
81
 
82
  // load all ad groups
29
  public function __construct() {
30
  $this->title = __( 'Ad Group', 'advanced-ads' );
31
  $this->description = __( 'Choose an existing ad group. Use this type when you want to assign the same display and visitor conditions to all ads in that group.', 'advanced-ads' );
32
+ $this->parameters = [
33
  'group_id' => 0
34
+ ];
35
 
36
  // on save, remove the group in which the ad is itself to prevent infinite loops
37
+ add_action( 'save_post_advanced_ads', [$this, 'remove_from_ad_group'], 1 );
38
  }
39
 
40
  /**
76
 
77
  $group_id = ( isset( $ad->output['group_id'] ) ) ? $ad->output['group_id'] : '';
78
 
79
+ $select = [];
80
  $model = Advanced_Ads::get_instance()->get_model();
81
 
82
  // load all ad groups
classes/ad_type_image.php CHANGED
@@ -28,11 +28,11 @@ class Advanced_Ads_Ad_Type_Image extends Advanced_Ads_Ad_Type_Abstract {
28
  public function __construct() {
29
  $this->title = __( 'Image Ad', 'advanced-ads' );
30
  $this->description = __( 'Ads in various image formats.', 'advanced-ads' );
31
- $this->parameters = array(
32
  'image_url' => '',
33
  'image_title' => '',
34
  'image_alt' => '',
35
- );
36
  }
37
 
38
  /**
28
  public function __construct() {
29
  $this->title = __( 'Image Ad', 'advanced-ads' );
30
  $this->description = __( 'Ads in various image formats.', 'advanced-ads' );
31
+ $this->parameters = [
32
  'image_url' => '',
33
  'image_title' => '',
34
  'image_alt' => '',
35
+ ];
36
  }
37
 
38
  /**
classes/ad_type_plain.php CHANGED
@@ -28,9 +28,9 @@ class Advanced_Ads_Ad_Type_Plain extends Advanced_Ads_Ad_Type_Abstract {
28
  public function __construct() {
29
  $this->title = __( 'Plain Text and Code', 'advanced-ads' );
30
  $this->description = __( 'Any ad network, Amazon, customized AdSense codes, shortcodes, and code like JavaScript, HTML or PHP.', 'advanced-ads' );
31
- $this->parameters = array(
32
  'content' => '',
33
- );
34
  }
35
 
36
  /**
@@ -89,9 +89,9 @@ class Advanced_Ads_Ad_Type_Plain extends Advanced_Ads_Ad_Type_Abstract {
89
  <?php
90
  echo wp_kses(
91
  __( 'Execute PHP code (wrapped in <code>&lt;?php ?&gt;</code>)', 'advanced-ads' ),
92
- array(
93
- 'code' => array(),
94
- )
95
  );
96
  ?>
97
  </span>
@@ -284,7 +284,7 @@ class Advanced_Ads_Ad_Type_Plain extends Advanced_Ads_Ad_Type_Abstract {
284
 
285
  $options = Advanced_Ads::get_instance()->options();
286
  if ( ! isset( $options['allow-unfiltered-html'] ) ) {
287
- $options['allow-unfiltered-html'] = array();
288
  }
289
  $allowed_roles = $options['allow-unfiltered-html'];
290
  $user = get_user_by( 'id', $author_id );
28
  public function __construct() {
29
  $this->title = __( 'Plain Text and Code', 'advanced-ads' );
30
  $this->description = __( 'Any ad network, Amazon, customized AdSense codes, shortcodes, and code like JavaScript, HTML or PHP.', 'advanced-ads' );
31
+ $this->parameters = [
32
  'content' => '',
33
+ ];
34
  }
35
 
36
  /**
89
  <?php
90
  echo wp_kses(
91
  __( 'Execute PHP code (wrapped in <code>&lt;?php ?&gt;</code>)', 'advanced-ads' ),
92
+ [
93
+ 'code' => [],
94
+ ]
95
  );
96
  ?>
97
  </span>
284
 
285
  $options = Advanced_Ads::get_instance()->options();
286
  if ( ! isset( $options['allow-unfiltered-html'] ) ) {
287
+ $options['allow-unfiltered-html'] = [];
288
  }
289
  $allowed_roles = $options['allow-unfiltered-html'];
290
  $user = get_user_by( 'id', $author_id );
classes/checks.php CHANGED
@@ -81,9 +81,9 @@ class Advanced_Ads_Checks {
81
  */
82
  public static function licenses_invalid() {
83
 
84
- $add_ons = apply_filters( 'advanced-ads-add-ons', array() );
85
 
86
- if ( array() === $add_ons ) {
87
  Advanced_Ads_Ad_Health_Notices::get_instance()->remove( 'license_invalid' );
88
  return false;
89
  }
@@ -203,7 +203,7 @@ class Advanced_Ads_Checks {
203
  * @return array $plugins names of conflicting plugins
204
  */
205
  public static function conflicting_plugins() {
206
- $conflicting_plugins = array();
207
 
208
  if ( defined( 'Publicize_Base' ) ) { // JetPack Publicize module.
209
  $conflicting_plugins[] = 'Jetpack – Publicize';
@@ -233,7 +233,7 @@ class Advanced_Ads_Checks {
233
  if ( isset( $options['disabled-ads'] ) && is_array( $options['disabled-ads'] ) ) {
234
  foreach ( $options['disabled-ads'] as $_key => $_value ) {
235
  // don’t warn if "RSS Feed", "404", or "REST API" option are enabled, because they are normally not critical.
236
- if ( ! empty( $_value ) && ! in_array( (string) $_key, array( 'feed', '404', 'rest-api' ), true ) ) {
237
  return true;
238
  }
239
  }
@@ -248,7 +248,7 @@ class Advanced_Ads_Checks {
248
  */
249
  public static function php_extensions() {
250
 
251
- $missing_extensions = array();
252
 
253
  if ( ! extension_loaded( 'dom' ) ) {
254
  $missing_extensions[] = 'dom';
@@ -269,7 +269,7 @@ class Advanced_Ads_Checks {
269
  public static function get_defined_constants() {
270
  $constants = apply_filters(
271
  'advanced-ads-constants',
272
- array(
273
  'ADVADS_ADS_DISABLED',
274
  'ADVADS_ALLOW_ADSENSE_ON_404',
275
  'ADVADS_DISABLE_RESPONSIVE_IMAGES',
@@ -289,10 +289,10 @@ class Advanced_Ads_Checks {
289
  'ADVANCED_ADS_SUPPRESS_PLUGIN_ERROR_NOTICES',
290
  'ADVANCED_ADS_TRACKING_DEBUG',
291
  'ADVANCED_ADS_TRACKING_NO_HOURLY_LIMIT',
292
- )
293
  );
294
 
295
- $result = array();
296
  foreach ( $constants as $constant ) {
297
  if ( defined( $constant ) ) {
298
  $result[] = $constant;
@@ -332,7 +332,7 @@ class Advanced_Ads_Checks {
332
  */
333
  public static function ads_txt_plugins() {
334
 
335
- $ads_txt_plugins = array();
336
 
337
  // Ads.txt Manager.
338
  if ( function_exists( 'tenup_display_ads_txt' ) ) {
@@ -356,7 +356,7 @@ class Advanced_Ads_Checks {
356
  */
357
  public static function header_footer_plugins() {
358
 
359
- $plugins = array();
360
 
361
  // Header Footer Code Manager.
362
  if ( function_exists( 'hfcm_options_install' ) ) {
81
  */
82
  public static function licenses_invalid() {
83
 
84
+ $add_ons = apply_filters( 'advanced-ads-add-ons', [] );
85
 
86
+ if ( [] === $add_ons ) {
87
  Advanced_Ads_Ad_Health_Notices::get_instance()->remove( 'license_invalid' );
88
  return false;
89
  }
203
  * @return array $plugins names of conflicting plugins
204
  */
205
  public static function conflicting_plugins() {
206
+ $conflicting_plugins = [];
207
 
208
  if ( defined( 'Publicize_Base' ) ) { // JetPack Publicize module.
209
  $conflicting_plugins[] = 'Jetpack – Publicize';
233
  if ( isset( $options['disabled-ads'] ) && is_array( $options['disabled-ads'] ) ) {
234
  foreach ( $options['disabled-ads'] as $_key => $_value ) {
235
  // don’t warn if "RSS Feed", "404", or "REST API" option are enabled, because they are normally not critical.
236
+ if ( ! empty( $_value ) && ! in_array( (string) $_key, [ 'feed', '404', 'rest-api' ], true ) ) {
237
  return true;
238
  }
239
  }
248
  */
249
  public static function php_extensions() {
250
 
251
+ $missing_extensions = [];
252
 
253
  if ( ! extension_loaded( 'dom' ) ) {
254
  $missing_extensions[] = 'dom';
269
  public static function get_defined_constants() {
270
  $constants = apply_filters(
271
  'advanced-ads-constants',
272
+ [
273
  'ADVADS_ADS_DISABLED',
274
  'ADVADS_ALLOW_ADSENSE_ON_404',
275
  'ADVADS_DISABLE_RESPONSIVE_IMAGES',
289
  'ADVANCED_ADS_SUPPRESS_PLUGIN_ERROR_NOTICES',
290
  'ADVANCED_ADS_TRACKING_DEBUG',
291
  'ADVANCED_ADS_TRACKING_NO_HOURLY_LIMIT',
292
+ ]
293
  );
294
 
295
+ $result = [];
296
  foreach ( $constants as $constant ) {
297
  if ( defined( $constant ) ) {
298
  $result[] = $constant;
332
  */
333
  public static function ads_txt_plugins() {
334
 
335
+ $ads_txt_plugins = [];
336
 
337
  // Ads.txt Manager.
338
  if ( function_exists( 'tenup_display_ads_txt' ) ) {
356
  */
357
  public static function header_footer_plugins() {
358
 
359
+ $plugins = [];
360
 
361
  // Header Footer Code Manager.
362
  if ( function_exists( 'hfcm_options_install' ) ) {
classes/compatibility.php CHANGED
@@ -18,38 +18,38 @@ class Advanced_Ads_Compatibility {
18
  if ( defined( 'ELEMENTOR_VERSION' ) ) {
19
  add_filter(
20
  'advanced-ads-placement-content-injection-xpath',
21
- array(
22
  $this,
23
  'content_injection_elementor',
24
- ),
25
  10,
26
  1
27
  );
28
  }
29
  // WP Rocket
30
- add_filter( 'rocket_excluded_inline_js_content', array( $this, 'rocket_exclude_inline_js' ) );
31
- add_filter( 'rocket_delay_js_exclusions', array( $this, 'rocket_exclude_inline_js' ) );
32
  // WPML.
33
- add_filter( 'wpml_admin_language_switcher_active_languages', array( $this, 'wpml_language_switcher' ) );
34
  // WordPress SEO by Yoast.
35
- add_filter( 'wpseo_sitemap_entry', array( $this, 'wordpress_seo_noindex_ad_attachments' ), 10, 3 );
36
  // Add shortcode for MailPoet.
37
- add_filter( 'mailpoet_newsletter_shortcode', array( 'Advanced_Ads_Compatibility', 'mailpoet_ad_shortcode' ), 10, 5 );
38
 
39
  // Enable Advanced Custom Fields on ad edit pages.
40
  if ( class_exists( 'ACF', false ) ) {
41
- add_filter( 'advanced-ads-ad-edit-allowed-metaboxes', array( $this, 'advanced_custom_fields_box' ) );
42
  }
43
 
44
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_dequeue_scripts_and_styles' ), 100 );
45
 
46
  if ( defined( 'BORLABS_COOKIE_VERSION' ) ) {
47
  // Check if Verification code & Auto ads ads can be displayed.
48
- add_filter( 'advanced-ads-can-display-ads-in-header', array( $this, 'borlabs_cookie_can_add_auto_ads_code' ), 10 );
49
  }
50
 
51
  // Make sure inline JS in head is executed when Complianz is set to block JS.
52
- add_filter( 'cmplz_script_class', array( $this, 'complianz_exclude_inline_js' ), 10, 2 );
53
 
54
  $this->critical_inline_js = $this->critical_inline_js();
55
  }
@@ -123,7 +123,7 @@ class Advanced_Ads_Compatibility {
123
  case 'advanced-ads_page_advanced-ads-groups':
124
  $translatable_taxonomies = $sitepress->get_translatable_taxonomies();
125
  if ( ! is_array( $translatable_taxonomies ) || ! in_array( 'advanced_ads_groups', $translatable_taxonomies, true ) ) {
126
- return array();
127
  }
128
  break;
129
  // check if Advanced Ads ad post type is translatable.
@@ -131,7 +131,7 @@ class Advanced_Ads_Compatibility {
131
  case 'advanced_ads': // edit page.
132
  $translatable_documents = $sitepress->get_translatable_documents();
133
  if ( empty( $translatable_documents['advanced_ads'] ) ) {
134
- return array();
135
  }
136
  break;
137
  }
@@ -155,10 +155,10 @@ class Advanced_Ads_Compatibility {
155
  static $ad_ids = null;
156
  if ( null === $ad_ids ) {
157
  $ad_ids = Advanced_Ads::get_instance()->get_model()->get_ads(
158
- array(
159
  'post_status' => 'any',
160
  'fields' => 'ids',
161
- )
162
  );
163
  }
164
 
@@ -197,7 +197,7 @@ class Advanced_Ads_Compatibility {
197
 
198
  // only display if the ad group type could work, i.e. default (random) and ordered.
199
  $ad_group = new Advanced_Ads_Group( $group_id );
200
- if ( isset( $ad_group->type ) && in_array( $ad_group->type, array( 'default', 'ordered' ), true ) ) {
201
  return get_ad_group( $group_id );
202
  }
203
 
@@ -216,7 +216,7 @@ class Advanced_Ads_Compatibility {
216
 
217
  $ad = new Advanced_Ads_Ad( $ad_id );
218
  // only display if the ad type could work, i.e. plain text and image ads.
219
- if ( isset( $ad->type ) && in_array( $ad->type, array( 'plain', 'image' ), true ) ) {
220
  return get_ad( $ad_id );
221
  }
222
 
@@ -342,7 +342,7 @@ class Advanced_Ads_Compatibility {
342
  }
343
 
344
  // load ACF field groups dedicated to the Advanced Ads post type
345
- $groups = acf_get_field_groups( array( 'post_type' => Advanced_Ads::POST_TYPE_SLUG ) );
346
 
347
  if ( is_array( $groups ) && $groups ) {
348
  foreach ( $groups as $_group ) {
@@ -362,9 +362,9 @@ class Advanced_Ads_Compatibility {
362
  */
363
  private function critical_inline_js() {
364
  $frontend_prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
365
- $default = array(
366
  sprintf( 'id="%sready"', $frontend_prefix ),
367
- );
368
  /**
369
  * Filters an array of strings of (inline) JavaScript "identifiers" that should not be "optimized"/delayed etc.
370
  *
18
  if ( defined( 'ELEMENTOR_VERSION' ) ) {
19
  add_filter(
20
  'advanced-ads-placement-content-injection-xpath',
21
+ [
22
  $this,
23
  'content_injection_elementor',
24
+ ],
25
  10,
26
  1
27
  );
28
  }
29
  // WP Rocket
30
+ add_filter( 'rocket_excluded_inline_js_content', [ $this, 'rocket_exclude_inline_js' ] );
31
+ add_filter( 'rocket_delay_js_exclusions', [ $this, 'rocket_exclude_inline_js' ] );
32
  // WPML.
33
+ add_filter( 'wpml_admin_language_switcher_active_languages', [ $this, 'wpml_language_switcher' ] );
34
  // WordPress SEO by Yoast.
35
+ add_filter( 'wpseo_sitemap_entry', [ $this, 'wordpress_seo_noindex_ad_attachments' ], 10, 3 );
36
  // Add shortcode for MailPoet.
37
+ add_filter( 'mailpoet_newsletter_shortcode', [ 'Advanced_Ads_Compatibility', 'mailpoet_ad_shortcode' ], 10, 5 );
38
 
39
  // Enable Advanced Custom Fields on ad edit pages.
40
  if ( class_exists( 'ACF', false ) ) {
41
+ add_filter( 'advanced-ads-ad-edit-allowed-metaboxes', [ $this, 'advanced_custom_fields_box' ] );
42
  }
43
 
44
+ add_action( 'admin_enqueue_scripts', [ $this, 'admin_dequeue_scripts_and_styles' ], 100 );
45
 
46
  if ( defined( 'BORLABS_COOKIE_VERSION' ) ) {
47
  // Check if Verification code & Auto ads ads can be displayed.
48
+ add_filter( 'advanced-ads-can-display-ads-in-header', [ $this, 'borlabs_cookie_can_add_auto_ads_code' ], 10 );
49
  }
50
 
51
  // Make sure inline JS in head is executed when Complianz is set to block JS.
52
+ add_filter( 'cmplz_script_class', [ $this, 'complianz_exclude_inline_js' ], 10, 2 );
53
 
54
  $this->critical_inline_js = $this->critical_inline_js();
55
  }
123
  case 'advanced-ads_page_advanced-ads-groups':
124
  $translatable_taxonomies = $sitepress->get_translatable_taxonomies();
125
  if ( ! is_array( $translatable_taxonomies ) || ! in_array( 'advanced_ads_groups', $translatable_taxonomies, true ) ) {
126
+ return [];
127
  }
128
  break;
129
  // check if Advanced Ads ad post type is translatable.
131
  case 'advanced_ads': // edit page.
132
  $translatable_documents = $sitepress->get_translatable_documents();
133
  if ( empty( $translatable_documents['advanced_ads'] ) ) {
134
+ return [];
135
  }
136
  break;
137
  }
155
  static $ad_ids = null;
156
  if ( null === $ad_ids ) {
157
  $ad_ids = Advanced_Ads::get_instance()->get_model()->get_ads(
158
+ [
159
  'post_status' => 'any',
160
  'fields' => 'ids',
161
+ ]
162
  );
163
  }
164
 
197
 
198
  // only display if the ad group type could work, i.e. default (random) and ordered.
199
  $ad_group = new Advanced_Ads_Group( $group_id );
200
+ if ( isset( $ad_group->type ) && in_array( $ad_group->type, [ 'default', 'ordered' ], true ) ) {
201
  return get_ad_group( $group_id );
202
  }
203
 
216
 
217
  $ad = new Advanced_Ads_Ad( $ad_id );
218
  // only display if the ad type could work, i.e. plain text and image ads.
219
+ if ( isset( $ad->type ) && in_array( $ad->type, [ 'plain', 'image' ], true ) ) {
220
  return get_ad( $ad_id );
221
  }
222
 
342
  }
343
 
344
  // load ACF field groups dedicated to the Advanced Ads post type
345
+ $groups = acf_get_field_groups( [ 'post_type' => Advanced_Ads::POST_TYPE_SLUG ] );
346
 
347
  if ( is_array( $groups ) && $groups ) {
348
  foreach ( $groups as $_group ) {
362
  */
363
  private function critical_inline_js() {
364
  $frontend_prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
365
+ $default = [
366
  sprintf( 'id="%sready"', $frontend_prefix ),
367
+ ];
368
  /**
369
  * Filters an array of strings of (inline) JavaScript "identifiers" that should not be "optimized"/delayed etc.
370
  *
classes/display-conditions.php CHANGED
@@ -34,7 +34,7 @@ class Advanced_Ads_Display_Conditions {
34
  *
35
  * @var array
36
  */
37
- protected static $query_var_keys = array(
38
  // 'is_single',
39
  'is_archive',
40
  'is_search',
@@ -44,7 +44,7 @@ class Advanced_Ads_Display_Conditions {
44
  'is_singular',
45
  'is_front_page',
46
  'is_feed',
47
- );
48
 
49
  /**
50
  * List of options for the General Conditions
@@ -52,7 +52,7 @@ class Advanced_Ads_Display_Conditions {
52
  * @var array
53
  */
54
 
55
- protected static $default_general_keys = array(
56
  'is_front_page',
57
  'is_singular',
58
  'is_archive',
@@ -62,7 +62,7 @@ class Advanced_Ads_Display_Conditions {
62
  'is_main_query',
63
  'is_feed',
64
  'is_rest_api',
65
- );
66
 
67
  /**
68
  * Constructor
@@ -70,11 +70,11 @@ class Advanced_Ads_Display_Conditions {
70
  private function __construct() {
71
 
72
  // register filter.
73
- add_filter( 'advanced-ads-ad-select-args', array( $this, 'ad_select_args_callback' ) );
74
- add_filter( 'advanced-ads-can-display', array( $this, 'can_display' ), 10, 2 );
75
 
76
  // register conditions with init hook, register as late as possible so other plugins can use the same hook to add new taxonomies.
77
- add_action( 'init', array( $this, 'register_conditions' ), 100 );
78
  }
79
 
80
  /**
@@ -83,63 +83,63 @@ class Advanced_Ads_Display_Conditions {
83
  * @since 1.7.1.4
84
  */
85
  public function register_conditions() {
86
- $conditions = array(
87
  // post types condition.
88
- 'posttypes' => array(
89
  'label' => __( 'post type', 'advanced-ads' ),
90
  'description' => __( 'Choose the public post types on which to display the ad.', 'advanced-ads' ),
91
- 'metabox' => array( 'Advanced_Ads_Display_Conditions', 'metabox_post_type' ), // callback to generate the metabox.
92
- 'check' => array( 'Advanced_Ads_Display_Conditions', 'check_post_type' ), // callback for frontend check.
93
- ),
94
  // post id condition.
95
- 'postids' => array(
96
  'label' => __( 'specific pages', 'advanced-ads' ),
97
  'description' => __( 'Choose on which individual posts, pages and public post type pages you want to display or hide ads.', 'advanced-ads' ),
98
- 'metabox' => array( 'Advanced_Ads_Display_Conditions', 'metabox_post_ids' ), // callback to generate the metabox.
99
- 'check' => array( 'Advanced_Ads_Display_Conditions', 'check_post_ids' ), // callback for frontend check.
100
- ),
101
  // general conditions.
102
- 'general' => array(
103
  'label' => __( 'general conditions', 'advanced-ads' ),
104
- 'metabox' => array( 'Advanced_Ads_Display_Conditions', 'metabox_general' ), // callback to generate the metabox.
105
- 'check' => array( 'Advanced_Ads_Display_Conditions', 'check_general' ), // callback for frontend check.
106
- ),
107
  // author conditions.
108
- 'author' => array(
109
  'label' => __( 'author', 'advanced-ads' ),
110
- 'metabox' => array( 'Advanced_Ads_Display_Conditions', 'metabox_author' ), // callback to generate the metabox.
111
- 'check' => array( 'Advanced_Ads_Display_Conditions', 'check_author' ), // callback for frontend check.
112
- ),
113
  // display ads only in content older or younger than a specific age.
114
- 'content_age' => array(
115
  'label' => __( 'content age', 'advanced-ads' ),
116
  'description' => __( 'Display ads based on age of the page.', 'advanced-ads' ),
117
- 'metabox' => array( 'Advanced_Ads_Display_Conditions', 'metabox_content_age' ), // callback to generate the metabox.
118
- 'check' => array( 'Advanced_Ads_Display_Conditions', 'check_content_age' ), // callback for frontend check.
119
- ),
120
  // condition for taxonomies in general.
121
- 'taxonomy' => array(
122
  'label' => __( 'taxonomy', 'advanced-ads' ),
123
  'description' => __( 'Display ads based on the taxonomy of an archive page.', 'advanced-ads' ),
124
- 'metabox' => array( 'Advanced_Ads_Display_Conditions', 'metabox_taxonomies' ), // callback to generate the metabox.
125
- 'check' => array( 'Advanced_Ads_Display_Conditions', 'check_taxonomy' ), // callback for frontend check.
126
- ),
127
- );
128
 
129
  // register a condition for each taxonomy for posts.
130
  $taxonomies = get_taxonomies(
131
- array(
132
  'public' => true,
133
  'publicly_queryable' => true,
134
- ),
135
  'objects',
136
  'or'
137
  );
138
 
139
- $tax_label_counts = array();
140
 
141
  foreach ( $taxonomies as $_tax ) :
142
- if ( in_array( $_tax->name, array( 'advanced_ads_groups' ), true ) ) {
143
  continue;
144
  }
145
 
@@ -158,23 +158,23 @@ class Advanced_Ads_Display_Conditions {
158
  $archive_label = sprintf( '%s (%s)', $_tax->labels->singular_name, $_tax->name );
159
  }
160
 
161
- $conditions[ 'taxonomy_' . $_tax->name ] = array(
162
  'label' => $label,
163
- 'metabox' => array( 'Advanced_Ads_Display_Conditions', 'metabox_taxonomy_terms' ), // callback to generate the metabox.
164
- 'check' => array( 'Advanced_Ads_Display_Conditions', 'check_taxonomies' ), // callback for frontend check.
165
  'taxonomy' => $_tax->name, // unique for this type: the taxonomy name.
166
- );
167
 
168
- $conditions[ 'archive_' . $_tax->name ] = array(
169
  'label' => sprintf(
170
  // translators: %s is a label of an archive page.
171
  __( 'archive: %s', 'advanced-ads' ),
172
  $archive_label
173
  ),
174
- 'metabox' => array( 'Advanced_Ads_Display_Conditions', 'metabox_taxonomy_terms' ), // callback to generate the metabox.
175
- 'check' => array( 'Advanced_Ads_Display_Conditions', 'check_taxonomy_archive' ), // callback for frontend check.
176
  'taxonomy' => $_tax->name, // unique for this type: the taxonomy name.
177
- );
178
  endforeach;
179
 
180
  $this->conditions = apply_filters( 'advanced-ads-display-conditions', $conditions );
@@ -214,7 +214,7 @@ class Advanced_Ads_Display_Conditions {
214
  *
215
  * @return bool false, if ad can’t be delivered
216
  */
217
- public static function frontend_check( $options = array(), $ad = false ) {
218
  $display_conditions = self::get_instance()->conditions;
219
 
220
  if ( is_array( $options ) && isset( $options['type'] ) && isset( $display_conditions[ $options['type'] ]['check'] ) ) {
@@ -225,7 +225,7 @@ class Advanced_Ads_Display_Conditions {
225
 
226
  // call frontend check callback.
227
  if ( method_exists( $check[0], $check[1] ) ) {
228
- return call_user_func( array( $check[0], $check[1] ), $options, $ad );
229
  }
230
 
231
  return true;
@@ -246,7 +246,7 @@ class Advanced_Ads_Display_Conditions {
246
  * - set to array of condition ID's to include only them.
247
  * }
248
  */
249
- public static function render_condition_list( array $set_conditions, $list_target = '', $form_name = '', $options = array() ) {
250
  $conditions = self::get_instance()->get_conditions();
251
 
252
 
@@ -257,7 +257,7 @@ class Advanced_Ads_Display_Conditions {
257
  } );
258
  } elseif ( is_array( $options['in'] ) ) {
259
  // Include already set condition types.
260
- $set_types = array();
261
  foreach ( $set_conditions as $set_condition ) {
262
  if ( isset( $set_condition['type'] ) ) {
263
  $set_types[] = $set_condition['type'];
@@ -282,7 +282,7 @@ class Advanced_Ads_Display_Conditions {
282
  */
283
 
284
  // add mockup conditions if add-ons are missing.
285
- $pro_conditions = array();
286
  if ( ! defined( 'AAP_VERSION' ) ) {
287
  $pro_conditions[] = __( 'parent page', 'advanced-ads' );
288
  $pro_conditions[] = __( 'post meta', 'advanced-ads' );
@@ -373,7 +373,7 @@ class Advanced_Ads_Display_Conditions {
373
 
374
  // get values and select operator based on previous settings.
375
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
376
- $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : array();
377
 
378
  // form name basis.
379
  $name = self::get_form_name_with_index( $form_name, $index );
@@ -386,10 +386,10 @@ class Advanced_Ads_Display_Conditions {
386
 
387
  // set defaults.
388
  $post_types = get_post_types(
389
- array(
390
  'public' => true,
391
  'publicly_queryable' => true,
392
- ),
393
  'object',
394
  'or'
395
  );
@@ -442,7 +442,7 @@ class Advanced_Ads_Display_Conditions {
442
 
443
  // get values and select operator based on previous settings.
444
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
445
- $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : array();
446
 
447
  // form name basis.
448
  $name = self::get_form_name_with_index( $form_name, $index );
@@ -455,12 +455,12 @@ class Advanced_Ads_Display_Conditions {
455
 
456
  // set defaults.
457
  $max_authors = absint( apply_filters( 'advanced-ads-admin-max-terms', 50 ) );
458
- $args = array(
459
  'orderby' => 'nicename',
460
  'number' => $max_authors,
461
- );
462
  if ( version_compare( get_bloginfo( 'version' ), '5.9' ) > -1 ) {
463
- $args['capability'] = array( 'edit_posts' );
464
  } else {
465
  $args['who'] = 'authors';
466
  }
@@ -496,7 +496,7 @@ class Advanced_Ads_Display_Conditions {
496
 
497
  // get values and select operator based on previous settings.
498
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
499
- $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : array();
500
 
501
  // limit the number of terms so many terms don’t break the admin page.
502
  $max_terms = absint( apply_filters( 'advanced-ads-admin-max-terms', 50 ) );
@@ -534,14 +534,14 @@ class Advanced_Ads_Display_Conditions {
534
  return;
535
  }
536
 
537
- $taxonomies = get_taxonomies( array( 'public' => 1 ), 'objects' );
538
 
539
  $name = self::get_form_name_with_index( $form_name, $index );
540
  $rand = md5( $name );
541
 
542
  // get values and select operator based on previous settings.
543
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
544
- $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : array();
545
 
546
  self::render_type_field( $options['type'], $name );
547
 
@@ -588,14 +588,14 @@ class Advanced_Ads_Display_Conditions {
588
  *
589
  * @return array|int|WP_Error
590
  */
591
- public static function display_term_list( $taxonomy, $checked = array(), $inputname = '', $max_terms = 50, $index = 0 ) {
592
 
593
  $terms = get_terms(
594
  $taxonomy->name,
595
- array(
596
  'hide_empty' => false,
597
  'number' => $max_terms,
598
- )
599
  );
600
  $rand = md5( $inputname );
601
 
@@ -605,7 +605,7 @@ class Advanced_Ads_Display_Conditions {
605
 
606
  // query active terms.
607
  if ( is_array( $checked ) && count( $checked ) ) {
608
- $args = array( 'hide_empty' => false );
609
  $args['include'] = $checked;
610
  $checked_terms = get_terms( $taxonomy->name, $args );
611
  // phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen, Squiz.PHP.EmbeddedPhp.ContentAfterOpen, Squiz.PHP.EmbeddedPhp.ContentBeforeEnd, Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- Prevent whitespaces between labels
@@ -657,7 +657,7 @@ class Advanced_Ads_Display_Conditions {
657
 
658
  // get values and select operator based on previous settings.
659
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
660
- $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : array();
661
 
662
  // form name basis.
663
  $name = self::get_form_name_with_index( $form_name, $index );
@@ -672,15 +672,15 @@ class Advanced_Ads_Display_Conditions {
672
  <?php
673
  // Query active post ids.
674
  // phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen, Squiz.PHP.EmbeddedPhp.ContentAfterOpen, Squiz.PHP.EmbeddedPhp.ContentBeforeEnd, Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- Prevent whitespaces between labels
675
- if ( array() !== $values ) {
676
- $args = array(
677
  'post_type' => 'any',
678
  'post__in' => $values,
679
  'posts_per_page' => - 1,
680
  'order' => 'ASC',
681
  'order_by' => 'title',
682
 
683
- );
684
 
685
  $the_query = new WP_Query( $args );
686
  while ( $the_query->have_posts() ) {
@@ -720,7 +720,7 @@ class Advanced_Ads_Display_Conditions {
720
  }
721
 
722
  $name = self::get_form_name_with_index( $form_name, $index );
723
- $values = isset( $options['value'] ) ? $options['value'] : array();
724
  ?>
725
  <div class="advads-conditions-single advads-buttonset">
726
  <?php
@@ -731,7 +731,7 @@ class Advanced_Ads_Display_Conditions {
731
  foreach ( $conditions as $_key => $_condition ) :
732
 
733
  // activate by default.
734
- $value = ( array() === $values || in_array( $_key, $values, true ) ) ? 1 : 0;
735
 
736
  $field_id = "advads-conditions-$_key-$rand";
737
  ?><input type="checkbox" id="<?php echo $field_id; ?>" name="<?php echo $name; ?>[value][]"
@@ -750,53 +750,53 @@ class Advanced_Ads_Display_Conditions {
750
  */
751
  public static function general_conditions() {
752
  return $conditions = apply_filters( 'advanced-ads-display-conditions-general',
753
- array(
754
- 'is_front_page' => array(
755
  'label' => __( 'Home Page', 'advanced-ads' ),
756
  'description' => __( 'show on Home page', 'advanced-ads' ),
757
  'type' => 'radio',
758
- ),
759
- 'is_singular' => array(
760
  'label' => __( 'Singular Pages', 'advanced-ads' ),
761
  'description' => __( 'show on singular pages/posts', 'advanced-ads' ),
762
  'type' => 'radio',
763
- ),
764
- 'is_archive' => array(
765
  'label' => __( 'Archive Pages', 'advanced-ads' ),
766
  'description' => __( 'show on any type of archive page (category, tag, author and date)', 'advanced-ads' ),
767
  'type' => 'radio',
768
- ),
769
- 'is_search' => array(
770
  'label' => __( 'Search Results', 'advanced-ads' ),
771
  'description' => __( 'show on search result pages', 'advanced-ads' ),
772
  'type' => 'radio',
773
- ),
774
- 'is_404' => array(
775
  'label' => __( '404 Page', 'advanced-ads' ),
776
  'description' => __( 'show on 404 error page', 'advanced-ads' ),
777
  'type' => 'radio',
778
- ),
779
- 'is_attachment' => array(
780
  'label' => __( 'Attachment Pages', 'advanced-ads' ),
781
  'description' => __( 'show on attachment pages', 'advanced-ads' ),
782
  'type' => 'radio',
783
- ),
784
- 'is_main_query' => array(
785
  'label' => __( 'Secondary Queries', 'advanced-ads' ),
786
  'description' => __( 'allow ads in secondary queries', 'advanced-ads' ),
787
  'type' => 'radio',
788
- ),
789
- 'is_feed' => array(
790
  'label' => __( 'RSS Feed', 'advanced-ads' ),
791
  'description' => __( 'allow ads in RSS Feed', 'advanced-ads' ),
792
  'type' => 'radio',
793
- ),
794
- 'is_rest_api' => array(
795
  'label' => __( 'REST API', 'advanced-ads' ),
796
  'description' => __( 'allow ads in REST API', 'advanced-ads' ),
797
  'type' => 'radio',
798
- ),
799
- )
800
  );
801
  }
802
 
@@ -1188,7 +1188,7 @@ class Advanced_Ads_Display_Conditions {
1188
  */
1189
  public static function in_array( $id, $ids ) {
1190
  // empty?
1191
- if ( ! isset( $id ) || array() === $id ) {
1192
  return;
1193
  }
1194
 
@@ -1197,7 +1197,7 @@ class Advanced_Ads_Display_Conditions {
1197
  return;
1198
  }
1199
 
1200
- return is_array( $id ) ? array() !== array_intersect( $id, $ids ) : in_array( $id, $ids );
1201
  }
1202
 
1203
  /**
@@ -1312,7 +1312,7 @@ class Advanced_Ads_Display_Conditions {
1312
 
1313
  if ( isset( $post ) ) {
1314
  if ( ! isset( $args['post'] ) ) {
1315
- $args['post'] = array();
1316
  }
1317
  if ( ! isset( $args['post']['id'] ) ) {
1318
 
@@ -1346,7 +1346,7 @@ class Advanced_Ads_Display_Conditions {
1346
  // pass query arguments.
1347
  if ( isset( $wp_the_query ) ) {
1348
  if ( ! isset( $args['wp_the_query'] ) ) {
1349
- $args['wp_the_query'] = array();
1350
  }
1351
  $query = $wp_the_query->get_queried_object();
1352
  // term_id exists only for taxonomy archive pages.
@@ -1396,13 +1396,13 @@ class Advanced_Ads_Display_Conditions {
1396
 
1397
  // use ID and not search field if ID given.
1398
  if ( 0 !== absint( $query['s'] ) && strlen( $query['s'] ) === strlen( absint( $query['s'] ) ) ) {
1399
- $query['post__in'] = array( absint( $query['s'] ) );
1400
  unset( $query['s'] );
1401
  }
1402
 
1403
  $query['suppress_filters'] = false;
1404
  $query['orderby'] = 'post_title';
1405
- $query['post_status'] = array( 'publish', 'pending', 'draft', 'future' );
1406
 
1407
  return $query;
1408
  }
34
  *
35
  * @var array
36
  */
37
+ protected static $query_var_keys = [
38
  // 'is_single',
39
  'is_archive',
40
  'is_search',
44
  'is_singular',
45
  'is_front_page',
46
  'is_feed',
47
+ ];
48
 
49
  /**
50
  * List of options for the General Conditions
52
  * @var array
53
  */
54
 
55
+ protected static $default_general_keys = [
56
  'is_front_page',
57
  'is_singular',
58
  'is_archive',
62
  'is_main_query',
63
  'is_feed',
64
  'is_rest_api',
65
+ ];
66
 
67
  /**
68
  * Constructor
70
  private function __construct() {
71
 
72
  // register filter.
73
+ add_filter( 'advanced-ads-ad-select-args', [ $this, 'ad_select_args_callback' ] );
74
+ add_filter( 'advanced-ads-can-display', [ $this, 'can_display' ], 10, 2 );
75
 
76
  // register conditions with init hook, register as late as possible so other plugins can use the same hook to add new taxonomies.
77
+ add_action( 'init', [ $this, 'register_conditions' ], 100 );
78
  }
79
 
80
  /**
83
  * @since 1.7.1.4
84
  */
85
  public function register_conditions() {
86
+ $conditions = [
87
  // post types condition.
88
+ 'posttypes' => [
89
  'label' => __( 'post type', 'advanced-ads' ),
90
  'description' => __( 'Choose the public post types on which to display the ad.', 'advanced-ads' ),
91
+ 'metabox' => [ 'Advanced_Ads_Display_Conditions', 'metabox_post_type' ], // callback to generate the metabox.
92
+ 'check' => [ 'Advanced_Ads_Display_Conditions', 'check_post_type' ], // callback for frontend check.
93
+ ],
94
  // post id condition.
95
+ 'postids' => [
96
  'label' => __( 'specific pages', 'advanced-ads' ),
97
  'description' => __( 'Choose on which individual posts, pages and public post type pages you want to display or hide ads.', 'advanced-ads' ),
98
+ 'metabox' => [ 'Advanced_Ads_Display_Conditions', 'metabox_post_ids' ], // callback to generate the metabox.
99
+ 'check' => [ 'Advanced_Ads_Display_Conditions', 'check_post_ids' ], // callback for frontend check.
100
+ ],
101
  // general conditions.
102
+ 'general' => [
103
  'label' => __( 'general conditions', 'advanced-ads' ),
104
+ 'metabox' => [ 'Advanced_Ads_Display_Conditions', 'metabox_general' ], // callback to generate the metabox.
105
+ 'check' => [ 'Advanced_Ads_Display_Conditions', 'check_general' ], // callback for frontend check.
106
+ ],
107
  // author conditions.
108
+ 'author' => [
109
  'label' => __( 'author', 'advanced-ads' ),
110
+ 'metabox' => [ 'Advanced_Ads_Display_Conditions', 'metabox_author' ], // callback to generate the metabox.
111
+ 'check' => [ 'Advanced_Ads_Display_Conditions', 'check_author' ], // callback for frontend check.
112
+ ],
113
  // display ads only in content older or younger than a specific age.
114
+ 'content_age' => [
115
  'label' => __( 'content age', 'advanced-ads' ),
116
  'description' => __( 'Display ads based on age of the page.', 'advanced-ads' ),
117
+ 'metabox' => [ 'Advanced_Ads_Display_Conditions', 'metabox_content_age' ], // callback to generate the metabox.
118
+ 'check' => [ 'Advanced_Ads_Display_Conditions', 'check_content_age' ], // callback for frontend check.
119
+ ],
120
  // condition for taxonomies in general.
121
+ 'taxonomy' => [
122
  'label' => __( 'taxonomy', 'advanced-ads' ),
123
  'description' => __( 'Display ads based on the taxonomy of an archive page.', 'advanced-ads' ),
124
+ 'metabox' => [ 'Advanced_Ads_Display_Conditions', 'metabox_taxonomies' ], // callback to generate the metabox.
125
+ 'check' => [ 'Advanced_Ads_Display_Conditions', 'check_taxonomy' ], // callback for frontend check.
126
+ ],
127
+ ];
128
 
129
  // register a condition for each taxonomy for posts.
130
  $taxonomies = get_taxonomies(
131
+ [
132
  'public' => true,
133
  'publicly_queryable' => true,
134
+ ],
135
  'objects',
136
  'or'
137
  );
138
 
139
+ $tax_label_counts = [];
140
 
141
  foreach ( $taxonomies as $_tax ) :
142
+ if ( in_array( $_tax->name, [ 'advanced_ads_groups' ], true ) ) {
143
  continue;
144
  }
145
 
158
  $archive_label = sprintf( '%s (%s)', $_tax->labels->singular_name, $_tax->name );
159
  }
160
 
161
+ $conditions[ 'taxonomy_' . $_tax->name ] = [
162
  'label' => $label,
163
+ 'metabox' => [ 'Advanced_Ads_Display_Conditions', 'metabox_taxonomy_terms' ], // callback to generate the metabox.
164
+ 'check' => [ 'Advanced_Ads_Display_Conditions', 'check_taxonomies' ], // callback for frontend check.
165
  'taxonomy' => $_tax->name, // unique for this type: the taxonomy name.
166
+ ];
167
 
168
+ $conditions[ 'archive_' . $_tax->name ] = [
169
  'label' => sprintf(
170
  // translators: %s is a label of an archive page.
171
  __( 'archive: %s', 'advanced-ads' ),
172
  $archive_label
173
  ),
174
+ 'metabox' => [ 'Advanced_Ads_Display_Conditions', 'metabox_taxonomy_terms' ], // callback to generate the metabox.
175
+ 'check' => [ 'Advanced_Ads_Display_Conditions', 'check_taxonomy_archive' ], // callback for frontend check.
176
  'taxonomy' => $_tax->name, // unique for this type: the taxonomy name.
177
+ ];
178
  endforeach;
179
 
180
  $this->conditions = apply_filters( 'advanced-ads-display-conditions', $conditions );
214
  *
215
  * @return bool false, if ad can’t be delivered
216
  */
217
+ public static function frontend_check( $options = [], $ad = false ) {
218
  $display_conditions = self::get_instance()->conditions;
219
 
220
  if ( is_array( $options ) && isset( $options['type'] ) && isset( $display_conditions[ $options['type'] ]['check'] ) ) {
225
 
226
  // call frontend check callback.
227
  if ( method_exists( $check[0], $check[1] ) ) {
228
+ return call_user_func( [ $check[0], $check[1] ], $options, $ad );
229
  }
230
 
231
  return true;
246
  * - set to array of condition ID's to include only them.
247
  * }
248
  */
249
+ public static function render_condition_list( array $set_conditions, $list_target = '', $form_name = '', $options = [] ) {
250
  $conditions = self::get_instance()->get_conditions();
251
 
252
 
257
  } );
258
  } elseif ( is_array( $options['in'] ) ) {
259
  // Include already set condition types.
260
+ $set_types = [];
261
  foreach ( $set_conditions as $set_condition ) {
262
  if ( isset( $set_condition['type'] ) ) {
263
  $set_types[] = $set_condition['type'];
282
  */
283
 
284
  // add mockup conditions if add-ons are missing.
285
+ $pro_conditions = [];
286
  if ( ! defined( 'AAP_VERSION' ) ) {
287
  $pro_conditions[] = __( 'parent page', 'advanced-ads' );
288
  $pro_conditions[] = __( 'post meta', 'advanced-ads' );
373
 
374
  // get values and select operator based on previous settings.
375
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
376
+ $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : [];
377
 
378
  // form name basis.
379
  $name = self::get_form_name_with_index( $form_name, $index );
386
 
387
  // set defaults.
388
  $post_types = get_post_types(
389
+ [
390
  'public' => true,
391
  'publicly_queryable' => true,
392
+ ],
393
  'object',
394
  'or'
395
  );
442
 
443
  // get values and select operator based on previous settings.
444
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
445
+ $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : [];
446
 
447
  // form name basis.
448
  $name = self::get_form_name_with_index( $form_name, $index );
455
 
456
  // set defaults.
457
  $max_authors = absint( apply_filters( 'advanced-ads-admin-max-terms', 50 ) );
458
+ $args = [
459
  'orderby' => 'nicename',
460
  'number' => $max_authors,
461
+ ];
462
  if ( version_compare( get_bloginfo( 'version' ), '5.9' ) > -1 ) {
463
+ $args['capability'] = [ 'edit_posts' ];
464
  } else {
465
  $args['who'] = 'authors';
466
  }
496
 
497
  // get values and select operator based on previous settings.
498
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
499
+ $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : [];
500
 
501
  // limit the number of terms so many terms don’t break the admin page.
502
  $max_terms = absint( apply_filters( 'advanced-ads-admin-max-terms', 50 ) );
534
  return;
535
  }
536
 
537
+ $taxonomies = get_taxonomies( [ 'public' => 1 ], 'objects' );
538
 
539
  $name = self::get_form_name_with_index( $form_name, $index );
540
  $rand = md5( $name );
541
 
542
  // get values and select operator based on previous settings.
543
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
544
+ $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : [];
545
 
546
  self::render_type_field( $options['type'], $name );
547
 
588
  *
589
  * @return array|int|WP_Error
590
  */
591
+ public static function display_term_list( $taxonomy, $checked = [], $inputname = '', $max_terms = 50, $index = 0 ) {
592
 
593
  $terms = get_terms(
594
  $taxonomy->name,
595
+ [
596
  'hide_empty' => false,
597
  'number' => $max_terms,
598
+ ]
599
  );
600
  $rand = md5( $inputname );
601
 
605
 
606
  // query active terms.
607
  if ( is_array( $checked ) && count( $checked ) ) {
608
+ $args = [ 'hide_empty' => false ];
609
  $args['include'] = $checked;
610
  $checked_terms = get_terms( $taxonomy->name, $args );
611
  // phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen, Squiz.PHP.EmbeddedPhp.ContentAfterOpen, Squiz.PHP.EmbeddedPhp.ContentBeforeEnd, Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- Prevent whitespaces between labels
657
 
658
  // get values and select operator based on previous settings.
659
  $operator = ( isset( $options['operator'] ) && 'is_not' === $options['operator'] ) ? 'is_not' : 'is';
660
+ $values = ( isset( $options['value'] ) && is_array( $options['value'] ) ) ? $options['value'] : [];
661
 
662
  // form name basis.
663
  $name = self::get_form_name_with_index( $form_name, $index );
672
  <?php
673
  // Query active post ids.
674
  // phpcs:disable Squiz.PHP.EmbeddedPhp.ContentBeforeOpen, Squiz.PHP.EmbeddedPhp.ContentAfterOpen, Squiz.PHP.EmbeddedPhp.ContentBeforeEnd, Squiz.PHP.EmbeddedPhp.ContentAfterEnd -- Prevent whitespaces between labels
675
+ if ( [] !== $values ) {
676
+ $args = [
677
  'post_type' => 'any',
678
  'post__in' => $values,
679
  'posts_per_page' => - 1,
680
  'order' => 'ASC',
681
  'order_by' => 'title',
682
 
683
+ ];
684
 
685
  $the_query = new WP_Query( $args );
686
  while ( $the_query->have_posts() ) {
720
  }
721
 
722
  $name = self::get_form_name_with_index( $form_name, $index );
723
+ $values = isset( $options['value'] ) ? $options['value'] : [];
724
  ?>
725
  <div class="advads-conditions-single advads-buttonset">
726
  <?php
731
  foreach ( $conditions as $_key => $_condition ) :
732
 
733
  // activate by default.
734
+ $value = ( [] === $values || in_array( $_key, $values, true ) ) ? 1 : 0;
735
 
736
  $field_id = "advads-conditions-$_key-$rand";
737
  ?><input type="checkbox" id="<?php echo $field_id; ?>" name="<?php echo $name; ?>[value][]"
750
  */
751
  public static function general_conditions() {
752
  return $conditions = apply_filters( 'advanced-ads-display-conditions-general',
753
+ [
754
+ 'is_front_page' => [
755
  'label' => __( 'Home Page', 'advanced-ads' ),
756
  'description' => __( 'show on Home page', 'advanced-ads' ),
757
  'type' => 'radio',
758
+ ],
759
+ 'is_singular' => [
760
  'label' => __( 'Singular Pages', 'advanced-ads' ),
761
  'description' => __( 'show on singular pages/posts', 'advanced-ads' ),
762
  'type' => 'radio',
763
+ ],
764
+ 'is_archive' => [
765
  'label' => __( 'Archive Pages', 'advanced-ads' ),
766
  'description' => __( 'show on any type of archive page (category, tag, author and date)', 'advanced-ads' ),
767
  'type' => 'radio',
768
+ ],
769
+ 'is_search' => [
770
  'label' => __( 'Search Results', 'advanced-ads' ),
771
  'description' => __( 'show on search result pages', 'advanced-ads' ),
772
  'type' => 'radio',
773
+ ],
774
+ 'is_404' => [
775
  'label' => __( '404 Page', 'advanced-ads' ),
776
  'description' => __( 'show on 404 error page', 'advanced-ads' ),
777
  'type' => 'radio',
778
+ ],
779
+ 'is_attachment' => [
780
  'label' => __( 'Attachment Pages', 'advanced-ads' ),
781
  'description' => __( 'show on attachment pages', 'advanced-ads' ),
782
  'type' => 'radio',
783
+ ],
784
+ 'is_main_query' => [
785
  'label' => __( 'Secondary Queries', 'advanced-ads' ),
786
  'description' => __( 'allow ads in secondary queries', 'advanced-ads' ),
787
  'type' => 'radio',
788
+ ],
789
+ 'is_feed' => [
790
  'label' => __( 'RSS Feed', 'advanced-ads' ),
791
  'description' => __( 'allow ads in RSS Feed', 'advanced-ads' ),
792
  'type' => 'radio',
793
+ ],
794
+ 'is_rest_api' => [
795
  'label' => __( 'REST API', 'advanced-ads' ),
796
  'description' => __( 'allow ads in REST API', 'advanced-ads' ),
797
  'type' => 'radio',
798
+ ],
799
+ ]
800
  );
801
  }
802
 
1188
  */
1189
  public static function in_array( $id, $ids ) {
1190
  // empty?
1191
+ if ( ! isset( $id ) || [] === $id ) {
1192
  return;
1193
  }
1194
 
1197
  return;
1198
  }
1199
 
1200
+ return is_array( $id ) ? [] !== array_intersect( $id, $ids ) : in_array( $id, $ids );
1201
  }
1202
 
1203
  /**
1312
 
1313
  if ( isset( $post ) ) {
1314
  if ( ! isset( $args['post'] ) ) {
1315
+ $args['post'] = [];
1316
  }
1317
  if ( ! isset( $args['post']['id'] ) ) {
1318
 
1346
  // pass query arguments.
1347
  if ( isset( $wp_the_query ) ) {
1348
  if ( ! isset( $args['wp_the_query'] ) ) {
1349
+ $args['wp_the_query'] = [];
1350
  }
1351
  $query = $wp_the_query->get_queried_object();
1352
  // term_id exists only for taxonomy archive pages.
1396
 
1397
  // use ID and not search field if ID given.
1398
  if ( 0 !== absint( $query['s'] ) && strlen( $query['s'] ) === strlen( absint( $query['s'] ) ) ) {
1399
+ $query['post__in'] = [ absint( $query['s'] ) ];
1400
  unset( $query['s'] );
1401
  }
1402
 
1403
  $query['suppress_filters'] = false;
1404
  $query['orderby'] = 'post_title';
1405
+ $query['post_status'] = [ 'publish', 'pending', 'draft', 'future' ];
1406
 
1407
  return $query;
1408
  }
classes/filesystem.php CHANGED
@@ -32,9 +32,9 @@ class Advanced_Ads_Filesystem {
32
  * not exist, a WP_Error object will be returned.
33
  * @return bool|WP_Error True if able to connect, false or a WP_Error otherwise.
34
  */
35
- public function fs_connect( $directories = array() ) {
36
  global $wp_filesystem;
37
- $directories = ( is_array( $directories ) && count( $directories ) ) ? $directories : array( WP_CONTENT_DIR );
38
 
39
  // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer.
40
  ob_start();
32
  * not exist, a WP_Error object will be returned.
33
  * @return bool|WP_Error True if able to connect, false or a WP_Error otherwise.
34
  */
35
+ public function fs_connect( $directories = [] ) {
36
  global $wp_filesystem;
37
+ $directories = ( is_array( $directories ) && count( $directories ) ) ? $directories : [ WP_CONTENT_DIR ];
38
 
39
  // This will output a credentials form in event of failure, We don't want that, so just hide with a buffer.
40
  ob_start();
classes/frontend-notices.php CHANGED
@@ -32,7 +32,7 @@ class Advanced_Ads_Frontend_Notices {
32
  *
33
  * @var array
34
  */
35
- public $notices = array();
36
 
37
  /**
38
  * Advanced_Ads_Ad_Health_Notices constructor.
@@ -70,18 +70,18 @@ class Advanced_Ads_Frontend_Notices {
70
  * attributes:
71
  * - append_text – text added to the default message
72
  */
73
- public function update( $notice_key, $atts = array() ) {
74
 
75
  // check if the notice already exists.
76
  $notice_key = esc_attr( $notice_key );
77
  $options_before = $options = $this->options();
78
 
79
  // load notices from "queue".
80
- $notices = isset( $options['notices'] ) ? $options['notices'] : array();
81
 
82
  // check if notice_key was already saved, this prevents the same notice from showing up in different forms.
83
  if ( ! isset( $notices[ $notice_key ] ) ) {
84
- $notices[ $notice_key ] = array();
85
  } else {
86
  // add `closed` marker, if given.
87
  if ( ! empty( $atts['closed'] ) ) {
@@ -106,10 +106,10 @@ class Advanced_Ads_Frontend_Notices {
106
  */
107
  public function options() {
108
  if ( ! isset( $this->options ) ) {
109
- $this->options = get_option( ADVADS_SLUG . '-frontend-notices', array() );
110
  }
111
  if ( ! is_array( $this->options ) ) {
112
- $this->options = array();
113
  }
114
 
115
  return $this->options;
@@ -122,7 +122,7 @@ class Advanced_Ads_Frontend_Notices {
122
  */
123
  public function update_options( array $options ) {
124
  // do not allow to clear options.
125
- if ( array() === $options ) {
126
  return;
127
  }
128
 
32
  *
33
  * @var array
34
  */
35
+ public $notices = [];
36
 
37
  /**
38
  * Advanced_Ads_Ad_Health_Notices constructor.
70
  * attributes:
71
  * - append_text – text added to the default message
72
  */
73
+ public function update( $notice_key, $atts = [] ) {
74
 
75
  // check if the notice already exists.
76
  $notice_key = esc_attr( $notice_key );
77
  $options_before = $options = $this->options();
78
 
79
  // load notices from "queue".
80
+ $notices = isset( $options['notices'] ) ? $options['notices'] : [];
81
 
82
  // check if notice_key was already saved, this prevents the same notice from showing up in different forms.
83
  if ( ! isset( $notices[ $notice_key ] ) ) {
84
+ $notices[ $notice_key ] = [];
85
  } else {
86
  // add `closed` marker, if given.
87
  if ( ! empty( $atts['closed'] ) ) {
106
  */
107
  public function options() {
108
  if ( ! isset( $this->options ) ) {
109
+ $this->options = get_option( ADVADS_SLUG . '-frontend-notices', [] );
110
  }
111
  if ( ! is_array( $this->options ) ) {
112
+ $this->options = [];
113
  }
114
 
115
  return $this->options;
122
  */
123
  public function update_options( array $options ) {
124
  // do not allow to clear options.
125
+ if ( [] === $options ) {
126
  return;
127
  }
128
 
classes/frontend_checks.php CHANGED
@@ -19,10 +19,10 @@ class Advanced_Ads_Frontend_Checks {
19
  */
20
  public function __construct() {
21
  // Wait until other plugins (for example Elementor) have disabled admin bar using `show_admin_bar` filter.
22
- add_action( 'template_redirect', array( $this, 'init' ), 11 );
23
 
24
  if ( wp_doing_ajax() ) {
25
- add_filter( 'advanced-ads-ad-output', array( $this, 'after_ad_output' ), 10, 2 );
26
  }
27
  }
28
 
@@ -35,16 +35,16 @@ class Advanced_Ads_Frontend_Checks {
35
  && current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) )
36
  && Advanced_Ads_Ad_Health_Notices::notices_enabled()
37
  ) {
38
- add_action( 'admin_bar_menu', array( $this, 'add_admin_bar_menu' ), 1000 );
39
- add_filter( 'the_content', array( $this, 'set_did_the_content' ) );
40
- add_action( 'wp_footer', array( $this, 'footer_checks' ), -101 );
41
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
42
- add_filter( 'advanced-ads-ad-select-args', array( $this, 'ad_select_args_callback' ) );
43
- add_filter( 'advanced-ads-ad-output', array( $this, 'after_ad_output' ), 10, 2 );
44
  }
45
 
46
  if ( Advanced_Ads_Ad_Health_Notices::notices_enabled() ) {
47
- add_action( 'body_class', array( $this, 'body_class' ) );
48
  }
49
  }
50
 
@@ -70,7 +70,7 @@ class Advanced_Ads_Frontend_Checks {
70
 
71
  // we don’t have our own script, so we attach this information to jquery
72
  wp_localize_script( 'jquery', 'advads_frontend_checks',
73
- array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
74
  }
75
 
76
  /**
@@ -103,84 +103,84 @@ class Advanced_Ads_Frontend_Checks {
103
  // check if AdSense loads Auto Ads ads
104
  // Hidden, will be shown using js.
105
  if( ! isset( $adsense_options['violation-warnings-disable'] ) ) {
106
- $nodes[] = array( 'type' => 2, 'data' => array(
107
  'parent' => 'advanced_ads_ad_health',
108
  'id' => 'advanced_ads_autoads_displayed',
109
  'title' => __( 'Random AdSense ads', 'advanced-ads' ),
110
  'href' => ADVADS_URL . 'adsense-in-random-positions-auto-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=frontend-autoads-ads',
111
- 'meta' => array(
112
  'class' => 'hidden',
113
  'target' => '_blank'
114
- )
115
- ) );
116
  }
117
 
118
  // check if current user was identified as a bot.
119
  if( Advanced_Ads::get_instance()->is_bot() ) {
120
- $nodes[] = array( 'type' => 1, 'data' => array(
121
  'parent' => 'advanced_ads_ad_health',
122
  'id' => 'advanced_ads_user_is_bot',
123
  'title' => __( 'You look like a bot', 'advanced-ads' ),
124
  'href' => ADVADS_URL . 'manual/ad-health/#look-like-bot',
125
- 'meta' => array(
126
  'class' => 'advanced_ads_ad_health_warning',
127
  'target' => '_blank'
128
- )
129
- ) );
130
  }
131
 
132
  // check if an ad blocker is enabled
133
  // Hidden, will be shown using js.
134
- $nodes[] = array( 'type' => 2, 'data' => array(
135
  'parent' => 'advanced_ads_ad_health',
136
  'id' => 'advanced_ads_ad_health_adblocker_enabled',
137
  'title' => __( 'Ad blocker enabled', 'advanced-ads' ),
138
- 'meta' => array(
139
  'class' => 'hidden advanced_ads_ad_health_warning',
140
  'target' => '_blank'
141
- )
142
- ) );
143
 
144
  if ( $wp_the_query->is_singular() ) {
145
  if ( $this->has_the_content_placements() ) {
146
- $nodes[] = array( 'type' => 2, 'data' => array(
147
  'parent' => 'advanced_ads_ad_health',
148
  'id' => 'advanced_ads_ad_health_the_content_not_invoked',
149
  'title' => sprintf( __( '<em>%s</em> filter does not exist', 'advanced-ads' ), 'the_content' ),
150
  'href' => ADVADS_URL . 'manual/ads-not-showing-up/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-content-filter-missing#the_content-filter-missing',
151
- 'meta' => array(
152
  'class' => 'hidden advanced_ads_ad_health_warning',
153
  'target' => '_blank'
154
- )
155
- ) );
156
  }
157
 
158
  if ( ! empty( $post->ID ) ) {
159
  $ad_settings = get_post_meta( $post->ID, '_advads_ad_settings', true );
160
 
161
  if ( ! empty( $ad_settings['disable_the_content'] ) ) {
162
- $nodes[] = array( 'type' => 1, 'data' => array(
163
  'parent' => 'advanced_ads_ad_health',
164
  'id' => 'advanced_ads_ad_health_disabled_in_content',
165
  'title' => __( 'Ads are disabled in the content of this page', 'advanced-ads' ),
166
  'href' => get_edit_post_link( $post->ID ) . '#advads-ad-settings',
167
- 'meta' => array(
168
  'class' => 'advanced_ads_ad_health_warning',
169
  'target' => '_blank'
170
- )
171
- ) );
172
  }
173
  } else {
174
- $nodes[] = array( 'type' => 1, 'data' => array(
175
  'parent' => 'advanced_ads_ad_health',
176
  'id' => 'advanced_ads_ad_health_post_zero',
177
  'title' => __( 'the current post ID is 0 ', 'advanced-ads' ),
178
  'href' => ADVADS_URL . 'manual/ad-health/#post-id-0',
179
- 'meta' => array(
180
  'class' => 'advanced_ads_ad_health_warning',
181
  'target' => '_blank'
182
- )
183
- ) );
184
  }
185
  }
186
 
@@ -188,64 +188,64 @@ class Advanced_Ads_Frontend_Checks {
188
  $disabled_id = Advanced_Ads::get_instance()->disabled_id;
189
 
190
  if ( 'page' === $disabled_reason && $disabled_id ) {
191
- $nodes[] = array(
192
  'type' => 1,
193
- 'data' => array(
194
  'parent' => 'advanced_ads_ad_health',
195
  'id' => 'advanced_ads_ad_health_disabled_on_page',
196
  'title' => __( 'Ads are disabled on this page', 'advanced-ads' ),
197
  'href' => get_edit_post_link( $disabled_id ) . '#advads-ad-settings',
198
- 'meta' => array(
199
  'class' => 'advanced_ads_ad_health_warning',
200
  'target' => '_blank',
201
- ),
202
- ),
203
- );
204
  }
205
 
206
  if ( 'all' === $disabled_reason ) {
207
- $nodes[] = array( 'type' => 1, 'data' => array(
208
  'parent' => 'advanced_ads_ad_health',
209
  'id' => 'advanced_ads_ad_health_no_all',
210
  'title' => __( 'Ads are disabled on all pages', 'advanced-ads' ),
211
  'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
212
- 'meta' => array(
213
  'class' => 'advanced_ads_ad_health_warning',
214
  'target' => '_blank'
215
- )
216
- ) );
217
  }
218
 
219
  if ( '404' === $disabled_reason ) {
220
- $nodes[] = array(
221
  'type' => 1,
222
- 'data' => array(
223
  'parent' => 'advanced_ads_ad_health',
224
  'id' => 'advanced_ads_ad_health_no_404',
225
  'title' => __( 'Ads are disabled on 404 pages', 'advanced-ads' ),
226
  'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
227
- 'meta' => array(
228
  'class' => 'advanced_ads_ad_health_warning',
229
  'target' => '_blank',
230
- ),
231
- ),
232
- );
233
  }
234
 
235
  if ( 'archive' === $disabled_reason ) {
236
- $nodes[] = array( 'type' => 1, 'data' => array(
237
  'parent' => 'advanced_ads_ad_health',
238
  'id' => 'advanced_ads_ad_health_no_archive',
239
  'title' => __( 'Ads are disabled on non singular pages', 'advanced-ads' ),
240
  'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
241
- 'meta' => array(
242
  'class' => 'advanced_ads_ad_health_warning',
243
  'target' => '_blank'
244
- )
245
- ) );
246
  }
247
 
248
- $nodes[] = array( 'type' => 2, 'data' => array(
249
  'parent' => 'advanced_ads_ad_health',
250
  'id' => 'advanced_ads_ad_health_has_http',
251
  'title' => sprintf( '%s %s',
@@ -253,26 +253,26 @@ class Advanced_Ads_Frontend_Checks {
253
  sprintf( __( 'Ad IDs: %s', 'advanced-ads' ), '<i></i>' )
254
  ),
255
  'href' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-https-ads#https-ads',
256
- 'meta' => array(
257
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_has_http',
258
  'target' => '_blank'
259
- )
260
- ) );
261
 
262
- $nodes[] = array( 'type' => 2, 'data' => array(
263
  'parent' => 'advanced_ads_ad_health',
264
  'id' => 'advanced_ads_ad_health_incorrect_head',
265
  'title' => sprintf( __( 'Visible ads should not use the Header placement: %s', 'advanced-ads' ), '<i></i>' ),
266
  'href' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-visible-ad-in-header#header-ads',
267
- 'meta' => array(
268
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_incorrect_head',
269
  'target' => '_blank'
270
- )
271
- ) );
272
 
273
  // warn if an AdSense ad seems to be hidden
274
  if( ! isset( $adsense_options['violation-warnings-disable'] ) ) {
275
- $nodes[] = array( 'type' => 2, 'data' => array(
276
  'parent' => 'advanced_ads_ad_health',
277
  'id' => 'advanced_ads_ad_health_hidden_adsense',
278
  'title' => sprintf( '%s: %s. %s',
@@ -281,75 +281,75 @@ class Advanced_Ads_Frontend_Checks {
281
  sprintf( __( 'IDs: %s', 'advanced-ads' ), '<i></i>' )
282
  ),
283
  'href' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-frontend-adsense-hidden#adsense-hidden',
284
- 'meta' => array(
285
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_hidden_adsense',
286
  'target' => '_blank'
287
- )
288
- ) );
289
  }
290
 
291
- $nodes[] = array( 'type' => 2, 'data' => array(
292
  'parent' => 'advanced_ads_ad_health',
293
  'id' => 'advanced_ads_ad_health_floated_responsive_adsense',
294
  'title' => sprintf( __( 'The following responsive AdSense ads are not showing up: %s', 'advanced-ads' ), '<i></i>' ),
295
  'href' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-adsense-responsive-not-showing#The_following_responsive_AdSense_ads_arenot_showing_up',
296
- 'meta' => array(
297
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_floated_responsive_adsense',
298
  'target' => '_blank'
299
- )
300
- ) );
301
 
302
  // warn if consent was not given
303
  $privacy = Advanced_Ads_Privacy::get_instance();
304
  if ( 'not_needed' !== $privacy->get_state() ) {
305
- $nodes[] = array( 'type' => 2, 'data' => array(
306
  'parent' => 'advanced_ads_ad_health',
307
  'id' => 'advanced_ads_ad_health_consent_missing',
308
  'title' => __( 'Consent not given', 'advanced-ads' ),
309
  'href' => admin_url( 'admin.php?page=advanced-ads-settings#top#privacy' ),
310
- 'meta' => array(
311
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_consent_missing',
312
  'target' => '_blank'
313
- )
314
- ) );
315
  }
316
 
317
  $privacy_options = $privacy->options();
318
  if ( ( empty( $privacy_options['enabled'] ) || $privacy_options['consent-method'] !== 'iab_tcf_20' ) ) {
319
- $nodes[] = array(
320
  'type' => 2,
321
- 'data' => array(
322
  'parent' => 'advanced_ads_ad_health',
323
  'id' => 'advanced_ads_ad_health_privacy_disabled',
324
  'title' => __( 'Enable TCF integration', 'advanced-ads' ),
325
  'href' => admin_url( 'admin.php?page=advanced-ads-settings#top#privacy' ),
326
- 'meta' => array(
327
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_privacy_disabled',
328
  'target' => '_blank',
329
- ),
330
- ),
331
- );
332
  }
333
 
334
- $nodes[] = array( 'type' => 3, 'data' => array(
335
  'parent' => 'advanced_ads_ad_health',
336
  'id' => 'advanced_ads_ad_health_gam_debug',
337
  'title' => __( 'Debug Google Ad Manager', 'advanced-ads' ),
338
  'href' => esc_url( add_query_arg( 'google_force_console', '1' ) ),
339
- 'meta' => array(
340
  'class' => 'hidden advanced_ads_ad_health_gam_debug_link',
341
- )
342
- ) );
343
 
344
  // link to highlight ads and jump from one ad to the next.
345
- $nodes[] = array( 'type' => 3, 'amp' => false, 'data' => array(
346
  'parent' => 'advanced_ads_ad_health',
347
  'id' => 'advanced_ads_ad_health_highlight_ads',
348
  'title' => __( 'highlight ads', 'advanced-ads' ),
349
- 'meta' => array(
350
  'class' => 'advanced_ads_ad_health_highlight_ads',
351
- ),
352
- ) );
353
 
354
  /**
355
  * Add new node.
@@ -361,7 +361,7 @@ class Advanced_Ads_Frontend_Checks {
361
  */
362
  $nodes = apply_filters( 'advanced-ads-ad-health-nodes', $nodes );
363
 
364
- usort( $nodes, array( $this, 'sort_nodes' ) );
365
 
366
  // load number of already detected notices.
367
  $notices = Advanced_Ads_Ad_Health_Notices::get_number_of_notices();
@@ -369,7 +369,7 @@ class Advanced_Ads_Frontend_Checks {
369
  if ( ! advads_is_amp() ) {
370
  $warnings = 0; // Will be updated using JS.
371
  } else {
372
- $warnings = $this->count_visible_warnings( $nodes, array( 1 ) );
373
  }
374
 
375
  $issues = $warnings;
@@ -393,9 +393,9 @@ class Advanced_Ads_Frontend_Checks {
393
  * @return string[] $classes Array of existing and new class names.
394
  */
395
  public function body_class( $classes ) {
396
- $aa_classes = array(
397
  'aa-prefix-' . Advanced_Ads_Plugin::get_instance()->get_frontend_prefix(),
398
- );
399
 
400
  $disabled_reason = Advanced_Ads::get_instance()->disabled_reason;
401
  if ( $disabled_reason ) {
@@ -419,10 +419,10 @@ class Advanced_Ads_Frontend_Checks {
419
  $aa_classes = apply_filters( 'advanced-ads-body-classes', $aa_classes );
420
 
421
  if ( ! is_array( $classes ) ) {
422
- $classes = array();
423
  }
424
  if ( ! is_array( $aa_classes ) ) {
425
- $aa_classes = array();
426
  }
427
 
428
  return array_merge( $classes, $aa_classes );
@@ -437,7 +437,7 @@ class Advanced_Ads_Frontend_Checks {
437
  * @param array $nodes Nodes to add.
438
  * @param array $types Warning types.
439
  */
440
- private function count_visible_warnings( $nodes, $types = array() ) {
441
  $warnings = 0;
442
  foreach ( $nodes as $node ) {
443
  if ( ! isset( $node['type'] ) || ! isset( $node['data'] ) ) { continue; }
@@ -456,25 +456,25 @@ class Advanced_Ads_Frontend_Checks {
456
  * @param int $notices Number of notices.
457
  */
458
  private function add_header_nodes( $wp_admin_bar, $issues, $notices ) {
459
- $wp_admin_bar->add_node( array(
460
  'id' => 'advanced_ads_ad_health',
461
  'title' => __( 'Ad Health', 'advanced-ads' ) . '&nbsp;<span class="advanced-ads-issue-counter">' . $issues . '</span>',
462
  'parent' => false,
463
  'href' => admin_url( 'admin.php?page=advanced-ads' ),
464
- 'meta' => array(
465
  'class' => $issues ? 'advads-adminbar-is-warnings': '',
466
- ),
467
- ) );
468
 
469
 
470
  // show that there are backend notices
471
  if ( $notices ) {
472
- $wp_admin_bar->add_node( array(
473
  'parent' => 'advanced_ads_ad_health',
474
  'id' => 'advanced_ads_ad_health_more',
475
  'title' => sprintf(__( 'Show %d more notifications', 'advanced-ads' ), absint( $notices ) ),
476
  'href' => admin_url( 'admin.php?page=advanced-ads' ),
477
- ) );
478
  }
479
  }
480
 
@@ -486,26 +486,26 @@ class Advanced_Ads_Frontend_Checks {
486
  */
487
  private function add_footer_nodes( $wp_admin_bar, $issues ) {
488
  if ( ! $issues ) {
489
- $wp_admin_bar->add_node( array(
490
  'parent' => 'advanced_ads_ad_health',
491
  'id' => 'advanced_ads_ad_health_fine',
492
  'title' => __( 'Everything is fine', 'advanced-ads' ),
493
  'href' => false,
494
- 'meta' => array(
495
  'target' => '_blank',
496
- )
497
- ) );
498
  }
499
 
500
- $wp_admin_bar->add_node( array(
501
  'parent' => 'advanced_ads_ad_health',
502
  'id' => 'advanced_ads_ad_health_support',
503
  'title' => __( 'Get help', 'advanced-ads' ),
504
  'href' => Advanced_Ads_Plugin::support_url( '?utm_source=advanced-ads&utm_medium=link&utm_campaign=health-support' ),
505
- 'meta' => array(
506
  'target' => '_blank',
507
- )
508
- ) );
509
  }
510
 
511
  /**
@@ -1087,7 +1087,7 @@ class Advanced_Ads_Frontend_Checks {
1087
  }
1088
 
1089
  if ( XML_ELEMENT_NODE === $node->nodeType
1090
- && ! in_array( $node->nodeName, array( 'meta', 'link', 'title', 'style', 'script', 'noscript', 'base' ) ) ) {
1091
  return false;
1092
  }
1093
  }
19
  */
20
  public function __construct() {
21
  // Wait until other plugins (for example Elementor) have disabled admin bar using `show_admin_bar` filter.
22
+ add_action( 'template_redirect', [ $this, 'init' ], 11 );
23
 
24
  if ( wp_doing_ajax() ) {
25
+ add_filter( 'advanced-ads-ad-output', [ $this, 'after_ad_output' ], 10, 2 );
26
  }
27
  }
28
 
35
  && current_user_can( Advanced_Ads_Plugin::user_cap( 'advanced_ads_edit_ads' ) )
36
  && Advanced_Ads_Ad_Health_Notices::notices_enabled()
37
  ) {
38
+ add_action( 'admin_bar_menu', [ $this, 'add_admin_bar_menu' ], 1000 );
39
+ add_filter( 'the_content', [ $this, 'set_did_the_content' ] );
40
+ add_action( 'wp_footer', [ $this, 'footer_checks' ], -101 );
41
+ add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
42
+ add_filter( 'advanced-ads-ad-select-args', [ $this, 'ad_select_args_callback' ] );
43
+ add_filter( 'advanced-ads-ad-output', [ $this, 'after_ad_output' ], 10, 2 );
44
  }
45
 
46
  if ( Advanced_Ads_Ad_Health_Notices::notices_enabled() ) {
47
+ add_action( 'body_class', [ $this, 'body_class' ] );
48
  }
49
  }
50
 
70
 
71
  // we don’t have our own script, so we attach this information to jquery
72
  wp_localize_script( 'jquery', 'advads_frontend_checks',
73
+ [ 'ajax_url' => admin_url( 'admin-ajax.php' ) ] );
74
  }
75
 
76
  /**
103
  // check if AdSense loads Auto Ads ads
104
  // Hidden, will be shown using js.
105
  if( ! isset( $adsense_options['violation-warnings-disable'] ) ) {
106
+ $nodes[] = [ 'type' => 2, 'data' => [
107
  'parent' => 'advanced_ads_ad_health',
108
  'id' => 'advanced_ads_autoads_displayed',
109
  'title' => __( 'Random AdSense ads', 'advanced-ads' ),
110
  'href' => ADVADS_URL . 'adsense-in-random-positions-auto-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=frontend-autoads-ads',
111
+ 'meta' => [
112
  'class' => 'hidden',
113
  'target' => '_blank'
114
+ ]
115
+ ] ];
116
  }
117
 
118
  // check if current user was identified as a bot.
119
  if( Advanced_Ads::get_instance()->is_bot() ) {
120
+ $nodes[] = [ 'type' => 1, 'data' => [
121
  'parent' => 'advanced_ads_ad_health',
122
  'id' => 'advanced_ads_user_is_bot',
123
  'title' => __( 'You look like a bot', 'advanced-ads' ),
124
  'href' => ADVADS_URL . 'manual/ad-health/#look-like-bot',
125
+ 'meta' => [
126
  'class' => 'advanced_ads_ad_health_warning',
127
  'target' => '_blank'
128
+ ]
129
+ ] ];
130
  }
131
 
132
  // check if an ad blocker is enabled
133
  // Hidden, will be shown using js.
134
+ $nodes[] = [ 'type' => 2, 'data' => [
135
  'parent' => 'advanced_ads_ad_health',
136
  'id' => 'advanced_ads_ad_health_adblocker_enabled',
137
  'title' => __( 'Ad blocker enabled', 'advanced-ads' ),
138
+ 'meta' => [
139
  'class' => 'hidden advanced_ads_ad_health_warning',
140
  'target' => '_blank'
141
+ ]
142
+ ] ];
143
 
144
  if ( $wp_the_query->is_singular() ) {
145
  if ( $this->has_the_content_placements() ) {
146
+ $nodes[] = [ 'type' => 2, 'data' => [
147
  'parent' => 'advanced_ads_ad_health',
148
  'id' => 'advanced_ads_ad_health_the_content_not_invoked',
149
  'title' => sprintf( __( '<em>%s</em> filter does not exist', 'advanced-ads' ), 'the_content' ),
150
  'href' => ADVADS_URL . 'manual/ads-not-showing-up/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-content-filter-missing#the_content-filter-missing',
151
+ 'meta' => [
152
  'class' => 'hidden advanced_ads_ad_health_warning',
153
  'target' => '_blank'
154
+ ]
155
+ ] ];
156
  }
157
 
158
  if ( ! empty( $post->ID ) ) {
159
  $ad_settings = get_post_meta( $post->ID, '_advads_ad_settings', true );
160
 
161
  if ( ! empty( $ad_settings['disable_the_content'] ) ) {
162
+ $nodes[] = [ 'type' => 1, 'data' => [
163
  'parent' => 'advanced_ads_ad_health',
164
  'id' => 'advanced_ads_ad_health_disabled_in_content',
165
  'title' => __( 'Ads are disabled in the content of this page', 'advanced-ads' ),
166
  'href' => get_edit_post_link( $post->ID ) . '#advads-ad-settings',
167
+ 'meta' => [
168
  'class' => 'advanced_ads_ad_health_warning',
169
  'target' => '_blank'
170
+ ]
171
+ ] ];
172
  }
173
  } else {
174
+ $nodes[] = [ 'type' => 1, 'data' => [
175
  'parent' => 'advanced_ads_ad_health',
176
  'id' => 'advanced_ads_ad_health_post_zero',
177
  'title' => __( 'the current post ID is 0 ', 'advanced-ads' ),
178
  'href' => ADVADS_URL . 'manual/ad-health/#post-id-0',
179
+ 'meta' => [
180
  'class' => 'advanced_ads_ad_health_warning',
181
  'target' => '_blank'
182
+ ]
183
+ ] ];
184
  }
185
  }
186
 
188
  $disabled_id = Advanced_Ads::get_instance()->disabled_id;
189
 
190
  if ( 'page' === $disabled_reason && $disabled_id ) {
191
+ $nodes[] = [
192
  'type' => 1,
193
+ 'data' => [
194
  'parent' => 'advanced_ads_ad_health',
195
  'id' => 'advanced_ads_ad_health_disabled_on_page',
196
  'title' => __( 'Ads are disabled on this page', 'advanced-ads' ),
197
  'href' => get_edit_post_link( $disabled_id ) . '#advads-ad-settings',
198
+ 'meta' => [
199
  'class' => 'advanced_ads_ad_health_warning',
200
  'target' => '_blank',
201
+ ],
202
+ ],
203
+ ];
204
  }
205
 
206
  if ( 'all' === $disabled_reason ) {
207
+ $nodes[] = [ 'type' => 1, 'data' => [
208
  'parent' => 'advanced_ads_ad_health',
209
  'id' => 'advanced_ads_ad_health_no_all',
210
  'title' => __( 'Ads are disabled on all pages', 'advanced-ads' ),
211
  'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
212
+ 'meta' => [
213
  'class' => 'advanced_ads_ad_health_warning',
214
  'target' => '_blank'
215
+ ]
216
+ ] ];
217
  }
218
 
219
  if ( '404' === $disabled_reason ) {
220
+ $nodes[] = [
221
  'type' => 1,
222
+ 'data' => [
223
  'parent' => 'advanced_ads_ad_health',
224
  'id' => 'advanced_ads_ad_health_no_404',
225
  'title' => __( 'Ads are disabled on 404 pages', 'advanced-ads' ),
226
  'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
227
+ 'meta' => [
228
  'class' => 'advanced_ads_ad_health_warning',
229
  'target' => '_blank',
230
+ ],
231
+ ],
232
+ ];
233
  }
234
 
235
  if ( 'archive' === $disabled_reason ) {
236
+ $nodes[] = [ 'type' => 1, 'data' => [
237
  'parent' => 'advanced_ads_ad_health',
238
  'id' => 'advanced_ads_ad_health_no_archive',
239
  'title' => __( 'Ads are disabled on non singular pages', 'advanced-ads' ),
240
  'href' => admin_url( 'admin.php?page=advanced-ads-settings' ),
241
+ 'meta' => [
242
  'class' => 'advanced_ads_ad_health_warning',
243
  'target' => '_blank'
244
+ ]
245
+ ] ];
246
  }
247
 
248
+ $nodes[] = [ 'type' => 2, 'data' => [
249
  'parent' => 'advanced_ads_ad_health',
250
  'id' => 'advanced_ads_ad_health_has_http',
251
  'title' => sprintf( '%s %s',
253
  sprintf( __( 'Ad IDs: %s', 'advanced-ads' ), '<i></i>' )
254
  ),
255
  'href' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-https-ads#https-ads',
256
+ 'meta' => [
257
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_has_http',
258
  'target' => '_blank'
259
+ ]
260
+ ] ];
261
 
262
+ $nodes[] = [ 'type' => 2, 'data' => [
263
  'parent' => 'advanced_ads_ad_health',
264
  'id' => 'advanced_ads_ad_health_incorrect_head',
265
  'title' => sprintf( __( 'Visible ads should not use the Header placement: %s', 'advanced-ads' ), '<i></i>' ),
266
  'href' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-visible-ad-in-header#header-ads',
267
+ 'meta' => [
268
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_incorrect_head',
269
  'target' => '_blank'
270
+ ]
271
+ ] ];
272
 
273
  // warn if an AdSense ad seems to be hidden
274
  if( ! isset( $adsense_options['violation-warnings-disable'] ) ) {
275
+ $nodes[] = [ 'type' => 2, 'data' => [
276
  'parent' => 'advanced_ads_ad_health',
277
  'id' => 'advanced_ads_ad_health_hidden_adsense',
278
  'title' => sprintf( '%s: %s. %s',
281
  sprintf( __( 'IDs: %s', 'advanced-ads' ), '<i></i>' )
282
  ),
283
  'href' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-frontend-adsense-hidden#adsense-hidden',
284
+ 'meta' => [
285
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_hidden_adsense',
286
  'target' => '_blank'
287
+ ]
288
+ ] ];
289
  }
290
 
291
+ $nodes[] = [ 'type' => 2, 'data' => [
292
  'parent' => 'advanced_ads_ad_health',
293
  'id' => 'advanced_ads_ad_health_floated_responsive_adsense',
294
  'title' => sprintf( __( 'The following responsive AdSense ads are not showing up: %s', 'advanced-ads' ), '<i></i>' ),
295
  'href' => ADVADS_URL . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adhealth-adsense-responsive-not-showing#The_following_responsive_AdSense_ads_arenot_showing_up',
296
+ 'meta' => [
297
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_floated_responsive_adsense',
298
  'target' => '_blank'
299
+ ]
300
+ ] ];
301
 
302
  // warn if consent was not given
303
  $privacy = Advanced_Ads_Privacy::get_instance();
304
  if ( 'not_needed' !== $privacy->get_state() ) {
305
+ $nodes[] = [ 'type' => 2, 'data' => [
306
  'parent' => 'advanced_ads_ad_health',
307
  'id' => 'advanced_ads_ad_health_consent_missing',
308
  'title' => __( 'Consent not given', 'advanced-ads' ),
309
  'href' => admin_url( 'admin.php?page=advanced-ads-settings#top#privacy' ),
310
+ 'meta' => [
311
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_consent_missing',
312
  'target' => '_blank'
313
+ ]
314
+ ] ];
315
  }
316
 
317
  $privacy_options = $privacy->options();
318
  if ( ( empty( $privacy_options['enabled'] ) || $privacy_options['consent-method'] !== 'iab_tcf_20' ) ) {
319
+ $nodes[] = [
320
  'type' => 2,
321
+ 'data' => [
322
  'parent' => 'advanced_ads_ad_health',
323
  'id' => 'advanced_ads_ad_health_privacy_disabled',
324
  'title' => __( 'Enable TCF integration', 'advanced-ads' ),
325
  'href' => admin_url( 'admin.php?page=advanced-ads-settings#top#privacy' ),
326
+ 'meta' => [
327
  'class' => 'hidden advanced_ads_ad_health_warning advanced_ads_ad_health_privacy_disabled',
328
  'target' => '_blank',
329
+ ],
330
+ ],
331
+ ];
332
  }
333
 
334
+ $nodes[] = [ 'type' => 3, 'data' => [
335
  'parent' => 'advanced_ads_ad_health',
336
  'id' => 'advanced_ads_ad_health_gam_debug',
337
  'title' => __( 'Debug Google Ad Manager', 'advanced-ads' ),
338
  'href' => esc_url( add_query_arg( 'google_force_console', '1' ) ),
339
+ 'meta' => [
340
  'class' => 'hidden advanced_ads_ad_health_gam_debug_link',
341
+ ]
342
+ ] ];
343
 
344
  // link to highlight ads and jump from one ad to the next.
345
+ $nodes[] = [ 'type' => 3, 'amp' => false, 'data' => [
346
  'parent' => 'advanced_ads_ad_health',
347
  'id' => 'advanced_ads_ad_health_highlight_ads',
348
  'title' => __( 'highlight ads', 'advanced-ads' ),
349
+ 'meta' => [
350
  'class' => 'advanced_ads_ad_health_highlight_ads',
351
+ ],
352
+ ] ];
353
 
354
  /**
355
  * Add new node.
361
  */
362
  $nodes = apply_filters( 'advanced-ads-ad-health-nodes', $nodes );
363
 
364
+ usort( $nodes, [ $this, 'sort_nodes' ] );
365
 
366
  // load number of already detected notices.
367
  $notices = Advanced_Ads_Ad_Health_Notices::get_number_of_notices();
369
  if ( ! advads_is_amp() ) {
370
  $warnings = 0; // Will be updated using JS.
371
  } else {
372
+ $warnings = $this->count_visible_warnings( $nodes, [ 1 ] );
373
  }
374
 
375
  $issues = $warnings;
393
  * @return string[] $classes Array of existing and new class names.
394
  */
395
  public function body_class( $classes ) {
396
+ $aa_classes = [
397
  'aa-prefix-' . Advanced_Ads_Plugin::get_instance()->get_frontend_prefix(),
398
+ ];
399
 
400
  $disabled_reason = Advanced_Ads::get_instance()->disabled_reason;
401
  if ( $disabled_reason ) {
419
  $aa_classes = apply_filters( 'advanced-ads-body-classes', $aa_classes );
420
 
421
  if ( ! is_array( $classes ) ) {
422
+ $classes = [];
423
  }
424
  if ( ! is_array( $aa_classes ) ) {
425
+ $aa_classes = [];
426
  }
427
 
428
  return array_merge( $classes, $aa_classes );
437
  * @param array $nodes Nodes to add.
438
  * @param array $types Warning types.
439
  */
440
+ private function count_visible_warnings( $nodes, $types = [] ) {
441
  $warnings = 0;
442
  foreach ( $nodes as $node ) {
443
  if ( ! isset( $node['type'] ) || ! isset( $node['data'] ) ) { continue; }
456
  * @param int $notices Number of notices.
457
  */
458
  private function add_header_nodes( $wp_admin_bar, $issues, $notices ) {
459
+ $wp_admin_bar->add_node( [
460
  'id' => 'advanced_ads_ad_health',
461
  'title' => __( 'Ad Health', 'advanced-ads' ) . '&nbsp;<span class="advanced-ads-issue-counter">' . $issues . '</span>',
462
  'parent' => false,
463
  'href' => admin_url( 'admin.php?page=advanced-ads' ),
464
+ 'meta' => [
465
  'class' => $issues ? 'advads-adminbar-is-warnings': '',
466
+ ],
467
+ ] );
468
 
469
 
470
  // show that there are backend notices
471
  if ( $notices ) {
472
+ $wp_admin_bar->add_node( [
473
  'parent' => 'advanced_ads_ad_health',
474
  'id' => 'advanced_ads_ad_health_more',
475
  'title' => sprintf(__( 'Show %d more notifications', 'advanced-ads' ), absint( $notices ) ),
476
  'href' => admin_url( 'admin.php?page=advanced-ads' ),
477
+ ] );
478
  }
479
  }
480
 
486
  */
487
  private function add_footer_nodes( $wp_admin_bar, $issues ) {
488
  if ( ! $issues ) {
489
+ $wp_admin_bar->add_node( [
490
  'parent' => 'advanced_ads_ad_health',
491
  'id' => 'advanced_ads_ad_health_fine',
492
  'title' => __( 'Everything is fine', 'advanced-ads' ),
493
  'href' => false,
494
+ 'meta' => [
495
  'target' => '_blank',
496
+ ]
497
+ ] );
498
  }
499
 
500
+ $wp_admin_bar->add_node( [
501
  'parent' => 'advanced_ads_ad_health',
502
  'id' => 'advanced_ads_ad_health_support',
503
  'title' => __( 'Get help', 'advanced-ads' ),
504
  'href' => Advanced_Ads_Plugin::support_url( '?utm_source=advanced-ads&utm_medium=link&utm_campaign=health-support' ),
505
+ 'meta' => [
506
  'target' => '_blank',
507
+ ]
508
+ ] );
509
  }
510
 
511
  /**
1087
  }
1088
 
1089
  if ( XML_ELEMENT_NODE === $node->nodeType
1090
+ && ! in_array( $node->nodeName, [ 'meta', 'link', 'title', 'style', 'script', 'noscript', 'base' ] ) ) {
1091
  return false;
1092
  }
1093
  }
classes/in-content-injector.php CHANGED
@@ -9,7 +9,7 @@ class Advanced_Ads_In_Content_Injector {
9
  *
10
  * @var array $ads_for_placeholders
11
  */
12
- private static $ads_for_placeholders = array();
13
 
14
  /**
15
  * Inject ads directly into the content
@@ -31,7 +31,7 @@ class Advanced_Ads_In_Content_Injector {
31
  *
32
  * @return string $content Content with injected placement.
33
  */
34
- public static function &inject_in_content( $placement_id, $placement_opts, &$content, $options = array() ) {
35
  if ( ! extension_loaded( 'dom' ) ) {
36
  return $content;
37
  }
@@ -54,7 +54,7 @@ class Advanced_Ads_In_Content_Injector {
54
  // get plugin options.
55
  $plugin_options = Advanced_Ads::get_instance()->options();
56
 
57
- $defaults = array(
58
  'allowEmpty' => false,
59
  'paragraph_select_from_bottom' => isset( $placement_opts['start_from_bottom'] ) && $placement_opts['start_from_bottom'],
60
  'position' => isset( $placement_opts['position'] ) ? $placement_opts['position'] : 'after',
@@ -63,7 +63,7 @@ class Advanced_Ads_In_Content_Injector {
63
  // Whether to alter nodes, for example to prevent injecting ads into `a` tags.
64
  'alter_nodes' => true,
65
  'repeat' => false,
66
- );
67
 
68
  $defaults['paragraph_id'] = isset( $placement_opts['index'] ) ? $placement_opts['index'] : 1;
69
  $defaults['paragraph_id'] = max( 1, (int) $defaults['paragraph_id'] );
@@ -77,7 +77,7 @@ class Advanced_Ads_In_Content_Injector {
77
  }
78
 
79
  // handle tags that are empty by definition or could be empty ("custom" option)
80
- if ( in_array( $tag_option, array( 'img', 'iframe', 'custom' ), true ) ) {
81
  $defaults['allowEmpty'] = true;
82
  }
83
 
@@ -134,7 +134,7 @@ class Advanced_Ads_In_Content_Injector {
134
  break;
135
  // any headline. By default h2, h3, and h4
136
  case 'headlines':
137
- $headlines = apply_filters( 'advanced-ads-headlines-for-ad-injection', array( 'h2', 'h3', 'h4' ) );
138
 
139
  foreach ( $headlines as &$headline ) {
140
  $headline = 'self::' . $headline;
@@ -143,7 +143,7 @@ class Advanced_Ads_In_Content_Injector {
143
  break;
144
  // any HTML element that makes sense in the content
145
  case 'anyelement':
146
- $exclude = array(
147
  'html',
148
  'body',
149
  'script',
@@ -178,7 +178,7 @@ class Advanced_Ads_In_Content_Injector {
178
  'time',
179
  'tt',
180
  'var',
181
- );
182
  $tag = '*[not(self::' . implode( ' or self::', $exclude ) . ')]';
183
  break;
184
  case 'custom':
@@ -214,7 +214,7 @@ class Advanced_Ads_In_Content_Injector {
214
 
215
  // filter empty tags from items.
216
  $whitespaces = json_decode( '"\t\n\r \u00A0"' );
217
- $paragraphs = array();
218
  foreach ( $items as $item ) {
219
  if ( $options['allowEmpty'] || ( isset( $item->textContent ) && trim( $item->textContent, $whitespaces ) !== '' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
220
  $paragraphs[] = $item;
@@ -228,7 +228,7 @@ class Advanced_Ads_In_Content_Injector {
228
 
229
  if ( $options['paragraph_count'] >= $options['paragraph_id'] ) {
230
  $offset = $options['paragraph_select_from_bottom'] ? $options['paragraph_count'] - $options['paragraph_id'] : $options['paragraph_id'] - 1;
231
- $offsets = apply_filters( 'advanced-ads-placement-content-offsets', array( $offset ), $options, $placement_opts, $xpath, $paragraphs, $dom );
232
  $did_inject = false;
233
 
234
  foreach ( $offsets as $offset ) {
@@ -353,7 +353,7 @@ class Advanced_Ads_In_Content_Injector {
353
  // Check if there are more elements without limitation.
354
  $all_items = $xpath->query( '//' . $tag );
355
 
356
- $paragraphs = array();
357
  foreach ( $all_items as $item ) {
358
  if ( $options['allowEmpty'] || ( isset( $item->textContent ) && trim( $item->textContent, $whitespaces ) !== '' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
359
  $paragraphs[] = $item;
@@ -363,7 +363,7 @@ class Advanced_Ads_In_Content_Injector {
363
  $paragraphs = self::filter_by_ancestors_to_limit( $paragraphs, $ancestors_to_limit );
364
  if ( $options['paragraph_id'] <= count( $paragraphs ) ) {
365
  // Add a warning to ad health.
366
- add_filter( 'advanced-ads-ad-health-nodes', array( 'Advanced_Ads_In_Content_Injector', 'add_ad_health_node' ) );
367
  }
368
  }
369
 
@@ -408,12 +408,12 @@ class Advanced_Ads_In_Content_Injector {
408
 
409
  // Inject placeholder.
410
  $id = count( self::$ads_for_placeholders );
411
- self::$ads_for_placeholders[] = array(
412
  'id' => $id,
413
  'tag' => $tag_name,
414
  'position' => $options['position'],
415
  'ad' => $ad_content,
416
- );
417
 
418
  return '%advads_placeholder_' . $id . '%';
419
  }
@@ -428,7 +428,7 @@ class Advanced_Ads_In_Content_Injector {
428
  */
429
  private static function prepare_output( $content, $content_orig ) {
430
  $content = self::inject_ads( $content, $content_orig, self::$ads_for_placeholders );
431
- self::$ads_for_placeholders = array();
432
 
433
  return $content;
434
  }
@@ -445,7 +445,7 @@ class Advanced_Ads_In_Content_Injector {
445
  * @return string $content
446
  */
447
  private static function inject_ads( $content, $content_orig, $ads_for_placeholders ) {
448
- $self_closing_tags = array(
449
  'area',
450
  'base',
451
  'basefont',
@@ -464,7 +464,7 @@ class Advanced_Ads_In_Content_Injector {
464
  'source',
465
  'track',
466
  'wbr',
467
- );
468
 
469
  // It is not possible to append/prepend in self closing tags.
470
  foreach ( $ads_for_placeholders as &$ad_content ) {
@@ -474,7 +474,7 @@ class Advanced_Ads_In_Content_Injector {
474
  }
475
  }
476
  unset( $ad_content );
477
- usort( $ads_for_placeholders, array( 'Advanced_Ads_In_Content_Injector', 'sort_ads_for_placehoders' ) );
478
 
479
  // Add tags before/after which ad placehoders were injected.
480
  foreach ( $ads_for_placeholders as $ad_content ) {
@@ -483,17 +483,17 @@ class Advanced_Ads_In_Content_Injector {
483
  switch ( $ad_content['position'] ) {
484
  case 'before':
485
  case 'prepend':
486
- $alts[] = "<${tag}[^>]*>";
487
  break;
488
  case 'after':
489
  if ( in_array( $tag, $self_closing_tags, true ) ) {
490
- $alts[] = "<${tag}[^>]*>";
491
  } else {
492
- $alts[] = "</${tag}>";
493
  }
494
  break;
495
  case 'append':
496
- $alts[] = "</${tag}>";
497
  break;
498
  }
499
  }
@@ -542,7 +542,7 @@ class Advanced_Ads_In_Content_Injector {
542
  $pos = 0;
543
 
544
  foreach ( $orig_tag_matches[0] as $n => $r ) {
545
- $to_inject = array();
546
  // Check if we need to inject an ad at this offset.
547
  foreach ( $ads_for_placeholders as $ad ) {
548
  if ( isset( $ad['offset'] ) && $ad['offset'] === $n ) {
@@ -586,12 +586,12 @@ class Advanced_Ads_In_Content_Injector {
586
  return 0;
587
  }
588
 
589
- $num = array(
590
  'before' => 1,
591
  'prepend' => 2,
592
  'append' => 3,
593
  'after' => 4,
594
- );
595
 
596
  return $num[ $first['position'] ] > $num[ $second['position'] ] ? 1 : - 1;
597
  }
@@ -604,9 +604,9 @@ class Advanced_Ads_In_Content_Injector {
604
  * @return array $nodes.
605
  */
606
  public static function add_ad_health_node( $nodes ) {
607
- $nodes[] = array(
608
  'type' => 1,
609
- 'data' => array(
610
  'parent' => 'advanced_ads_ad_health',
611
  'id' => 'advanced_ads_ad_health_the_content_not_enough_elements',
612
  'title' => sprintf(
@@ -615,12 +615,12 @@ class Advanced_Ads_In_Content_Injector {
615
  __( 'Disable level limitation', 'advanced-ads' )
616
  ),
617
  'href' => admin_url( '/admin.php?page=advanced-ads-settings#top#general' ),
618
- 'meta' => array(
619
  'class' => 'advanced_ads_ad_health_warning',
620
  'target' => '_blank',
621
- ),
622
- ),
623
- );
624
 
625
  return $nodes;
626
  }
@@ -635,11 +635,11 @@ class Advanced_Ads_In_Content_Injector {
635
  private static function get_ancestors_to_limit( $xpath ) {
636
  $query = self::get_ancestors_to_limit_query();
637
  if ( ! $query ) {
638
- return array();
639
  }
640
 
641
  $node_list = $xpath->query( $query );
642
- $ancestors_to_limit = array();
643
 
644
  foreach ( $node_list as $a ) {
645
  $ancestors_to_limit[] = $a->getNodePath();
@@ -658,7 +658,7 @@ class Advanced_Ads_In_Content_Injector {
658
  * @return array $new_paragraphs An array of `DOMNode` objects to insert ads before or after.
659
  */
660
  private static function filter_by_ancestors_to_limit( $paragraphs, $ancestors_to_limit ) {
661
- $new_paragraphs = array();
662
 
663
  foreach ( $paragraphs as $k => $paragraph ) {
664
  foreach ( $ancestors_to_limit as $a ) {
@@ -697,31 +697,31 @@ class Advanced_Ads_In_Content_Injector {
697
  */
698
  $items = apply_filters(
699
  'advanced-ads-content-injection-nodes-without-ads',
700
- array(
701
- array(
702
  // a class anyone can use to prevent automatic ad injection into a specific element.
703
  'node' => '.advads-stop-injection',
704
  'type' => 'ancestor',
705
- ),
706
- array(
707
  // Product Slider for Beaver Builder by WooPack.
708
  'node' => '.woopack-product-carousel',
709
  'type' => 'ancestor',
710
- ),
711
- array(
712
  // WP Author Box Lite.
713
  'node' => '#wpautbox-%',
714
  'type' => 'ancestor',
715
- ),
716
- array(
717
  // GeoDirectory Post Slider.
718
  'node' => '.geodir-post-slider',
719
  'type' => 'ancestor',
720
- ),
721
- )
722
  );
723
 
724
- $query = array();
725
  foreach ( $items as $p ) {
726
  $sel = $p['node'];
727
 
9
  *
10
  * @var array $ads_for_placeholders
11
  */
12
+ private static $ads_for_placeholders = [];
13
 
14
  /**
15
  * Inject ads directly into the content
31
  *
32
  * @return string $content Content with injected placement.
33
  */
34
+ public static function &inject_in_content( $placement_id, $placement_opts, &$content, $options = [] ) {
35
  if ( ! extension_loaded( 'dom' ) ) {
36
  return $content;
37
  }
54
  // get plugin options.
55
  $plugin_options = Advanced_Ads::get_instance()->options();
56
 
57
+ $defaults = [
58
  'allowEmpty' => false,
59
  'paragraph_select_from_bottom' => isset( $placement_opts['start_from_bottom'] ) && $placement_opts['start_from_bottom'],
60
  'position' => isset( $placement_opts['position'] ) ? $placement_opts['position'] : 'after',
63
  // Whether to alter nodes, for example to prevent injecting ads into `a` tags.
64
  'alter_nodes' => true,
65
  'repeat' => false,
66
+ ];
67
 
68
  $defaults['paragraph_id'] = isset( $placement_opts['index'] ) ? $placement_opts['index'] : 1;
69
  $defaults['paragraph_id'] = max( 1, (int) $defaults['paragraph_id'] );
77
  }
78
 
79
  // handle tags that are empty by definition or could be empty ("custom" option)
80
+ if ( in_array( $tag_option, [ 'img', 'iframe', 'custom' ], true ) ) {
81
  $defaults['allowEmpty'] = true;
82
  }
83
 
134
  break;
135
  // any headline. By default h2, h3, and h4
136
  case 'headlines':
137
+ $headlines = apply_filters( 'advanced-ads-headlines-for-ad-injection', [ 'h2', 'h3', 'h4' ] );
138
 
139
  foreach ( $headlines as &$headline ) {
140
  $headline = 'self::' . $headline;
143
  break;
144
  // any HTML element that makes sense in the content
145
  case 'anyelement':
146
+ $exclude = [
147
  'html',
148
  'body',
149
  'script',
178
  'time',
179
  'tt',
180
  'var',
181
+ ];
182
  $tag = '*[not(self::' . implode( ' or self::', $exclude ) . ')]';
183
  break;
184
  case 'custom':
214
 
215
  // filter empty tags from items.
216
  $whitespaces = json_decode( '"\t\n\r \u00A0"' );
217
+ $paragraphs = [];
218
  foreach ( $items as $item ) {
219
  if ( $options['allowEmpty'] || ( isset( $item->textContent ) && trim( $item->textContent, $whitespaces ) !== '' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
220
  $paragraphs[] = $item;
228
 
229
  if ( $options['paragraph_count'] >= $options['paragraph_id'] ) {
230
  $offset = $options['paragraph_select_from_bottom'] ? $options['paragraph_count'] - $options['paragraph_id'] : $options['paragraph_id'] - 1;
231
+ $offsets = apply_filters( 'advanced-ads-placement-content-offsets', [ $offset ], $options, $placement_opts, $xpath, $paragraphs, $dom );
232
  $did_inject = false;
233
 
234
  foreach ( $offsets as $offset ) {
353
  // Check if there are more elements without limitation.
354
  $all_items = $xpath->query( '//' . $tag );
355
 
356
+ $paragraphs = [];
357
  foreach ( $all_items as $item ) {
358
  if ( $options['allowEmpty'] || ( isset( $item->textContent ) && trim( $item->textContent, $whitespaces ) !== '' ) ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar
359
  $paragraphs[] = $item;
363
  $paragraphs = self::filter_by_ancestors_to_limit( $paragraphs, $ancestors_to_limit );
364
  if ( $options['paragraph_id'] <= count( $paragraphs ) ) {
365
  // Add a warning to ad health.
366
+ add_filter( 'advanced-ads-ad-health-nodes', [ 'Advanced_Ads_In_Content_Injector', 'add_ad_health_node' ] );
367
  }
368
  }
369
 
408
 
409
  // Inject placeholder.
410
  $id = count( self::$ads_for_placeholders );
411
+ self::$ads_for_placeholders[] = [
412
  'id' => $id,
413
  'tag' => $tag_name,
414
  'position' => $options['position'],
415
  'ad' => $ad_content,
416
+ ];
417
 
418
  return '%advads_placeholder_' . $id . '%';
419
  }
428
  */
429
  private static function prepare_output( $content, $content_orig ) {
430
  $content = self::inject_ads( $content, $content_orig, self::$ads_for_placeholders );
431
+ self::$ads_for_placeholders = [];
432
 
433
  return $content;
434
  }
445
  * @return string $content
446
  */
447
  private static function inject_ads( $content, $content_orig, $ads_for_placeholders ) {
448
+ $self_closing_tags = [
449
  'area',
450
  'base',
451
  'basefont',
464
  'source',
465
  'track',
466
  'wbr',
467
+ ];
468
 
469
  // It is not possible to append/prepend in self closing tags.
470
  foreach ( $ads_for_placeholders as &$ad_content ) {
474
  }
475
  }
476
  unset( $ad_content );
477
+ usort( $ads_for_placeholders, [ 'Advanced_Ads_In_Content_Injector', 'sort_ads_for_placehoders' ] );
478
 
479
  // Add tags before/after which ad placehoders were injected.
480
  foreach ( $ads_for_placeholders as $ad_content ) {
483
  switch ( $ad_content['position'] ) {
484
  case 'before':
485
  case 'prepend':
486
+ $alts[] = "<{$tag}[^>]*>";
487
  break;
488
  case 'after':
489
  if ( in_array( $tag, $self_closing_tags, true ) ) {
490
+ $alts[] = "<{$tag}[^>]*>";
491
  } else {
492
+ $alts[] = "</{$tag}>";
493
  }
494
  break;
495
  case 'append':
496
+ $alts[] = "</{$tag}>";
497
  break;
498
  }
499
  }
542
  $pos = 0;
543
 
544
  foreach ( $orig_tag_matches[0] as $n => $r ) {
545
+ $to_inject = [];
546
  // Check if we need to inject an ad at this offset.
547
  foreach ( $ads_for_placeholders as $ad ) {
548
  if ( isset( $ad['offset'] ) && $ad['offset'] === $n ) {
586
  return 0;
587
  }
588
 
589
+ $num = [
590
  'before' => 1,
591
  'prepend' => 2,
592
  'append' => 3,
593
  'after' => 4,
594
+ ];
595
 
596
  return $num[ $first['position'] ] > $num[ $second['position'] ] ? 1 : - 1;
597
  }
604
  * @return array $nodes.
605
  */
606
  public static function add_ad_health_node( $nodes ) {
607
+ $nodes[] = [
608
  'type' => 1,
609
+ 'data' => [
610
  'parent' => 'advanced_ads_ad_health',
611
  'id' => 'advanced_ads_ad_health_the_content_not_enough_elements',
612
  'title' => sprintf(
615
  __( 'Disable level limitation', 'advanced-ads' )
616
  ),
617
  'href' => admin_url( '/admin.php?page=advanced-ads-settings#top#general' ),
618
+ 'meta' => [
619
  'class' => 'advanced_ads_ad_health_warning',
620
  'target' => '_blank',
621
+ ],
622
+ ],
623
+ ];
624
 
625
  return $nodes;
626
  }
635
  private static function get_ancestors_to_limit( $xpath ) {
636
  $query = self::get_ancestors_to_limit_query();
637
  if ( ! $query ) {
638
+ return [];
639
  }
640
 
641
  $node_list = $xpath->query( $query );
642
+ $ancestors_to_limit = [];
643
 
644
  foreach ( $node_list as $a ) {
645
  $ancestors_to_limit[] = $a->getNodePath();
658
  * @return array $new_paragraphs An array of `DOMNode` objects to insert ads before or after.
659
  */
660
  private static function filter_by_ancestors_to_limit( $paragraphs, $ancestors_to_limit ) {
661
+ $new_paragraphs = [];
662
 
663
  foreach ( $paragraphs as $k => $paragraph ) {
664
  foreach ( $ancestors_to_limit as $a ) {
697
  */
698
  $items = apply_filters(
699
  'advanced-ads-content-injection-nodes-without-ads',
700
+ [
701
+ [
702
  // a class anyone can use to prevent automatic ad injection into a specific element.
703
  'node' => '.advads-stop-injection',
704
  'type' => 'ancestor',
705
+ ],
706
+ [
707
  // Product Slider for Beaver Builder by WooPack.
708
  'node' => '.woopack-product-carousel',
709
  'type' => 'ancestor',
710
+ ],
711
+ [
712
  // WP Author Box Lite.
713
  'node' => '#wpautbox-%',
714
  'type' => 'ancestor',
715
+ ],
716
+ [
717
  // GeoDirectory Post Slider.
718
  'node' => '.geodir-post-slider',
719
  'type' => 'ancestor',
720
+ ],
721
+ ]
722
  );
723
 
724
+ $query = [];
725
  foreach ( $items as $p ) {
726
  $sel = $p['node'];
727
 
classes/inline-css.php CHANGED
@@ -106,7 +106,7 @@ class Advanced_Ads_Inline_Css {
106
  }
107
 
108
  if ( ! empty( $privacy_options['enabled'] ) && $privacy_options['enabled'] === 'on' && $privacy_options['consent-method'] === 'iab_tcf_20' ) {
109
- add_filter( 'advanced-ads-output-final', array( $this, 'add_tcf_container' ), 20, 2 );
110
  $this->add_inline_css = false;
111
  }
112
  }
106
  }
107
 
108
  if ( ! empty( $privacy_options['enabled'] ) && $privacy_options['enabled'] === 'on' && $privacy_options['consent-method'] === 'iab_tcf_20' ) {
109
+ add_filter( 'advanced-ads-output-final', [ $this, 'add_tcf_container' ], 20, 2 );
110
  $this->add_inline_css = false;
111
  }
112
  }
classes/plugin.php CHANGED
@@ -55,12 +55,12 @@ class Advanced_Ads_Plugin {
55
  * Advanced_Ads_Plugin constructor.
56
  */
57
  private function __construct() {
58
- register_activation_hook( ADVADS_BASE, array( $this, 'activate' ) );
59
- register_deactivation_hook( ADVADS_BASE, array( $this, 'deactivate' ) );
60
- register_uninstall_hook( ADVADS_BASE, array( 'Advanced_Ads_Plugin', 'uninstall' ) );
61
 
62
- add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ), 20 );
63
- add_action( 'init', array( $this, 'run_upgrades' ), 9 );
64
  }
65
 
66
  /**
@@ -94,33 +94,33 @@ class Advanced_Ads_Plugin {
94
  $this->load_plugin_textdomain();
95
 
96
  // activate plugin when new blog is added on multisites // -TODO this is admin-only.
97
- add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
98
 
99
  // Load public-facing style sheet and JavaScript.
100
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
101
- add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
102
- add_action( 'wp_head', array( $this, 'print_head_scripts' ), 7 );
103
  // higher priority to make sure other scripts are printed before.
104
- add_action( 'wp_footer', array( $this, 'print_footer_scripts' ), 100 );
105
 
106
  // add short codes.
107
- add_shortcode( 'the_ad', array( $this, 'shortcode_display_ad' ) );
108
- add_shortcode( 'the_ad_group', array( $this, 'shortcode_display_ad_group' ) );
109
- add_shortcode( 'the_ad_placement', array( $this, 'shortcode_display_ad_placement' ) );
110
 
111
  // remove default ad group menu item // -TODO only for admin.
112
- add_action( 'admin_menu', array( $this, 'remove_taxonomy_menu_item' ) );
113
  // load widgets.
114
- add_action( 'widgets_init', array( $this, 'widget_init' ) );
115
 
116
  // Call action hooks for ad status changes.
117
- add_action( 'transition_post_status', array( $this, 'transition_ad_status' ), 10, 3 );
118
 
119
  // register expired post status.
120
  Advanced_Ads_Ad_Expiration::register_post_status();
121
 
122
  // if expired ad gets untrashed, revert it to expired status (instead of draft).
123
- add_filter( 'wp_untrash_post_status', array( Advanced_Ads_Ad_Expiration::class, 'wp_untrash_post_status' ), 10, 3 );
124
 
125
  // load display conditions.
126
  Advanced_Ads_Display_Conditions::get_instance();
@@ -175,7 +175,7 @@ class Advanced_Ads_Plugin {
175
  wp_register_script(
176
  $this->get_plugin_slug() . '-advanced-js',
177
  sprintf( '%spublic/assets/js/advanced%s.js', ADVADS_BASE_URL, defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ),
178
- array( 'jquery' ),
179
  ADVADS_VERSION,
180
  false
181
  );
@@ -188,10 +188,10 @@ class Advanced_Ads_Plugin {
188
  wp_localize_script(
189
  $this->get_plugin_slug() . '-advanced-js',
190
  'advads_options',
191
- array(
192
  'blog_id' => get_current_blog_id(),
193
  'privacy' => $privacy_options,
194
- )
195
  );
196
 
197
  $activated_js = apply_filters( 'advanced-ads-activate-advanced-js', isset( $this->options()['advanced-js'] ) );
@@ -203,7 +203,7 @@ class Advanced_Ads_Plugin {
203
  wp_register_script(
204
  $this->get_plugin_slug() . '-frontend-picker',
205
  sprintf( '%spublic/assets/js/frontend-picker%s.js', ADVADS_BASE_URL, defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ),
206
- array( 'jquery', $this->get_plugin_slug() . '-advanced-js' ),
207
  ADVADS_VERSION,
208
  false
209
  );
@@ -391,7 +391,7 @@ class Advanced_Ads_Plugin {
391
  * @return string ad content.
392
  */
393
  public function shortcode_display_ad( $atts ) {
394
- $atts = is_array( $atts ) ? $atts : array();
395
  $id = isset( $atts['id'] ) ? (int) $atts['id'] : 0;
396
  // check if there is an inline attribute with or without value.
397
  if ( isset( $atts['inline'] ) || in_array( 'inline', $atts, true ) ) {
@@ -411,7 +411,7 @@ class Advanced_Ads_Plugin {
411
  * @return string ad group content.
412
  */
413
  public function shortcode_display_ad_group( $atts ) {
414
- $atts = is_array( $atts ) ? $atts : array();
415
  $id = isset( $atts['id'] ) ? (int) $atts['id'] : 0;
416
  $atts = $this->prepare_shortcode_atts( $atts );
417
 
@@ -427,7 +427,7 @@ class Advanced_Ads_Plugin {
427
  * @return string ad placement content.
428
  */
429
  public function shortcode_display_ad_placement( $atts ) {
430
- $atts = is_array( $atts ) ? $atts : array();
431
  $id = isset( $atts['id'] ) ? (string) $atts['id'] : '';
432
  $atts = $this->prepare_shortcode_atts( $atts );
433
 
@@ -443,7 +443,7 @@ class Advanced_Ads_Plugin {
443
  * @return array
444
  */
445
  private function prepare_shortcode_atts( $atts ) {
446
- $result = array();
447
 
448
  /**
449
  * Prepare attributes by converting strings to multi-dimensional array
@@ -458,7 +458,7 @@ class Advanced_Ads_Plugin {
458
 
459
  foreach ( $levels as $lvl ) {
460
  if ( ! isset( $cur_lvl[ $lvl ] ) ) {
461
- $cur_lvl[ $lvl ] = array();
462
  }
463
 
464
  $cur_lvl = &$cur_lvl[ $lvl ];
@@ -469,11 +469,11 @@ class Advanced_Ads_Plugin {
469
 
470
  $result = array_diff_key(
471
  $result,
472
- array(
473
  'id' => false,
474
  'blog_id' => false,
475
  'ad_args' => false,
476
- )
477
  );
478
  }
479
 
@@ -495,7 +495,7 @@ class Advanced_Ads_Plugin {
495
  public function options() {
496
  // we can’t store options if WPML String Translations is enabled, or it would not translate the "Ad Label" option.
497
  if ( ! isset( $this->options ) || class_exists( 'WPML_ST_String' ) ) {
498
- $this->options = get_option( ADVADS_SLUG, array() );
499
  }
500
 
501
  // allow to change options dynamically
@@ -511,7 +511,7 @@ class Advanced_Ads_Plugin {
511
  */
512
  public function update_options( array $options ) {
513
  // do not allow to clear options.
514
- if ( array() === $options ) {
515
  return;
516
  }
517
 
@@ -527,14 +527,14 @@ class Advanced_Ads_Plugin {
527
  */
528
  public function internal_options() {
529
  if ( ! isset( $this->internal_options ) ) {
530
- $defaults = array(
531
  'version' => ADVADS_VERSION,
532
  'installed' => time(), // when was this installed.
533
- );
534
- $this->internal_options = get_option( ADVADS_SLUG . '-internal', array() );
535
 
536
  // save defaults.
537
- if ( array() === $this->internal_options ) {
538
  $this->internal_options = $defaults;
539
  $this->update_internal_options( $this->internal_options );
540
 
@@ -558,7 +558,7 @@ class Advanced_Ads_Plugin {
558
  */
559
  public function update_internal_options( array $options ) {
560
  // do not allow to clear options.
561
- if ( array() === $options ) {
562
  return;
563
  }
564
 
@@ -723,8 +723,8 @@ class Advanced_Ads_Plugin {
723
  if ( $post_ids ) {
724
  $wpdb->delete(
725
  $wpdb->posts,
726
- array( 'post_type' => Advanced_Ads::POST_TYPE_SLUG ),
727
- array( '%s' )
728
  );
729
 
730
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN( %s )", implode( ',', $post_ids ) ) );
@@ -737,34 +737,41 @@ class Advanced_Ads_Plugin {
737
  wp_delete_term( $term_id, Advanced_Ads::AD_GROUP_TAXONOMY );
738
  }
739
 
 
 
 
740
  delete_option( 'advads-ad-groups' );
741
- delete_option( Advanced_Ads::AD_GROUP_TAXONOMY . '_children' );
742
  delete_option( 'advads-ad-weights' );
743
-
744
- // Placements.
 
 
 
 
 
 
 
 
745
  delete_option( 'advads-ads-placements' );
746
 
747
  // User metadata.
748
  delete_metadata( 'user', null, 'advanced-ads-hide-wizard', '', true );
749
  delete_metadata( 'user', null, 'advanced-ads-subscribed', '', true );
 
 
 
 
 
 
 
 
750
 
751
  // Post metadata.
752
  delete_metadata( 'post', null, '_advads_ad_settings', '', true );
753
 
754
  // Transients.
755
- delete_transient( ADVADS_SLUG . '_add-on-updates-checked' );
756
-
757
- delete_option( GADSENSE_OPT_NAME );
758
- delete_option( ADVADS_SLUG );
759
- delete_option( ADVADS_SLUG . '-internal' );
760
- delete_option( ADVADS_SLUG . '-notices' );
761
-
762
- // Widget.
763
- $base_widget_id = Advanced_Ads_Widget::get_base_id();
764
- delete_option( 'widget_' . $base_widget_id );
765
-
766
- // Ad blocker disquise.
767
- delete_option( ADVADS_AB_SLUG );
768
 
769
  do_action( 'advanced-ads-uninstall' );
770
 
55
  * Advanced_Ads_Plugin constructor.
56
  */
57
  private function __construct() {
58
+ register_activation_hook( ADVADS_BASE, [ $this, 'activate' ] );
59
+ register_deactivation_hook( ADVADS_BASE, [ $this, 'deactivate' ] );
60
+ register_uninstall_hook( ADVADS_BASE, [ 'Advanced_Ads_Plugin', 'uninstall' ] );
61
 
62
+ add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ], 20 );
63
+ add_action( 'init', [ $this, 'run_upgrades' ], 9 );
64
  }
65
 
66
  /**
94
  $this->load_plugin_textdomain();
95
 
96
  // activate plugin when new blog is added on multisites // -TODO this is admin-only.
97
+ add_action( 'wpmu_new_blog', [ $this, 'activate_new_site' ] );
98
 
99
  // Load public-facing style sheet and JavaScript.
100
+ add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_styles' ] );
101
+ add_action( 'wp_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
102
+ add_action( 'wp_head', [ $this, 'print_head_scripts' ], 7 );
103
  // higher priority to make sure other scripts are printed before.
104
+ add_action( 'wp_footer', [ $this, 'print_footer_scripts' ], 100 );
105
 
106
  // add short codes.
107
+ add_shortcode( 'the_ad', [ $this, 'shortcode_display_ad' ] );
108
+ add_shortcode( 'the_ad_group', [ $this, 'shortcode_display_ad_group' ] );
109
+ add_shortcode( 'the_ad_placement', [ $this, 'shortcode_display_ad_placement' ] );
110
 
111
  // remove default ad group menu item // -TODO only for admin.
112
+ add_action( 'admin_menu', [ $this, 'remove_taxonomy_menu_item' ] );
113
  // load widgets.
114
+ add_action( 'widgets_init', [ $this, 'widget_init' ] );
115
 
116
  // Call action hooks for ad status changes.
117
+ add_action( 'transition_post_status', [ $this, 'transition_ad_status' ], 10, 3 );
118
 
119
  // register expired post status.
120
  Advanced_Ads_Ad_Expiration::register_post_status();
121
 
122
  // if expired ad gets untrashed, revert it to expired status (instead of draft).
123
+ add_filter( 'wp_untrash_post_status', [ Advanced_Ads_Ad_Expiration::class, 'wp_untrash_post_status' ], 10, 3 );
124
 
125
  // load display conditions.
126
  Advanced_Ads_Display_Conditions::get_instance();
175
  wp_register_script(
176
  $this->get_plugin_slug() . '-advanced-js',
177
  sprintf( '%spublic/assets/js/advanced%s.js', ADVADS_BASE_URL, defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ),
178
+ [ 'jquery' ],
179
  ADVADS_VERSION,
180
  false
181
  );
188
  wp_localize_script(
189
  $this->get_plugin_slug() . '-advanced-js',
190
  'advads_options',
191
+ [
192
  'blog_id' => get_current_blog_id(),
193
  'privacy' => $privacy_options,
194
+ ]
195
  );
196
 
197
  $activated_js = apply_filters( 'advanced-ads-activate-advanced-js', isset( $this->options()['advanced-js'] ) );
203
  wp_register_script(
204
  $this->get_plugin_slug() . '-frontend-picker',
205
  sprintf( '%spublic/assets/js/frontend-picker%s.js', ADVADS_BASE_URL, defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ),
206
+ [ 'jquery', $this->get_plugin_slug() . '-advanced-js' ],
207
  ADVADS_VERSION,
208
  false
209
  );
391
  * @return string ad content.
392
  */
393
  public function shortcode_display_ad( $atts ) {
394
+ $atts = is_array( $atts ) ? $atts : [];
395
  $id = isset( $atts['id'] ) ? (int) $atts['id'] : 0;
396
  // check if there is an inline attribute with or without value.
397
  if ( isset( $atts['inline'] ) || in_array( 'inline', $atts, true ) ) {
411
  * @return string ad group content.
412
  */
413
  public function shortcode_display_ad_group( $atts ) {
414
+ $atts = is_array( $atts ) ? $atts : [];
415
  $id = isset( $atts['id'] ) ? (int) $atts['id'] : 0;
416
  $atts = $this->prepare_shortcode_atts( $atts );
417
 
427
  * @return string ad placement content.
428
  */
429
  public function shortcode_display_ad_placement( $atts ) {
430
+ $atts = is_array( $atts ) ? $atts : [];
431
  $id = isset( $atts['id'] ) ? (string) $atts['id'] : '';
432
  $atts = $this->prepare_shortcode_atts( $atts );
433
 
443
  * @return array
444
  */
445
  private function prepare_shortcode_atts( $atts ) {
446
+ $result = [];
447
 
448
  /**
449
  * Prepare attributes by converting strings to multi-dimensional array
458
 
459
  foreach ( $levels as $lvl ) {
460
  if ( ! isset( $cur_lvl[ $lvl ] ) ) {
461
+ $cur_lvl[ $lvl ] = [];
462
  }
463
 
464
  $cur_lvl = &$cur_lvl[ $lvl ];
469
 
470
  $result = array_diff_key(
471
  $result,
472
+ [
473
  'id' => false,
474
  'blog_id' => false,
475
  'ad_args' => false,
476
+ ]
477
  );
478
  }
479
 
495
  public function options() {
496
  // we can’t store options if WPML String Translations is enabled, or it would not translate the "Ad Label" option.
497
  if ( ! isset( $this->options ) || class_exists( 'WPML_ST_String' ) ) {
498
+ $this->options = get_option( ADVADS_SLUG, [] );
499
  }
500
 
501
  // allow to change options dynamically
511
  */
512
  public function update_options( array $options ) {
513
  // do not allow to clear options.
514
+ if ( [] === $options ) {
515
  return;
516
  }
517
 
527
  */
528
  public function internal_options() {
529
  if ( ! isset( $this->internal_options ) ) {
530
+ $defaults = [
531
  'version' => ADVADS_VERSION,
532
  'installed' => time(), // when was this installed.
533
+ ];
534
+ $this->internal_options = get_option( ADVADS_SLUG . '-internal', [] );
535
 
536
  // save defaults.
537
+ if ( [] === $this->internal_options ) {
538
  $this->internal_options = $defaults;
539
  $this->update_internal_options( $this->internal_options );
540
 
558
  */
559
  public function update_internal_options( array $options ) {
560
  // do not allow to clear options.
561
+ if ( [] === $options ) {
562
  return;
563
  }
564
 
723
  if ( $post_ids ) {
724
  $wpdb->delete(
725
  $wpdb->posts,
726
+ [ 'post_type' => Advanced_Ads::POST_TYPE_SLUG ],
727
+ [ '%s' ]
728
  );
729
 
730
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->postmeta} WHERE post_id IN( %s )", implode( ',', $post_ids ) ) );
737
  wp_delete_term( $term_id, Advanced_Ads::AD_GROUP_TAXONOMY );
738
  }
739
 
740
+ delete_option( 'advanced-ads' );
741
+ delete_option( 'advanced-ads-internal' );
742
+ delete_option( 'advanced-ads-notices' );
743
  delete_option( 'advads-ad-groups' );
744
+ delete_option( 'advanced_ads_groups_children' );
745
  delete_option( 'advads-ad-weights' );
746
+ delete_option( 'advanced_ads_ads_txt' );
747
+ delete_option( 'advanced-ads-ad-health-notices' );
748
+ delete_option( 'advanced-ads-adsense' );
749
+ delete_option( 'advanced_ads_adsense_report_domain' );
750
+ delete_option( 'advanced_ads_adsense_report_unit' );
751
+ delete_option( 'advanced-ads-adsense-dashboard-filter' );
752
+ delete_option( 'advanced-ads-adsense-mapi' );
753
+ delete_option( 'advanced-ads-licenses' );
754
+ delete_option( 'advanced-ads-ab-module' );
755
+ delete_option( 'widget_' . Advanced_Ads_Widget::get_base_id() );
756
  delete_option( 'advads-ads-placements' );
757
 
758
  // User metadata.
759
  delete_metadata( 'user', null, 'advanced-ads-hide-wizard', '', true );
760
  delete_metadata( 'user', null, 'advanced-ads-subscribed', '', true );
761
+ delete_metadata( 'user', null, 'advanced-ads-ad-list-screen-options', '', true );
762
+ delete_metadata( 'user', null, 'advanced-ads-admin-settings', '', true );
763
+ delete_metadata( 'user', null, 'advanced-ads-role', '', true );
764
+ delete_metadata( 'user', null, 'edit_advanced_ads_per_page', '', true );
765
+ delete_metadata( 'user', null, 'meta-box-order_advanced_ads', '', true );
766
+ delete_metadata( 'user', null, 'screen_layout_advanced_ads', '', true );
767
+ delete_metadata( 'user', null, 'closedpostboxes_advanced_ads', '', true );
768
+ delete_metadata( 'user', null, 'metaboxhidden_advanced_ads', '', true );
769
 
770
  // Post metadata.
771
  delete_metadata( 'post', null, '_advads_ad_settings', '', true );
772
 
773
  // Transients.
774
+ delete_transient( 'advanced-ads_add-on-updates-checked' );
 
 
 
 
 
 
 
 
 
 
 
 
775
 
776
  do_action( 'advanced-ads-uninstall' );
777
 
classes/utils.php CHANGED
@@ -21,7 +21,7 @@ class Advanced_Ads_Utils {
21
  * @copyright Copyright 2001 - 2013 Drupal contributors. License: GPL-2.0+. Drupal is a registered trademark of Dries Buytaert.
22
  */
23
  public static function merge_deep_array( array $arrays, $preserve_integer_keys = false ) {
24
- $result = array();
25
  foreach ( $arrays as $array ) {
26
  if ( ! is_array( $array ) ) {
27
  continue; }
@@ -34,7 +34,7 @@ class Advanced_Ads_Utils {
34
  $result[] = $value;
35
  } elseif ( isset( $result[ $key ] ) && is_array( $result[ $key ] ) && is_array( $value ) ) {
36
  // recurse when both values are arrays.
37
- $result[ $key ] = self::merge_deep_array( array( $result[ $key ], $value ), $preserve_integer_keys );
38
  } else {
39
  // otherwise, use the latter value, overriding any previous value.
40
  $result[ $key ] = $value;
@@ -106,7 +106,7 @@ class Advanced_Ads_Utils {
106
  * @return array of Advanced_Ads_Ad objects.
107
  */
108
  public static function get_nested_ads( $id, $type ) {
109
- $result = array();
110
 
111
  switch ( $type ) {
112
  case 'placement':
@@ -145,7 +145,7 @@ class Advanced_Ads_Utils {
145
  global $wp_roles;
146
 
147
  $roles_or_caps = (array) $roles_or_caps;
148
- $roles = array();
149
 
150
  foreach ( $roles_or_caps as $cap ) {
151
  if ( $wp_roles->is_role( $cap ) ) {
21
  * @copyright Copyright 2001 - 2013 Drupal contributors. License: GPL-2.0+. Drupal is a registered trademark of Dries Buytaert.
22
  */
23
  public static function merge_deep_array( array $arrays, $preserve_integer_keys = false ) {
24
+ $result = [];
25
  foreach ( $arrays as $array ) {
26
  if ( ! is_array( $array ) ) {
27
  continue; }
34
  $result[] = $value;
35
  } elseif ( isset( $result[ $key ] ) && is_array( $result[ $key ] ) && is_array( $value ) ) {
36
  // recurse when both values are arrays.
37
+ $result[ $key ] = self::merge_deep_array( [ $result[ $key ], $value ], $preserve_integer_keys );
38
  } else {
39
  // otherwise, use the latter value, overriding any previous value.
40
  $result[ $key ] = $value;
106
  * @return array of Advanced_Ads_Ad objects.
107
  */
108
  public static function get_nested_ads( $id, $type ) {
109
+ $result = [];
110
 
111
  switch ( $type ) {
112
  case 'placement':
145
  global $wp_roles;
146
 
147
  $roles_or_caps = (array) $roles_or_caps;
148
+ $roles = [];
149
 
150
  foreach ( $roles_or_caps as $cap ) {
151
  if ( $wp_roles->is_role( $cap ) ) {
classes/visitor-conditions.php CHANGED
@@ -34,28 +34,28 @@ class Advanced_Ads_Visitor_Conditions {
34
  // register conditions.
35
  $this->conditions = apply_filters(
36
  'advanced-ads-visitor-conditions',
37
- array(
38
- 'mobile' => array(
39
  // type of the condition.
40
  'label' => __( 'device', 'advanced-ads' ),
41
  'description' => __( 'Display ads only on mobile devices or hide them.', 'advanced-ads' ),
42
- 'metabox' => array( 'Advanced_Ads_Visitor_Conditions', 'mobile_is_or_not' ), // callback to generate the metabox.
43
- 'check' => array( 'Advanced_Ads_Visitor_Conditions', 'check_mobile' ), // callback for frontend check.
44
  'helplink' => ADVADS_URL . 'manual/display-ads-either-on-mobile-or-desktop/?utm_source=advanced-ads&utm_medium=link&utm_campaign=condition-device',
45
- ),
46
- 'loggedin' => array(
47
  'label' => __( 'logged-in visitor', 'advanced-ads' ),
48
  'description' => __( 'Whether the visitor has to be logged in or not in order to see the ad.', 'advanced-ads' ),
49
- 'metabox' => array( 'Advanced_Ads_Visitor_Conditions', 'metabox_is_or_not' ), // callback to generate the metabox.
50
- 'check' => array( 'Advanced_Ads_Visitor_Conditions', 'check_logged_in' ), // callback for frontend check.
51
  'helplink' => ADVADS_URL . 'manual/logged-in-visitors/?utm_source=advanced-ads&utm_medium=link&utm_campaign=condition-logged-in-visitors',
52
- 'passive_info' => array(
53
  'hash_fields' => null,
54
  'remove' => 'login',
55
  'function' => 'is_user_logged_in',
56
- ),
57
- ),
58
- )
59
  );
60
  }
61
 
@@ -118,12 +118,12 @@ class Advanced_Ads_Visitor_Conditions {
118
  wp_kses(
119
  // translators: %s is a URL. Please don’t change it.
120
  __( 'Display ads by the available space on the device or target tablets with the <a href="%s" target="_blank">Responsive add-on</a>', 'advanced-ads' ),
121
- array(
122
- 'a' => array(
123
- 'href' => array(),
124
- 'target' => array(),
125
- ),
126
- )
127
  ),
128
  ADVADS_URL . 'add-ons/responsive-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor-responsive'
129
  );
@@ -225,7 +225,7 @@ class Advanced_Ads_Visitor_Conditions {
225
  *
226
  * @return bool false, if ad can’t be delivered
227
  */
228
- public static function frontend_check( $options = array(), $ad = false ) {
229
  $visitor_conditions = self::get_instance()->conditions;
230
 
231
  if ( is_array( $options ) && isset( $visitor_conditions[ $options['type'] ]['check'] ) ) {
@@ -236,7 +236,7 @@ class Advanced_Ads_Visitor_Conditions {
236
 
237
  // call frontend check callback.
238
  if ( method_exists( $check[0], $check[1] ) ) {
239
- return call_user_func( array( $check[0], $check[1] ), $options, $ad );
240
  }
241
 
242
  return true;
@@ -266,7 +266,7 @@ class Advanced_Ads_Visitor_Conditions {
266
  */
267
 
268
  // add mockup conditions if add-ons are missing.
269
- $pro_conditions = array();
270
  if ( ! defined( 'AAP_VERSION' ) ) {
271
  $pro_conditions[] = __( 'browser language', 'advanced-ads' );
272
  $pro_conditions[] = __( 'cookie', 'advanced-ads' );
@@ -340,7 +340,7 @@ class Advanced_Ads_Visitor_Conditions {
340
  *
341
  * @return bool true if can be displayed
342
  */
343
- public static function check_mobile( $options = array() ) {
344
 
345
  if ( ! isset( $options['operator'] ) ) {
346
  return true;
@@ -370,7 +370,7 @@ class Advanced_Ads_Visitor_Conditions {
370
  * @return bool true if can be displayed
371
  * @since 1.6.3
372
  */
373
- public static function check_logged_in( $options = array() ) {
374
 
375
  if ( ! isset( $options['operator'] ) ) {
376
  return true;
@@ -401,13 +401,14 @@ class Advanced_Ads_Visitor_Conditions {
401
  * @return bool true if ad can be displayed
402
  * @since 1.6.3
403
  */
404
- public static function helper_check_string( $string = '', $options = array() ) {
405
- if ( ! isset( $options['operator'] ) || ! isset( $options['value'] ) || '' === $options['value'] ) {
406
  return true;
407
  }
408
 
409
  $operator = $options['operator'];
410
- $value = $options['value'];
 
411
 
412
  // check the condition by mode and bool.
413
  $condition = true;
34
  // register conditions.
35
  $this->conditions = apply_filters(
36
  'advanced-ads-visitor-conditions',
37
+ [
38
+ 'mobile' => [
39
  // type of the condition.
40
  'label' => __( 'device', 'advanced-ads' ),
41
  'description' => __( 'Display ads only on mobile devices or hide them.', 'advanced-ads' ),
42
+ 'metabox' => [ 'Advanced_Ads_Visitor_Conditions', 'mobile_is_or_not' ], // callback to generate the metabox.
43
+ 'check' => [ 'Advanced_Ads_Visitor_Conditions', 'check_mobile' ], // callback for frontend check.
44
  'helplink' => ADVADS_URL . 'manual/display-ads-either-on-mobile-or-desktop/?utm_source=advanced-ads&utm_medium=link&utm_campaign=condition-device',
45
+ ],
46
+ 'loggedin' => [
47
  'label' => __( 'logged-in visitor', 'advanced-ads' ),
48
  'description' => __( 'Whether the visitor has to be logged in or not in order to see the ad.', 'advanced-ads' ),
49
+ 'metabox' => [ 'Advanced_Ads_Visitor_Conditions', 'metabox_is_or_not' ], // callback to generate the metabox.
50
+ 'check' => [ 'Advanced_Ads_Visitor_Conditions', 'check_logged_in' ], // callback for frontend check.
51
  'helplink' => ADVADS_URL . 'manual/logged-in-visitors/?utm_source=advanced-ads&utm_medium=link&utm_campaign=condition-logged-in-visitors',
52
+ 'passive_info' => [
53
  'hash_fields' => null,
54
  'remove' => 'login',
55
  'function' => 'is_user_logged_in',
56
+ ],
57
+ ],
58
+ ]
59
  );
60
  }
61
 
118
  wp_kses(
119
  // translators: %s is a URL. Please don’t change it.
120
  __( 'Display ads by the available space on the device or target tablets with the <a href="%s" target="_blank">Responsive add-on</a>', 'advanced-ads' ),
121
+ [
122
+ 'a' => [
123
+ 'href' => [],
124
+ 'target' => [],
125
+ ],
126
+ ]
127
  ),
128
  ADVADS_URL . 'add-ons/responsive-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=edit-visitor-responsive'
129
  );
225
  *
226
  * @return bool false, if ad can’t be delivered
227
  */
228
+ public static function frontend_check( $options = [], $ad = false ) {
229
  $visitor_conditions = self::get_instance()->conditions;
230
 
231
  if ( is_array( $options ) && isset( $visitor_conditions[ $options['type'] ]['check'] ) ) {
236
 
237
  // call frontend check callback.
238
  if ( method_exists( $check[0], $check[1] ) ) {
239
+ return call_user_func( [ $check[0], $check[1] ], $options, $ad );
240
  }
241
 
242
  return true;
266
  */
267
 
268
  // add mockup conditions if add-ons are missing.
269
+ $pro_conditions = [];
270
  if ( ! defined( 'AAP_VERSION' ) ) {
271
  $pro_conditions[] = __( 'browser language', 'advanced-ads' );
272
  $pro_conditions[] = __( 'cookie', 'advanced-ads' );
340
  *
341
  * @return bool true if can be displayed
342
  */
343
+ public static function check_mobile( $options = [] ) {
344
 
345
  if ( ! isset( $options['operator'] ) ) {
346
  return true;
370
  * @return bool true if can be displayed
371
  * @since 1.6.3
372
  */
373
+ public static function check_logged_in( $options = [] ) {
374
 
375
  if ( ! isset( $options['operator'] ) ) {
376
  return true;
401
  * @return bool true if ad can be displayed
402
  * @since 1.6.3
403
  */
404
+ public static function helper_check_string( $string = '', $options = [] ) {
405
+ if ( ! isset( $options['operator'] ) || empty( $options['value'] ) ) {
406
  return true;
407
  }
408
 
409
  $operator = $options['operator'];
410
+ $string = (string) maybe_serialize( $string );
411
+ $value = (string) maybe_serialize( $options['value'] );
412
 
413
  // check the condition by mode and bool.
414
  $condition = true;
classes/widget.php CHANGED
@@ -29,17 +29,17 @@ class Advanced_Ads_Widget extends WP_Widget {
29
  $prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
30
  $classname = $prefix . 'widget';
31
 
32
- $widget_ops = array(
33
  'classname' => $classname,
34
  'show_instance_in_rest' => true,
35
  'description' => __( 'Display Ads and Ad Groups.', 'advanced-ads' ),
36
- );
37
- $control_ops = array();
38
  $base_id = self::get_base_id();
39
 
40
  parent::__construct( $base_id, 'Advanced Ads', $widget_ops, $control_ops );
41
 
42
- add_filter( 'q2w3-fixed-widgets', array( $this, 'q2w3_replace_frontend_id' ) );
43
  }
44
 
45
  /**
@@ -89,7 +89,7 @@ class Advanced_Ads_Widget extends WP_Widget {
89
  $instance['item_id'] = $new_instance['item_id'];
90
 
91
  // Allow to remove/replace id for new widgets and if it was allowed earlier.
92
- if ( array() === $old_instance || ! empty( $old_instance['remove-widget-id'] ) ) {
93
  $instance['remove-widget-id'] = true;
94
  }
95
  return $instance;
@@ -103,10 +103,10 @@ class Advanced_Ads_Widget extends WP_Widget {
103
  public function form( $instance ) {
104
  $instance = wp_parse_args(
105
  (array) $instance,
106
- array(
107
  'title' => '',
108
  'item_id' => '',
109
- )
110
  );
111
  $title = strip_tags( $instance['title'] );
112
  $elementid = $instance['item_id'];
@@ -166,15 +166,15 @@ class Advanced_Ads_Widget extends WP_Widget {
166
  * @return array $select items for select field.
167
  */
168
  public static function items_for_select() {
169
- $select = array();
170
  $model = Advanced_Ads::get_instance()->get_model();
171
 
172
  // load all ads.
173
  $ads = $model->get_ads(
174
- array(
175
  'orderby' => 'title',
176
  'order' => 'ASC',
177
- )
178
  );
179
  foreach ( $ads as $_ad ) {
180
  $select['ads'][ 'ad_' . $_ad->ID ] = $_ad->post_title;
@@ -195,7 +195,7 @@ class Advanced_Ads_Widget extends WP_Widget {
195
  * @return array $items for select field.
196
  */
197
  public static function widget_placements_for_select() {
198
- $select = array();
199
  $placements = Advanced_Ads::get_instance()->get_model()->get_ad_placements_array();
200
 
201
  if ( is_array( $placements ) ) {
@@ -203,7 +203,7 @@ class Advanced_Ads_Widget extends WP_Widget {
203
  }
204
 
205
  foreach ( $placements as $placement_slug => $placement ) {
206
- if ( isset( $placement['type'] ) && in_array( $placement['type'], array( 'sidebar_widget', 'default' ), true ) ) {
207
  $select['placements'][ 'placement_' . $placement_slug ] = $placement['name'];
208
  }
209
  }
29
  $prefix = Advanced_Ads_Plugin::get_instance()->get_frontend_prefix();
30
  $classname = $prefix . 'widget';
31
 
32
+ $widget_ops = [
33
  'classname' => $classname,
34
  'show_instance_in_rest' => true,
35
  'description' => __( 'Display Ads and Ad Groups.', 'advanced-ads' ),
36
+ ];
37
+ $control_ops = [];
38
  $base_id = self::get_base_id();
39
 
40
  parent::__construct( $base_id, 'Advanced Ads', $widget_ops, $control_ops );
41
 
42
+ add_filter( 'q2w3-fixed-widgets', [ $this, 'q2w3_replace_frontend_id' ] );
43
  }
44
 
45
  /**
89
  $instance['item_id'] = $new_instance['item_id'];
90
 
91
  // Allow to remove/replace id for new widgets and if it was allowed earlier.
92
+ if ( [] === $old_instance || ! empty( $old_instance['remove-widget-id'] ) ) {
93
  $instance['remove-widget-id'] = true;
94
  }
95
  return $instance;
103
  public function form( $instance ) {
104
  $instance = wp_parse_args(
105
  (array) $instance,
106
+ [
107
  'title' => '',
108
  'item_id' => '',
109
+ ]
110
  );
111
  $title = strip_tags( $instance['title'] );
112
  $elementid = $instance['item_id'];
166
  * @return array $select items for select field.
167
  */
168
  public static function items_for_select() {
169
+ $select = [];
170
  $model = Advanced_Ads::get_instance()->get_model();
171
 
172
  // load all ads.
173
  $ads = $model->get_ads(
174
+ [
175
  'orderby' => 'title',
176
  'order' => 'ASC',
177
+ ]
178
  );
179
  foreach ( $ads as $_ad ) {
180
  $select['ads'][ 'ad_' . $_ad->ID ] = $_ad->post_title;
195
  * @return array $items for select field.
196
  */
197
  public static function widget_placements_for_select() {
198
+ $select = [];
199
  $placements = Advanced_Ads::get_instance()->get_model()->get_ad_placements_array();
200
 
201
  if ( is_array( $placements ) ) {
203
  }
204
 
205
  foreach ( $placements as $placement_slug => $placement ) {
206
+ if ( isset( $placement['type'] ) && in_array( $placement['type'], [ 'sidebar_widget', 'default' ], true ) ) {
207
  $select['placements'][ 'placement_' . $placement_slug ] = $placement['name'];
208
  }
209
  }
includes/array_ad_conditions.php CHANGED
@@ -28,72 +28,72 @@ if ( ! class_exists( 'Advanced_Ads', false ) ) {
28
 
29
  $advanced_ads_slug = Advanced_Ads::get_instance()->get_plugin_slug();
30
 
31
- $advanced_ads_ad_conditions = array(
32
- 'enabled' => array( // dummy, to let the validation of the general ad conditions past
33
  // 'label' => __('Post Types', 'advanced-ads'),
34
  // 'description' => __('Choose the public post types on which to display the ad.', 'advanced-ads'),
35
  'type' => 'other',
36
  // 'callback' => array('Advanced_Ads_Display_Condition_Callbacks', 'post_types')
37
- ),
38
- 'posttypes' => array(
39
  'label' => __( 'Post Types', 'advanced-ads' ),
40
  'description' => __( 'Choose the public post types on which to display the ad.', 'advanced-ads' ),
41
  'type' => 'textvalues',
42
- 'callback' => array('Advanced_Ads_Display_Condition_Callbacks', 'post_types')
43
- ),
44
- 'categoryids' => array(
45
  'label' => __( 'Categories, Tags and Taxonomies', 'advanced-ads' ),
46
  'description' => __( 'Choose terms from public category, tag and other taxonomies a post must belong to in order to have ads.', 'advanced-ads' ),
47
  'type' => 'idfield',
48
- 'callback' => array('Advanced_Ads_Display_Condition_Callbacks', 'terms')
49
- ),
50
- 'categoryarchiveids' => array(
51
  'label' => __( 'Category Archives', 'advanced-ads' ),
52
  'description' => __( 'comma seperated IDs of category archives', 'advanced-ads' ),
53
  'type' => 'idfield',
54
- 'callback' => array('Advanced_Ads_Display_Condition_Callbacks', 'category_archives')
55
- ),
56
- 'postids' => array(
57
  'label' => __( 'Individual Posts, Pages and Public Post Types', 'advanced-ads' ),
58
  'description' => __( 'Choose on which individual posts, pages and public post type pages you want to display or hide ads.', 'advanced-ads' ),
59
  'type' => 'other',
60
- 'callback' => array('Advanced_Ads_Display_Condition_Callbacks', 'single_posts')
61
- ),
62
- 'is_front_page' => array(
63
  'label' => __( 'Home Page', 'advanced-ads' ),
64
  'description' => __( 'show on Home page', 'advanced-ads' ),
65
  'type' => 'radio',
66
- ),
67
- 'is_singular' => array(
68
  'label' => __( 'Singular Pages', 'advanced-ads' ),
69
  'description' => __( 'show on singular pages/posts', 'advanced-ads' ),
70
  'type' => 'radio',
71
- ),
72
- 'is_archive' => array(
73
  'label' => __( 'Archive Pages', 'advanced-ads' ),
74
  'description' => __( 'show on any type of archive page (category, tag, author and date)', 'advanced-ads' ),
75
  'type' => 'radio',
76
- ),
77
- 'is_search' => array(
78
  'label' => __( 'Search Results', 'advanced-ads' ),
79
  'description' => __( 'show on search result pages', 'advanced-ads' ),
80
  'type' => 'radio',
81
- ),
82
- 'is_404' => array(
83
  'label' => __( '404 Page', 'advanced-ads' ),
84
  'description' => __( 'show on 404 error page', 'advanced-ads' ),
85
  'type' => 'radio',
86
- ),
87
- 'is_attachment' => array(
88
  'label' => __( 'Attachment Pages', 'advanced-ads' ),
89
  'description' => __( 'show on attachment pages', 'advanced-ads' ),
90
  'type' => 'radio',
91
- ),
92
- 'is_main_query' => array(
93
  'label' => __( 'Secondary Queries', 'advanced-ads' ),
94
  'description' => __( 'allow ads in secondary queries', 'advanced-ads' ),
95
  'type' => 'radio',
96
- )
97
- );
98
 
99
  return apply_filters( 'advanced-ads-conditions', $advanced_ads_ad_conditions );
28
 
29
  $advanced_ads_slug = Advanced_Ads::get_instance()->get_plugin_slug();
30
 
31
+ $advanced_ads_ad_conditions = [
32
+ 'enabled' => [ // dummy, to let the validation of the general ad conditions past
33
  // 'label' => __('Post Types', 'advanced-ads'),
34
  // 'description' => __('Choose the public post types on which to display the ad.', 'advanced-ads'),
35
  'type' => 'other',
36
  // 'callback' => array('Advanced_Ads_Display_Condition_Callbacks', 'post_types')
37
+ ],
38
+ 'posttypes' => [
39
  'label' => __( 'Post Types', 'advanced-ads' ),
40
  'description' => __( 'Choose the public post types on which to display the ad.', 'advanced-ads' ),
41
  'type' => 'textvalues',
42
+ 'callback' => ['Advanced_Ads_Display_Condition_Callbacks', 'post_types']
43
+ ],
44
+ 'categoryids' => [
45
  'label' => __( 'Categories, Tags and Taxonomies', 'advanced-ads' ),
46
  'description' => __( 'Choose terms from public category, tag and other taxonomies a post must belong to in order to have ads.', 'advanced-ads' ),
47
  'type' => 'idfield',
48
+ 'callback' => ['Advanced_Ads_Display_Condition_Callbacks', 'terms']
49
+ ],
50
+ 'categoryarchiveids' => [
51
  'label' => __( 'Category Archives', 'advanced-ads' ),
52
  'description' => __( 'comma seperated IDs of category archives', 'advanced-ads' ),
53
  'type' => 'idfield',
54
+ 'callback' => ['Advanced_Ads_Display_Condition_Callbacks', 'category_archives']
55
+ ],
56
+ 'postids' => [
57
  'label' => __( 'Individual Posts, Pages and Public Post Types', 'advanced-ads' ),
58
  'description' => __( 'Choose on which individual posts, pages and public post type pages you want to display or hide ads.', 'advanced-ads' ),
59
  'type' => 'other',
60
+ 'callback' => ['Advanced_Ads_Display_Condition_Callbacks', 'single_posts']
61
+ ],
62
+ 'is_front_page' => [
63
  'label' => __( 'Home Page', 'advanced-ads' ),
64
  'description' => __( 'show on Home page', 'advanced-ads' ),
65
  'type' => 'radio',
66
+ ],
67
+ 'is_singular' => [
68
  'label' => __( 'Singular Pages', 'advanced-ads' ),
69
  'description' => __( 'show on singular pages/posts', 'advanced-ads' ),
70
  'type' => 'radio',
71
+ ],
72
+ 'is_archive' => [
73
  'label' => __( 'Archive Pages', 'advanced-ads' ),
74
  'description' => __( 'show on any type of archive page (category, tag, author and date)', 'advanced-ads' ),
75
  'type' => 'radio',
76
+ ],
77
+ 'is_search' => [
78
  'label' => __( 'Search Results', 'advanced-ads' ),
79
  'description' => __( 'show on search result pages', 'advanced-ads' ),
80
  'type' => 'radio',
81
+ ],
82
+ 'is_404' => [
83
  'label' => __( '404 Page', 'advanced-ads' ),
84
  'description' => __( 'show on 404 error page', 'advanced-ads' ),
85
  'type' => 'radio',
86
+ ],
87
+ 'is_attachment' => [
88
  'label' => __( 'Attachment Pages', 'advanced-ads' ),
89
  'description' => __( 'show on attachment pages', 'advanced-ads' ),
90
  'type' => 'radio',
91
+ ],
92
+ 'is_main_query' => [
93
  'label' => __( 'Secondary Queries', 'advanced-ads' ),
94
  'description' => __( 'allow ads in secondary queries', 'advanced-ads' ),
95
  'type' => 'radio',
96
+ ]
97
+ ];
98
 
99
  return apply_filters( 'advanced-ads-conditions', $advanced_ads_ad_conditions );
includes/cap_map.php CHANGED
@@ -6,10 +6,10 @@
6
  * currently only for informational purposes
7
  */
8
 
9
- $advanced_ads_capabilities = apply_filters( 'advanced-ads-capabilities', array(
10
  'advanced_ads_manage_options', // admins only
11
  'advanced_ads_see_interface', // admins, maybe editors
12
  'advanced_ads_edit_ads', // admins, maybe editors
13
  'advanced_ads_manage_placements', // admins, maybe editors
14
  'advanced_ads_place_ads', // admins, maybe editors
15
- ));
6
  * currently only for informational purposes
7
  */
8
 
9
+ $advanced_ads_capabilities = apply_filters( 'advanced-ads-capabilities', [
10
  'advanced_ads_manage_options', // admins only
11
  'advanced_ads_see_interface', // admins, maybe editors
12
  'advanced_ads_edit_ads', // admins, maybe editors
13
  'advanced_ads_manage_placements', // admins, maybe editors
14
  'advanced_ads_place_ads', // admins, maybe editors
15
+ ]);
includes/functions.php CHANGED
@@ -11,9 +11,9 @@
11
  * @param int $id id of the ad (post)
12
  * @param arr $args additional arguments
13
  */
14
- function get_ad($id = 0, $args = array()){
15
  if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) {
16
- $args = array();
17
  }
18
 
19
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'id', $args );
@@ -26,7 +26,7 @@ function get_ad($id = 0, $args = array()){
26
  * @param int $id id of the ad (post)
27
  * @param arr $args additional arguments
28
  */
29
- function the_ad($id = 0, $args = array()){
30
  echo get_ad( $id, $args );
31
  }
32
 
@@ -37,9 +37,9 @@ function the_ad($id = 0, $args = array()){
37
  * @param int $id id of the ad group (taxonomy)
38
  *
39
  */
40
- function get_ad_group( $id = 0, $args = array() ) {
41
  if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) {
42
- $args = array();
43
  }
44
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'group', $args );
45
  }
@@ -61,9 +61,9 @@ function the_ad_group($id = 0){
61
  * @param string $id slug of the ad placement
62
  *
63
  */
64
- function get_ad_placement( $id = '', $args = array() ) {
65
  if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) {
66
- $args = array();
67
  }
68
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'placement', $args );
69
  }
@@ -99,7 +99,7 @@ function advads_is_amp() {
99
  if ( is_admin()
100
  || is_embed()
101
  || is_feed()
102
- || ( isset( $pagenow ) && in_array( $pagenow, array( 'wp-login.php', 'wp-signup.php', 'wp-activate.php' ), true ) )
103
  || ( defined( 'REST_REQUEST' ) && REST_REQUEST )
104
  || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST )
105
  ) {
@@ -123,10 +123,10 @@ function advads_is_amp() {
123
  * @return bool
124
  */
125
  function placement_has_ads( $id = '' ) {
126
- $args = array(
127
  'global_output' => false,
128
  'cache-busting' => 'ignore',
129
- );
130
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'placement', $args ) != '';
131
 
132
  }
@@ -137,9 +137,9 @@ function placement_has_ads( $id = '' ) {
137
  * @return bool
138
  */
139
  function group_has_ads( $id = '' ) {
140
- $args = array(
141
  'global_output' => false,
142
  'cache-busting' => 'ignore',
143
- );
144
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'group', $args ) != '';
145
  }
11
  * @param int $id id of the ad (post)
12
  * @param arr $args additional arguments
13
  */
14
+ function get_ad($id = 0, $args = []){
15
  if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) {
16
+ $args = [];
17
  }
18
 
19
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'id', $args );
26
  * @param int $id id of the ad (post)
27
  * @param arr $args additional arguments
28
  */
29
+ function the_ad($id = 0, $args = []){
30
  echo get_ad( $id, $args );
31
  }
32
 
37
  * @param int $id id of the ad group (taxonomy)
38
  *
39
  */
40
+ function get_ad_group( $id = 0, $args = [] ) {
41
  if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) {
42
+ $args = [];
43
  }
44
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'group', $args );
45
  }
61
  * @param string $id slug of the ad placement
62
  *
63
  */
64
+ function get_ad_placement( $id = '', $args = [] ) {
65
  if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) {
66
+ $args = [];
67
  }
68
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'placement', $args );
69
  }
99
  if ( is_admin()
100
  || is_embed()
101
  || is_feed()
102
+ || ( isset( $pagenow ) && in_array( $pagenow, [ 'wp-login.php', 'wp-signup.php', 'wp-activate.php' ], true ) )
103
  || ( defined( 'REST_REQUEST' ) && REST_REQUEST )
104
  || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST )
105
  ) {
123
  * @return bool
124
  */
125
  function placement_has_ads( $id = '' ) {
126
+ $args = [
127
  'global_output' => false,
128
  'cache-busting' => 'ignore',
129
+ ];
130
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'placement', $args ) != '';
131
 
132
  }
137
  * @return bool
138
  */
139
  function group_has_ads( $id = '' ) {
140
+ $args = [
141
  'global_output' => false,
142
  'cache-busting' => 'ignore',
143
+ ];
144
  return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'group', $args ) != '';
145
  }
includes/load_modules.php CHANGED
@@ -6,8 +6,8 @@
6
  final class Advanced_Ads_ModuleLoader {
7
 
8
  protected static $loader;
9
- protected static $textdomains = array();
10
- protected static $modules = array();
11
 
12
  /**
13
  * Get the Composer autoloader.
@@ -30,10 +30,10 @@ final class Advanced_Ads_ModuleLoader {
30
  * @param string $path path to modules
31
  * @param array $options module loader options
32
  */
33
- public static function loadModules($path, $options = array()) {
34
  $loader = self::getLoader();
35
 
36
- $disabledModules = isset($options['disabled']) ? (array) $options['disabled'] : array();
37
  $isAdmin = is_admin();
38
 
39
  // iterate modules
6
  final class Advanced_Ads_ModuleLoader {
7
 
8
  protected static $loader;
9
+ protected static $textdomains = [];
10
+ protected static $modules = [];
11
 
12
  /**
13
  * Get the Composer autoloader.
30
  * @param string $path path to modules
31
  * @param array $options module loader options
32
  */
33
+ public static function loadModules($path, $options = []) {
34
  $loader = self::getLoader();
35
 
36
+ $disabledModules = isset($options['disabled']) ? (array) $options['disabled'] : [];
37
  $isAdmin = is_admin();
38
 
39
  // iterate modules
languages/advanced-ads.pot CHANGED
@@ -2,14 +2,14 @@
2
  # This file is distributed under the GPL-2.0+.
3
  msgid ""
4
  msgstr ""
5
- "Project-Id-Version: Advanced Ads 1.37.1\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/advanced-ads/\n"
7
  "Last-Translator: Thomas Maier <post@webzunft.de>\n"
8
  "Language-Team: webgilde <support@wpadvancedads.com>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
- "POT-Creation-Date: 2022-11-02T10:46:48+00:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.7.1\n"
15
  "X-Domain: advanced-ads\n"
@@ -125,8 +125,8 @@ msgstr ""
125
  msgid "Thank the developer with a &#9733;&#9733;&#9733;&#9733;&#9733; review on <a href=\"%s\" target=\"_blank\">wordpress.org</a>"
126
  msgstr ""
127
 
128
- #: admin/class-advanced-ads-admin.php:795
129
- #: admin/class-advanced-ads-admin.php:801
130
  #: admin/includes/class-menu.php:123
131
  #: admin/views/ad-group-list-ads.php:36
132
  #: public/class-advanced-ads.php:798
@@ -134,30 +134,31 @@ msgstr ""
134
  msgid "New Ad"
135
  msgstr ""
136
 
137
- #: admin/class-advanced-ads-admin.php:800
138
  msgid "Your Ads"
139
  msgstr ""
140
 
141
- #: admin/class-advanced-ads-admin.php:810
142
  msgid "Your Groups"
143
  msgstr ""
144
 
145
- #: admin/class-advanced-ads-admin.php:811
 
146
  #: public/class-advanced-ads.php:762
147
  msgid "New Ad Group"
148
  msgstr ""
149
 
150
- #: admin/class-advanced-ads-admin.php:819
151
  msgid "Your Placements"
152
  msgstr ""
153
 
154
- #: admin/class-advanced-ads-admin.php:820
155
  #: admin/views/placements.php:37
156
  #: admin/views/placements.php:464
157
  msgid "New Placement"
158
  msgstr ""
159
 
160
- #: admin/class-advanced-ads-admin.php:826
161
  #: admin/includes/class-menu.php:150
162
  msgid "Advanced Ads Settings"
163
  msgstr ""
@@ -302,67 +303,73 @@ msgstr ""
302
  msgid "Learn how."
303
  msgstr ""
304
 
305
- #: admin/includes/class-ad-groups-list.php:185
 
 
 
 
 
306
  msgid "Ad weight"
307
  msgstr ""
308
 
309
  #. translators: %s is a date.
310
- #: admin/includes/class-ad-groups-list.php:197
311
  #: admin/views/ad-list/timing.php:21
312
  msgid "starts %s"
313
  msgstr ""
314
 
315
  #. translators: %s is a date.
316
  #. translators: %s is a time and date string.
317
- #: admin/includes/class-ad-groups-list.php:218
318
  #: admin/views/ad-list/timing.php:59
319
  msgid "expires %s"
320
  msgstr ""
321
 
322
  #. translators: %s is a date.
323
  #. translators: %s is a time and date string.
324
- #: admin/includes/class-ad-groups-list.php:221
325
  #: admin/views/ad-list/timing.php:70
326
  msgid "<strong>expired</strong> %s"
327
  msgstr ""
328
 
329
  #. translators: %d is a number.
330
- #: admin/includes/class-ad-groups-list.php:238
331
  msgid "show %d more ads"
332
  msgstr ""
333
 
334
- #: admin/includes/class-ad-groups-list.php:243
335
  msgid "No ads assigned"
336
  msgstr ""
337
 
338
- #: admin/includes/class-ad-groups-list.php:245
339
  msgid "Add some"
340
  msgstr ""
341
 
342
  #. translators: amount of ads displayed
343
- #: admin/includes/class-ad-groups-list.php:273
344
  msgid "Up to %d ad displayed."
345
  msgid_plural "Up to %d ads displayed"
346
  msgstr[0] ""
347
  msgstr[1] ""
348
 
349
- #: admin/includes/class-ad-groups-list.php:343
350
  msgid "Random ads"
351
  msgstr ""
352
 
353
- #: admin/includes/class-ad-groups-list.php:344
354
  msgid "Display random ads based on ad weight"
355
  msgstr ""
356
 
357
- #: admin/includes/class-ad-groups-list.php:347
358
  msgid "Ordered ads"
359
  msgstr ""
360
 
361
- #: admin/includes/class-ad-groups-list.php:348
362
  msgid "Display ads with the highest ad weight first"
363
  msgstr ""
364
 
365
- #: admin/includes/class-ad-groups-list.php:367
 
366
  #: admin/views/placements.php:273
367
  #: modules/import-export/classes/import.php:153
368
  #: modules/import-export/classes/import.php:193
@@ -371,40 +378,41 @@ msgstr ""
371
  msgid "Edit"
372
  msgstr ""
373
 
374
- #: admin/includes/class-ad-groups-list.php:368
375
  #: admin/views/placements.php:131
376
  msgid "show usage"
377
  msgstr ""
378
 
379
- #: admin/includes/class-ad-groups-list.php:377
380
  #: admin/views/placements.php:10
381
  msgid "Delete"
382
  msgstr ""
383
 
384
- #: admin/includes/class-ad-groups-list.php:399
385
- #: admin/includes/class-ad-groups-list.php:469
386
  msgid "Invalid Ad Group"
387
  msgstr ""
388
 
389
- #: admin/includes/class-ad-groups-list.php:404
390
- #: admin/includes/class-ad-groups-list.php:474
391
  msgid "You don’t have permission to change the ad groups"
392
  msgstr ""
393
 
394
- #: admin/includes/class-ad-groups-list.php:438
395
  msgid "No ad group created"
396
  msgstr ""
397
 
398
  #: admin/includes/class-ad-type.php:133
399
- #: admin/views/ad-group-list-form-row.php:61
 
400
  #: admin/views/placements.php:56
401
- #: admin/views/placements.php:256
402
  #: modules/gadsense/admin/views/adsense-ad-parameters.php:105
403
  msgid "Type"
404
  msgstr ""
405
 
406
  #: admin/includes/class-ad-type.php:138
407
- #: admin/views/ad-group-list-form-row.php:36
 
408
  #: admin/views/placements.php:56
409
  #: modules/gadsense/admin/views/external-ads-list.php:38
410
  #: modules/privacy/admin/views/setting-general.php:44
@@ -528,6 +536,7 @@ msgid "Upgrade"
528
  msgstr ""
529
 
530
  #: admin/includes/class-admin-upgrades.php:83
 
531
  msgid "Pro Feature"
532
  msgstr ""
533
 
@@ -645,7 +654,7 @@ msgstr ""
645
  #: admin/includes/class-menu.php:90
646
  #: admin/includes/class-menu.php:91
647
  #: admin/includes/class-shortcode-creator.php:212
648
- #: admin/views/ad-group-list-form-row.php:96
649
  #: admin/views/ad-group-list-header.php:16
650
  #: admin/views/placement-form.php:61
651
  #: admin/views/placements-item.php:26
@@ -700,6 +709,14 @@ msgstr ""
700
  msgid "You attempted to edit an ad group that doesn&#8217;t exist. Perhaps it was deleted?"
701
  msgstr ""
702
 
 
 
 
 
 
 
 
 
703
  #: admin/includes/class-meta-box.php:61
704
  msgid "Ad Type"
705
  msgstr ""
@@ -710,7 +727,7 @@ msgid "AdSense Earnings"
710
  msgstr ""
711
 
712
  #: admin/includes/class-meta-box.php:89
713
- #: admin/views/ad-group-list-row.php:39
714
  #: admin/views/placements.php:305
715
  msgid "Usage"
716
  msgstr ""
@@ -750,11 +767,13 @@ msgstr ""
750
  #: admin/includes/class-meta-box.php:231
751
  #: admin/includes/class-meta-box.php:236
752
  #: admin/includes/class-overview-widgets.php:179
753
- #: admin/views/ad-group.php:76
754
  #: admin/views/ad-main-metabox.php:29
755
  #: admin/views/ad-output-metabox.php:43
756
  #: admin/views/conditions/condition-device.php:22
757
  #: admin/views/conditions/condition-is-or-not.php:21
 
 
758
  #: admin/views/header.php:50
759
  #: admin/views/placements.php:28
760
  #: admin/views/settings/general/custom-label.php:10
@@ -1280,45 +1299,44 @@ msgstr ""
1280
  msgid "add"
1281
  msgstr ""
1282
 
1283
- #: admin/views/ad-group-list-form-row.php:77
1284
  msgctxt "option to display all ads in an ad groups"
1285
  msgid "all"
1286
  msgstr ""
1287
 
1288
- #: admin/views/ad-group-list-form-row.php:84
1289
  msgid "Visible ads"
1290
  msgstr ""
1291
 
1292
- #: admin/views/ad-group-list-form-row.php:86
1293
  msgid "Number of ads that are visible at the same time"
1294
  msgstr ""
1295
 
1296
- #: admin/views/ad-group-list-header.php:14
1297
- #: classes/ad_type_group.php:30
1298
- msgid "Ad Group"
1299
- msgstr ""
1300
-
1301
  #: admin/views/ad-group-list-header.php:15
1302
  msgid "Details"
1303
  msgstr ""
1304
 
1305
- #: admin/views/ad-group-list-row.php:32
 
 
 
 
1306
  #: admin/views/placements.php:309
1307
  msgid "shortcode"
1308
  msgstr ""
1309
 
1310
- #: admin/views/ad-group-list-row.php:34
1311
  #: admin/views/placements.php:312
1312
  msgid "template (PHP)"
1313
  msgstr ""
1314
 
1315
  #. translators: %s is the name of a group type
1316
- #: admin/views/ad-group-list-row.php:50
1317
  msgid "Type: %s"
1318
  msgstr ""
1319
 
1320
  #. translators: %s is the ID of an ad group
1321
- #: admin/views/ad-group-list-row.php:58
1322
  msgid "ID: %s"
1323
  msgstr ""
1324
 
@@ -1330,20 +1348,17 @@ msgstr ""
1330
  msgid "Ad Groups successfully updated"
1331
  msgstr ""
1332
 
1333
- #: admin/views/ad-group.php:69
1334
- msgid "Group title"
1335
  msgstr ""
1336
 
1337
- #: admin/views/ad-group.php:70
1338
- msgid "save"
1339
  msgstr ""
1340
 
1341
- #: admin/views/ad-group.php:74
1342
- msgid "Ad Groups are a very flexible method to bundle ads. You can use them to display random ads in the frontend or run split tests, but also just for informational purposes. Not only can an Ad Groups have multiple ads, but an ad can belong to multiple ad groups."
1343
- msgstr ""
1344
-
1345
- #: admin/views/ad-group.php:110
1346
- msgid "Update Groups"
1347
  msgstr ""
1348
 
1349
  #: admin/views/ad-info-after-textarea.php:17
@@ -1724,6 +1739,28 @@ msgstr ""
1724
  msgid "There is an error in your AdSense setup."
1725
  msgstr ""
1726
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1727
  #: admin/views/header.php:33
1728
  msgid "Reset"
1729
  msgstr ""
@@ -1815,10 +1852,6 @@ msgstr ""
1815
  msgid "Placement types define where the ad is going to be displayed. Learn more about the different types from the <a href=\"%s\">manual</a>"
1816
  msgstr ""
1817
 
1818
- #: admin/views/placement-form.php:38
1819
- msgid "Please select a placement type."
1820
- msgstr ""
1821
-
1822
  #: admin/views/placement-form.php:40
1823
  msgid "Choose a Name"
1824
  msgstr ""
@@ -1831,10 +1864,6 @@ msgstr ""
1831
  msgid "The name of the placement is only visible to you. Tip: choose a descriptive one, e.g. Below Post Headline."
1832
  msgstr ""
1833
 
1834
- #: admin/views/placement-form.php:49
1835
- msgid "Please enter a name for your placement."
1836
- msgstr ""
1837
-
1838
  #: admin/views/placement-form.php:50
1839
  msgid "Choose the Ad or Group"
1840
  msgstr ""
@@ -2723,6 +2752,10 @@ msgstr ""
2723
  msgid "URL"
2724
  msgstr ""
2725
 
 
 
 
 
2726
  #: classes/ad_type_group.php:31
2727
  msgid "Choose an existing ad group. Use this type when you want to assign the same display and visitor conditions to all ads in that group."
2728
  msgstr ""
@@ -4357,10 +4390,6 @@ msgstr ""
4357
  msgid "New Ad Groups Name"
4358
  msgstr ""
4359
 
4360
- #: public/class-advanced-ads.php:765
4361
- msgid "No Ad Group found"
4362
- msgstr ""
4363
-
4364
  #: public/class-advanced-ads.php:801
4365
  msgid "Edit Ad"
4366
  msgstr ""
2
  # This file is distributed under the GPL-2.0+.
3
  msgid ""
4
  msgstr ""
5
+ "Project-Id-Version: Advanced Ads 1.37.2\n"
6
  "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/advanced-ads/\n"
7
  "Last-Translator: Thomas Maier <post@webzunft.de>\n"
8
  "Language-Team: webgilde <support@wpadvancedads.com>\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "POT-Creation-Date: 2022-11-22T08:44:07+00:00\n"
13
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
14
  "X-Generator: WP-CLI 2.7.1\n"
15
  "X-Domain: advanced-ads\n"
125
  msgid "Thank the developer with a &#9733;&#9733;&#9733;&#9733;&#9733; review on <a href=\"%s\" target=\"_blank\">wordpress.org</a>"
126
  msgstr ""
127
 
128
+ #: admin/class-advanced-ads-admin.php:796
129
+ #: admin/class-advanced-ads-admin.php:802
130
  #: admin/includes/class-menu.php:123
131
  #: admin/views/ad-group-list-ads.php:36
132
  #: public/class-advanced-ads.php:798
134
  msgid "New Ad"
135
  msgstr ""
136
 
137
+ #: admin/class-advanced-ads-admin.php:801
138
  msgid "Your Ads"
139
  msgstr ""
140
 
141
+ #: admin/class-advanced-ads-admin.php:811
142
  msgid "Your Groups"
143
  msgstr ""
144
 
145
+ #: admin/class-advanced-ads-admin.php:812
146
+ #: admin/views/ad-group.php:64
147
  #: public/class-advanced-ads.php:762
148
  msgid "New Ad Group"
149
  msgstr ""
150
 
151
+ #: admin/class-advanced-ads-admin.php:820
152
  msgid "Your Placements"
153
  msgstr ""
154
 
155
+ #: admin/class-advanced-ads-admin.php:821
156
  #: admin/views/placements.php:37
157
  #: admin/views/placements.php:464
158
  msgid "New Placement"
159
  msgstr ""
160
 
161
+ #: admin/class-advanced-ads-admin.php:827
162
  #: admin/includes/class-menu.php:150
163
  msgid "Advanced Ads Settings"
164
  msgstr ""
303
  msgid "Learn how."
304
  msgstr ""
305
 
306
+ #. translators: %s is the group type string
307
+ #: admin/includes/class-ad-groups-list.php:112
308
+ msgid "The originally selected group type “%s” is not enabled."
309
+ msgstr ""
310
+
311
+ #: admin/includes/class-ad-groups-list.php:180
312
  msgid "Ad weight"
313
  msgstr ""
314
 
315
  #. translators: %s is a date.
316
+ #: admin/includes/class-ad-groups-list.php:192
317
  #: admin/views/ad-list/timing.php:21
318
  msgid "starts %s"
319
  msgstr ""
320
 
321
  #. translators: %s is a date.
322
  #. translators: %s is a time and date string.
323
+ #: admin/includes/class-ad-groups-list.php:213
324
  #: admin/views/ad-list/timing.php:59
325
  msgid "expires %s"
326
  msgstr ""
327
 
328
  #. translators: %s is a date.
329
  #. translators: %s is a time and date string.
330
+ #: admin/includes/class-ad-groups-list.php:216
331
  #: admin/views/ad-list/timing.php:70
332
  msgid "<strong>expired</strong> %s"
333
  msgstr ""
334
 
335
  #. translators: %d is a number.
336
+ #: admin/includes/class-ad-groups-list.php:233
337
  msgid "show %d more ads"
338
  msgstr ""
339
 
340
+ #: admin/includes/class-ad-groups-list.php:238
341
  msgid "No ads assigned"
342
  msgstr ""
343
 
344
+ #: admin/includes/class-ad-groups-list.php:240
345
  msgid "Add some"
346
  msgstr ""
347
 
348
  #. translators: amount of ads displayed
349
+ #: admin/includes/class-ad-groups-list.php:268
350
  msgid "Up to %d ad displayed."
351
  msgid_plural "Up to %d ads displayed"
352
  msgstr[0] ""
353
  msgstr[1] ""
354
 
355
+ #: admin/includes/class-ad-groups-list.php:338
356
  msgid "Random ads"
357
  msgstr ""
358
 
359
+ #: admin/includes/class-ad-groups-list.php:339
360
  msgid "Display random ads based on ad weight"
361
  msgstr ""
362
 
363
+ #: admin/includes/class-ad-groups-list.php:343
364
  msgid "Ordered ads"
365
  msgstr ""
366
 
367
+ #: admin/includes/class-ad-groups-list.php:344
368
  msgid "Display ads with the highest ad weight first"
369
  msgstr ""
370
 
371
+ #: admin/includes/class-ad-groups-list.php:379
372
+ #: admin/views/ad-group-list-row.php:42
373
  #: admin/views/placements.php:273
374
  #: modules/import-export/classes/import.php:153
375
  #: modules/import-export/classes/import.php:193
378
  msgid "Edit"
379
  msgstr ""
380
 
381
+ #: admin/includes/class-ad-groups-list.php:380
382
  #: admin/views/placements.php:131
383
  msgid "show usage"
384
  msgstr ""
385
 
386
+ #: admin/includes/class-ad-groups-list.php:389
387
  #: admin/views/placements.php:10
388
  msgid "Delete"
389
  msgstr ""
390
 
391
+ #: admin/includes/class-ad-groups-list.php:411
392
+ #: admin/includes/class-ad-groups-list.php:490
393
  msgid "Invalid Ad Group"
394
  msgstr ""
395
 
396
+ #: admin/includes/class-ad-groups-list.php:416
397
+ #: admin/includes/class-ad-groups-list.php:495
398
  msgid "You don’t have permission to change the ad groups"
399
  msgstr ""
400
 
401
+ #: admin/includes/class-ad-groups-list.php:459
402
  msgid "No ad group created"
403
  msgstr ""
404
 
405
  #: admin/includes/class-ad-type.php:133
406
+ #: admin/views/ad-group-list-form-row.php:58
407
+ #: admin/views/ad-group-list-header.php:13
408
  #: admin/views/placements.php:56
 
409
  #: modules/gadsense/admin/views/adsense-ad-parameters.php:105
410
  msgid "Type"
411
  msgstr ""
412
 
413
  #: admin/includes/class-ad-type.php:138
414
+ #: admin/views/ad-group-list-form-row.php:30
415
+ #: admin/views/ad-group-list-header.php:14
416
  #: admin/views/placements.php:56
417
  #: modules/gadsense/admin/views/external-ads-list.php:38
418
  #: modules/privacy/admin/views/setting-general.php:44
536
  msgstr ""
537
 
538
  #: admin/includes/class-admin-upgrades.php:83
539
+ #: admin/views/group-form.php:27
540
  msgid "Pro Feature"
541
  msgstr ""
542
 
654
  #: admin/includes/class-menu.php:90
655
  #: admin/includes/class-menu.php:91
656
  #: admin/includes/class-shortcode-creator.php:212
657
+ #: admin/views/ad-group-list-form-row.php:93
658
  #: admin/views/ad-group-list-header.php:16
659
  #: admin/views/placement-form.php:61
660
  #: admin/views/placements-item.php:26
709
  msgid "You attempted to edit an ad group that doesn&#8217;t exist. Perhaps it was deleted?"
710
  msgstr ""
711
 
712
+ #: admin/includes/class-menu.php:373
713
+ msgid "Grid"
714
+ msgstr ""
715
+
716
+ #: admin/includes/class-menu.php:381
717
+ msgid "Ad Slider"
718
+ msgstr ""
719
+
720
  #: admin/includes/class-meta-box.php:61
721
  msgid "Ad Type"
722
  msgstr ""
727
  msgstr ""
728
 
729
  #: admin/includes/class-meta-box.php:89
730
+ #: admin/views/ad-group-list-row.php:61
731
  #: admin/views/placements.php:305
732
  msgid "Usage"
733
  msgstr ""
767
  #: admin/includes/class-meta-box.php:231
768
  #: admin/includes/class-meta-box.php:236
769
  #: admin/includes/class-overview-widgets.php:179
770
+ #: admin/views/ad-group.php:59
771
  #: admin/views/ad-main-metabox.php:29
772
  #: admin/views/ad-output-metabox.php:43
773
  #: admin/views/conditions/condition-device.php:22
774
  #: admin/views/conditions/condition-is-or-not.php:21
775
+ #: admin/views/conditions/condition-number.php:23
776
+ #: admin/views/conditions/condition-string.php:9
777
  #: admin/views/header.php:50
778
  #: admin/views/placements.php:28
779
  #: admin/views/settings/general/custom-label.php:10
1299
  msgid "add"
1300
  msgstr ""
1301
 
1302
+ #: admin/views/ad-group-list-form-row.php:74
1303
  msgctxt "option to display all ads in an ad groups"
1304
  msgid "all"
1305
  msgstr ""
1306
 
1307
+ #: admin/views/ad-group-list-form-row.php:81
1308
  msgid "Visible ads"
1309
  msgstr ""
1310
 
1311
+ #: admin/views/ad-group-list-form-row.php:83
1312
  msgid "Number of ads that are visible at the same time"
1313
  msgstr ""
1314
 
 
 
 
 
 
1315
  #: admin/views/ad-group-list-header.php:15
1316
  msgid "Details"
1317
  msgstr ""
1318
 
1319
+ #: admin/views/ad-group-list-row.php:43
1320
+ msgid "Save"
1321
+ msgstr ""
1322
+
1323
+ #: admin/views/ad-group-list-row.php:54
1324
  #: admin/views/placements.php:309
1325
  msgid "shortcode"
1326
  msgstr ""
1327
 
1328
+ #: admin/views/ad-group-list-row.php:56
1329
  #: admin/views/placements.php:312
1330
  msgid "template (PHP)"
1331
  msgstr ""
1332
 
1333
  #. translators: %s is the name of a group type
1334
+ #: admin/views/ad-group-list-row.php:79
1335
  msgid "Type: %s"
1336
  msgstr ""
1337
 
1338
  #. translators: %s is the ID of an ad group
1339
+ #: admin/views/ad-group-list-row.php:87
1340
  msgid "ID: %s"
1341
  msgstr ""
1342
 
1348
  msgid "Ad Groups successfully updated"
1349
  msgstr ""
1350
 
1351
+ #: admin/views/ad-group.php:57
1352
+ msgid "Ad Groups are a very flexible method to bundle ads. You can use them to display random ads in the frontend or run split tests, but also just for informational purposes. Not only can an Ad Groups have multiple ads, but an ad can belong to multiple ad groups."
1353
  msgstr ""
1354
 
1355
+ #: admin/views/ad-group.php:65
1356
+ msgid "Save New Group"
1357
  msgstr ""
1358
 
1359
+ #: admin/views/ad-group.php:104
1360
+ #: public/class-advanced-ads.php:765
1361
+ msgid "No Ad Group found"
 
 
 
1362
  msgstr ""
1363
 
1364
  #: admin/views/ad-info-after-textarea.php:17
1739
  msgid "There is an error in your AdSense setup."
1740
  msgstr ""
1741
 
1742
+ #: admin/views/group-form.php:10
1743
+ msgid "Choose the type"
1744
+ msgstr ""
1745
+
1746
+ #: admin/views/group-form.php:45
1747
+ #: admin/views/placement-form.php:38
1748
+ msgid "Please select a type."
1749
+ msgstr ""
1750
+
1751
+ #: admin/views/group-form.php:47
1752
+ msgid "Choose a name"
1753
+ msgstr ""
1754
+
1755
+ #: admin/views/group-form.php:48
1756
+ msgid "Group title"
1757
+ msgstr ""
1758
+
1759
+ #: admin/views/group-form.php:49
1760
+ #: admin/views/placement-form.php:49
1761
+ msgid "Please enter a name."
1762
+ msgstr ""
1763
+
1764
  #: admin/views/header.php:33
1765
  msgid "Reset"
1766
  msgstr ""
1852
  msgid "Placement types define where the ad is going to be displayed. Learn more about the different types from the <a href=\"%s\">manual</a>"
1853
  msgstr ""
1854
 
 
 
 
 
1855
  #: admin/views/placement-form.php:40
1856
  msgid "Choose a Name"
1857
  msgstr ""
1864
  msgid "The name of the placement is only visible to you. Tip: choose a descriptive one, e.g. Below Post Headline."
1865
  msgstr ""
1866
 
 
 
 
 
1867
  #: admin/views/placement-form.php:50
1868
  msgid "Choose the Ad or Group"
1869
  msgstr ""
2752
  msgid "URL"
2753
  msgstr ""
2754
 
2755
+ #: classes/ad_type_group.php:30
2756
+ msgid "Ad Group"
2757
+ msgstr ""
2758
+
2759
  #: classes/ad_type_group.php:31
2760
  msgid "Choose an existing ad group. Use this type when you want to assign the same display and visitor conditions to all ads in that group."
2761
  msgstr ""
4390
  msgid "New Ad Groups Name"
4391
  msgstr ""
4392
 
 
 
 
 
4393
  #: public/class-advanced-ads.php:801
4394
  msgid "Edit Ad"
4395
  msgstr ""
modules/ad-blocker/admin/admin.php CHANGED
@@ -51,7 +51,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
51
  */
52
  private function __construct() {
53
  // add module settings to Advanced Ads settings page
54
- add_action( 'advanced-ads-settings-init', array( $this, 'settings_init' ), 9, 1 );
55
 
56
  $is_main_site = is_main_site( get_current_blog_id() );
57
  if ( ! $is_main_site ) {
@@ -62,7 +62,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
62
  $this->options = Advanced_Ads_Ad_Blocker::get_instance()->options();
63
  $this->upload_dir = $this->options['upload_dir'];
64
 
65
- add_action( 'admin_init', array( $this, 'process_auto_update' ) );
66
 
67
  $this->error_messages = new WP_Error();
68
  }
@@ -91,7 +91,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
91
  add_settings_field(
92
  'use-adblocker',
93
  __( 'Ad blocker fix', 'advanced-ads' ),
94
- array( $this, 'render_settings_use_adblocker' ),
95
  $hook,
96
  'advanced_ads_adblocker_setting_section'
97
  );
@@ -169,7 +169,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
169
  **/
170
  private function process_form() {
171
  // at this point we do not need ftp/ssh credentials anymore
172
- $form_post_fields = array_intersect_key( $_POST, array( 'advads_ab_assign_new_folder' => false ) );
173
 
174
  $this->create_dummy_plugin( $form_post_fields );
175
 
@@ -190,7 +190,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
190
  * @param array $form_post_fields options, POST data sent by user.
191
  * @return array $new_options - options, that need to be stored in database.
192
  */
193
- public function create_dummy_plugin( $form_post_fields = array() ) {
194
  global $wp_filesystem;
195
 
196
  $need_assign_new_name = isset( $form_post_fields['advads_ab_assign_new_folder'] );
@@ -201,18 +201,18 @@ class Advanced_Ads_Ad_Blocker_Admin {
201
  return false;
202
  }
203
 
204
- $new_options = array(
205
- 'lookup_table' => isset( $this->options['lookup_table'] ) ? $this->options['lookup_table'] : array(),
206
- );
207
  $new_options_error = $new_options;
208
  // $new_options_error does not have the 'module_can_work' key - ad-blocker script will be inactive and the asset folder will be rebuilt next time
209
  $new_options['module_can_work'] = true;
210
 
211
  $existing_files = @scandir( $this->upload_dir['basedir'] );
212
  if ( $existing_files ) {
213
- $existing_files = array_diff( $existing_files, array( '..', '.' ) );
214
  } else {
215
- $existing_files = array();
216
  }
217
 
218
  if ( ! empty( $this->options['folder_name'] ) ) {
@@ -300,7 +300,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
300
  $asset_path_normalized = Advanced_Ads_Filesystem::get_instance()->normalize_path( trailingslashit( $this->upload_dir['basedir'] ) ) . $folder_name;
301
 
302
  // already saved associations (original name => replaced name)
303
- $rand_asset_names = array();
304
 
305
  if ( $need_assign_new_name ) {
306
  // Check if there is a previous asset folder
@@ -331,14 +331,14 @@ class Advanced_Ads_Ad_Blocker_Admin {
331
  // I.e: [advanced-ads-layer/admin/assets/css/admin.css] => array( path => /12/34/56/78/1347107783.css, mtime => 99 ).
332
  $assets = $this->get_assets();
333
  if ( $need_assign_new_name ) {
334
- $lookup_table = array();
335
  } else {
336
- $lookup_table = isset( $this->options['lookup_table'] ) ? $this->options['lookup_table'] : array();
337
  }
338
 
339
  /* Do not rename assets and folders. If, for example, some library uses in file.css something like this:
340
  'background: url(/img/image.png)', you should add 'img') to this array */
341
- $not_rename_assets = array( 'public', 'assets', 'js', 'css', 'fancybox', 'advanced.js', 'jquery.fancybox-1.3.4.css' );
342
 
343
  // Loop through all the found assets
344
  foreach ( $assets as $file => $filemtime ) {
@@ -351,7 +351,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
351
  $first_cleanup_filename = basename( $first_cleanup );
352
  $first_cleanup_file_extension = pathinfo( $first_cleanup, PATHINFO_EXTENSION );
353
  $path_components = preg_split('/\//', $first_cleanup_dir, -1, PREG_SPLIT_NO_EMPTY);
354
- $path_components_new = array();
355
 
356
  // Interate over directories.
357
  foreach ( $path_components as $k => $dir ) {
@@ -408,10 +408,10 @@ class Advanced_Ads_Ad_Blocker_Admin {
408
  return false;
409
  }
410
 
411
- $lookup_table[ $first_cleanup ] = array(
412
  'path' => $new_rel_file,
413
  'mtime' => $filemtime,
414
- );
415
  }
416
 
417
  return $lookup_table;
@@ -424,7 +424,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
424
  * @return Array with pairs: abs_filename => mtime.
425
  */
426
  public function recursive_search_assets( $dir ) {
427
- $assets = array();
428
 
429
  $tree = glob( rtrim( $dir, '/' ) . '/*' );
430
  if ( is_array( $tree ) ) {
@@ -454,7 +454,7 @@ class Advanced_Ads_Ad_Blocker_Admin {
454
  }
455
 
456
  $asset_path = trailingslashit( trailingslashit( $this->upload_dir['basedir'] ) . $this->options['folder_name'] ) ;
457
- $new_files = array();
458
 
459
  foreach ( $new_files_info as $abs_file => $mtime ) {
460
  $rel_file = str_replace( WP_PLUGIN_DIR , '', $abs_file );
51
  */
52
  private function __construct() {
53
  // add module settings to Advanced Ads settings page
54
+ add_action( 'advanced-ads-settings-init', [ $this, 'settings_init' ], 9, 1 );
55
 
56
  $is_main_site = is_main_site( get_current_blog_id() );
57
  if ( ! $is_main_site ) {
62
  $this->options = Advanced_Ads_Ad_Blocker::get_instance()->options();
63
  $this->upload_dir = $this->options['upload_dir'];
64
 
65
+ add_action( 'admin_init', [ $this, 'process_auto_update' ] );
66
 
67
  $this->error_messages = new WP_Error();
68
  }
91
  add_settings_field(
92
  'use-adblocker',
93
  __( 'Ad blocker fix', 'advanced-ads' ),
94
+ [ $this, 'render_settings_use_adblocker' ],
95
  $hook,
96
  'advanced_ads_adblocker_setting_section'
97
  );
169
  **/
170
  private function process_form() {
171
  // at this point we do not need ftp/ssh credentials anymore
172
+ $form_post_fields = array_intersect_key( $_POST, [ 'advads_ab_assign_new_folder' => false ] );
173
 
174
  $this->create_dummy_plugin( $form_post_fields );
175
 
190
  * @param array $form_post_fields options, POST data sent by user.
191
  * @return array $new_options - options, that need to be stored in database.
192
  */
193
+ public function create_dummy_plugin( $form_post_fields = [] ) {
194
  global $wp_filesystem;
195
 
196
  $need_assign_new_name = isset( $form_post_fields['advads_ab_assign_new_folder'] );
201
  return false;
202
  }
203
 
204
+ $new_options = [
205
+ 'lookup_table' => isset( $this->options['lookup_table'] ) ? $this->options['lookup_table'] : [],
206
+ ];
207
  $new_options_error = $new_options;
208
  // $new_options_error does not have the 'module_can_work' key - ad-blocker script will be inactive and the asset folder will be rebuilt next time
209
  $new_options['module_can_work'] = true;
210
 
211
  $existing_files = @scandir( $this->upload_dir['basedir'] );
212
  if ( $existing_files ) {
213
+ $existing_files = array_diff( $existing_files, [ '..', '.' ] );
214
  } else {
215
+ $existing_files = [];
216
  }
217
 
218
  if ( ! empty( $this->options['folder_name'] ) ) {
300
  $asset_path_normalized = Advanced_Ads_Filesystem::get_instance()->normalize_path( trailingslashit( $this->upload_dir['basedir'] ) ) . $folder_name;
301
 
302
  // already saved associations (original name => replaced name)
303
+ $rand_asset_names = [];
304
 
305
  if ( $need_assign_new_name ) {
306
  // Check if there is a previous asset folder
331
  // I.e: [advanced-ads-layer/admin/assets/css/admin.css] => array( path => /12/34/56/78/1347107783.css, mtime => 99 ).
332
  $assets = $this->get_assets();
333
  if ( $need_assign_new_name ) {
334
+ $lookup_table = [];
335
  } else {
336
+ $lookup_table = isset( $this->options['lookup_table'] ) ? $this->options['lookup_table'] : [];
337
  }
338
 
339
  /* Do not rename assets and folders. If, for example, some library uses in file.css something like this:
340
  'background: url(/img/image.png)', you should add 'img') to this array */
341
+ $not_rename_assets = [ 'public', 'assets', 'js', 'css', 'fancybox', 'advanced.js', 'jquery.fancybox-1.3.4.css' ];
342
 
343
  // Loop through all the found assets
344
  foreach ( $assets as $file => $filemtime ) {
351
  $first_cleanup_filename = basename( $first_cleanup );
352
  $first_cleanup_file_extension = pathinfo( $first_cleanup, PATHINFO_EXTENSION );
353
  $path_components = preg_split('/\//', $first_cleanup_dir, -1, PREG_SPLIT_NO_EMPTY);
354
+ $path_components_new = [];
355
 
356
  // Interate over directories.
357
  foreach ( $path_components as $k => $dir ) {
408
  return false;
409
  }
410
 
411
+ $lookup_table[ $first_cleanup ] = [
412
  'path' => $new_rel_file,
413
  'mtime' => $filemtime,
414
+ ];
415
  }
416
 
417
  return $lookup_table;
424
  * @return Array with pairs: abs_filename => mtime.
425
  */
426
  public function recursive_search_assets( $dir ) {
427
+ $assets = [];
428
 
429
  $tree = glob( rtrim( $dir, '/' ) . '/*' );
430
  if ( is_array( $tree ) ) {
454
  }
455
 
456
  $asset_path = trailingslashit( trailingslashit( $this->upload_dir['basedir'] ) . $this->options['folder_name'] ) ;
457
+ $new_files = [];
458
 
459
  foreach ( $new_files_info as $abs_file => $mtime ) {
460
  $rel_file = str_replace( WP_PLUGIN_DIR , '', $abs_file );
modules/ad-blocker/classes/plugin.php CHANGED
@@ -35,7 +35,7 @@ class Advanced_Ads_Ad_Blocker {
35
  $options['upload_dir']
36
  ) {
37
  $this->plugins_url = plugins_url();
38
- add_action( 'wp_enqueue_scripts', array( $this, 'edit_script_output' ), 101 );
39
  }
40
  }
41
 
@@ -116,20 +116,20 @@ class Advanced_Ads_Ad_Blocker {
116
  // Switch to main blog.
117
  switch_to_blog( $current_site->blog_id );
118
 
119
- $this->options = get_option( ADVADS_AB_SLUG, array() );
120
  // Do not init options in the 'Advanced_Ads_Plugin' class.
121
- $advads_options = (array) get_option( ADVADS_SLUG, array() );
122
  $upload_dir = wp_upload_dir();
123
 
124
  restore_current_blog();
125
  } else {
126
- $this->options = get_option( ADVADS_AB_SLUG, array() );
127
  $advads_options = Advanced_Ads::get_instance()->options();
128
  $upload_dir = wp_upload_dir();
129
  }
130
 
131
  if ( ! $this->options ) {
132
- $this->options = array();
133
  }
134
 
135
  $this->options['use-adblocker'] = ! empty( $advads_options['use-adblocker'] );
35
  $options['upload_dir']
36
  ) {
37
  $this->plugins_url = plugins_url();
38
+ add_action( 'wp_enqueue_scripts', [ $this, 'edit_script_output' ], 101 );
39
  }
40
  }
41
 
116
  // Switch to main blog.
117
  switch_to_blog( $current_site->blog_id );
118
 
119
+ $this->options = get_option( ADVADS_AB_SLUG, [] );
120
  // Do not init options in the 'Advanced_Ads_Plugin' class.
121
+ $advads_options = (array) get_option( ADVADS_SLUG, [] );
122
  $upload_dir = wp_upload_dir();
123
 
124
  restore_current_blog();
125
  } else {
126
+ $this->options = get_option( ADVADS_AB_SLUG, [] );
127
  $advads_options = Advanced_Ads::get_instance()->options();
128
  $upload_dir = wp_upload_dir();
129
  }
130
 
131
  if ( ! $this->options ) {
132
+ $this->options = [];
133
  }
134
 
135
  $this->options['use-adblocker'] = ! empty( $advads_options['use-adblocker'] );
modules/ad-blocker/config.php CHANGED
@@ -4,10 +4,10 @@
4
 
5
  $path = dirname( __FILE__ );
6
 
7
- return array(
8
- 'classmap' => array(
9
  'Advanced_Ads_Ad_Blocker' => $path . '/classes/plugin.php',
10
  'Advanced_Ads_Ad_Blocker_Admin' => $path . '/admin/admin.php',
11
- ),
12
  'textdomain' => null,
13
- );
4
 
5
  $path = dirname( __FILE__ );
6
 
7
+ return [
8
+ 'classmap' => [
9
  'Advanced_Ads_Ad_Blocker' => $path . '/classes/plugin.php',
10
  'Advanced_Ads_Ad_Blocker_Admin' => $path . '/admin/admin.php',
11
+ ],
12
  'textdomain' => null,
13
+ ];
modules/ad-positioning/classes/ad-positioning.php CHANGED
@@ -16,16 +16,16 @@ class Advanced_Ads_Ad_Positioning {
16
  *
17
  * @var array
18
  */
19
- private $positioning = array(
20
  'position' => 'none',
21
  'clearfix' => false,
22
- 'margin' => array(
23
  'top' => 0,
24
  'left' => 0,
25
  'bottom' => 0,
26
  'right' => 0,
27
- ),
28
- );
29
 
30
  /**
31
  * Class constructor.
@@ -59,7 +59,7 @@ class Advanced_Ads_Ad_Positioning {
59
  }
60
 
61
  // left, center, right are the old values, if it's none of these we've already migrated.
62
- if ( ! in_array( $this->positioning['position'], array( 'left', 'center', 'right' ), true ) ) {
63
  // ensure we get an array with min two elements.
64
  $position = explode( '_', $this->positioning['position'] . '_' );
65
 
@@ -107,38 +107,38 @@ class Advanced_Ads_Ad_Positioning {
107
  * @return array
108
  */
109
  private function setup_positioning_options() {
110
- return array(
111
- 'default' => array(
112
  'title' => __( "Theme’s Default", 'advanced-ads' ),
113
  'description' => __( 'The ad will behave as predefined by the theme.', 'advanced-ads' ),
114
- 'options' => array(
115
- 'none' => array(),
116
- ),
117
- ),
118
- 'float' => array(
119
  'title' => _x( 'Float', 'Layout options "Text Flow" heading', 'advanced-ads' ),
120
  'description' => __( 'Text will wrap around the ad and its margin.', 'advanced-ads' ),
121
- 'options' => array(
122
- 'left_float' => array(),
123
- 'right_float' => array(),
124
- ),
125
- ),
126
- 'block' => array(
127
  'title' => _x( 'Block', 'Layout options "Text Flow" heading', 'advanced-ads' ),
128
  'description' => __( 'Text will continue after the ad and its margin.', 'advanced-ads' ),
129
- 'options' => array(
130
- 'left_nofloat' => array(
131
  'img' => 'block-lr',
132
- ),
133
- 'center_nofloat' => array(
134
  'img' => 'block-cntr',
135
- ),
136
- 'right_nofloat' => array(
137
  'img' => 'block-lr',
138
- ),
139
- ),
140
- ),
141
- );
142
  }
143
 
144
  /**
@@ -172,20 +172,20 @@ class Advanced_Ads_Ad_Positioning {
172
  */
173
  private function spacing_admin_view() {
174
  $is_centered = explode( '_', $this->positioning['position'] )[0] === 'center';
175
- $spacings = array(
176
- 'top' => array(
177
  'label' => _x( 'Top', 'Ad positioning spacing label', 'advanced-ads' ),
178
- ),
179
- 'right' => array(
180
  'label' => _x( 'Right', 'Ad positioning spacing label', 'advanced-ads' ),
181
- ),
182
- 'bottom' => array(
183
  'label' => _x( 'Bottom', 'Ad positioning spacing label', 'advanced-ads' ),
184
- ),
185
- 'left' => array(
186
  'label' => _x( 'Left', 'Ad positioning spacing label', 'advanced-ads' ),
187
- ),
188
- );
189
  foreach ( $spacings as $direction => $item ) {
190
  $spacings[ $direction ]['value'] = (int) $this->positioning['margin'][ $direction ];
191
  }
16
  *
17
  * @var array
18
  */
19
+ private $positioning = [
20
  'position' => 'none',
21
  'clearfix' => false,
22
+ 'margin' => [
23
  'top' => 0,
24
  'left' => 0,
25
  'bottom' => 0,
26
  'right' => 0,
27
+ ],
28
+ ];
29
 
30
  /**
31
  * Class constructor.
59
  }
60
 
61
  // left, center, right are the old values, if it's none of these we've already migrated.
62
+ if ( ! in_array( $this->positioning['position'], [ 'left', 'center', 'right' ], true ) ) {
63
  // ensure we get an array with min two elements.
64
  $position = explode( '_', $this->positioning['position'] . '_' );
65
 
107
  * @return array
108
  */
109
  private function setup_positioning_options() {
110
+ return [
111
+ 'default' => [
112
  'title' => __( "Theme’s Default", 'advanced-ads' ),
113
  'description' => __( 'The ad will behave as predefined by the theme.', 'advanced-ads' ),
114
+ 'options' => [
115
+ 'none' => [],
116
+ ],
117
+ ],
118
+ 'float' => [
119
  'title' => _x( 'Float', 'Layout options "Text Flow" heading', 'advanced-ads' ),
120
  'description' => __( 'Text will wrap around the ad and its margin.', 'advanced-ads' ),
121
+ 'options' => [
122
+ 'left_float' => [],
123
+ 'right_float' => [],
124
+ ],
125
+ ],
126
+ 'block' => [
127
  'title' => _x( 'Block', 'Layout options "Text Flow" heading', 'advanced-ads' ),
128
  'description' => __( 'Text will continue after the ad and its margin.', 'advanced-ads' ),
129
+ 'options' => [
130
+ 'left_nofloat' => [
131
  'img' => 'block-lr',
132
+ ],
133
+ 'center_nofloat' => [
134
  'img' => 'block-cntr',
135
+ ],
136
+ 'right_nofloat' => [
137
  'img' => 'block-lr',
138
+ ],
139
+ ],
140
+ ],
141
+ ];
142
  }
143
 
144
  /**
172
  */
173
  private function spacing_admin_view() {
174
  $is_centered = explode( '_', $this->positioning['position'] )[0] === 'center';
175
+ $spacings = [
176
+ 'top' => [
177
  'label' => _x( 'Top', 'Ad positioning spacing label', 'advanced-ads' ),
178
+ ],
179
+ 'right' => [
180
  'label' => _x( 'Right', 'Ad positioning spacing label', 'advanced-ads' ),
181
+ ],
182
+ 'bottom' => [
183
  'label' => _x( 'Bottom', 'Ad positioning spacing label', 'advanced-ads' ),
184
+ ],
185
+ 'left' => [
186
  'label' => _x( 'Left', 'Ad positioning spacing label', 'advanced-ads' ),
187
+ ],
188
+ ];
189
  foreach ( $spacings as $direction => $item ) {
190
  $spacings[ $direction ]['value'] = (int) $this->positioning['margin'][ $direction ];
191
  }
modules/ad-positioning/views/ad-spacing.php CHANGED
@@ -25,7 +25,7 @@
25
  class="advads-ad-positioning-spacing-option"
26
  name="advanced_ad[output][margin][<?php echo esc_attr( $direction ); ?>]"
27
  value="<?php echo esc_attr( $spacing['value'] ); ?>"
28
- <?php __checked_selected_helper( $is_centered && ( in_array( $direction, array( 'left', 'right' ), true ) ), true, true, 'readonly' ); ?>
29
  >
30
  </label>
31
 
25
  class="advads-ad-positioning-spacing-option"
26
  name="advanced_ad[output][margin][<?php echo esc_attr( $direction ); ?>]"
27
  value="<?php echo esc_attr( $spacing['value'] ); ?>"
28
+ <?php __checked_selected_helper( $is_centered && ( in_array( $direction, [ 'left', 'right' ], true ) ), true, true, 'readonly' ); ?>
29
  >
30
  </label>
31
 
modules/adblock-finder/admin/admin.php CHANGED
@@ -6,7 +6,7 @@
6
  class Advanced_Ads_Adblock_Finder_Admin {
7
  public function __construct() {
8
  // Add module settings to Advanced Ads settings page.
9
- add_action( 'advanced-ads-settings-init', array( $this, 'settings_init' ), 9, 1 );
10
  }
11
 
12
  /**
@@ -18,14 +18,14 @@ class Advanced_Ads_Adblock_Finder_Admin {
18
  add_settings_section(
19
  'advanced_ads_adblocker_setting_section',
20
  __( 'Ad Blocker', 'advanced-ads' ),
21
- array( $this, 'render_settings_section_callback' ),
22
  $hook
23
  );
24
 
25
  add_settings_field(
26
  'GA-tracking-id',
27
  __( 'Ad blocker counter', 'advanced-ads' ),
28
- array( $this, 'render_settings_ga' ),
29
  $hook,
30
  'advanced_ads_adblocker_setting_section'
31
  );
6
  class Advanced_Ads_Adblock_Finder_Admin {
7
  public function __construct() {
8
  // Add module settings to Advanced Ads settings page.
9
+ add_action( 'advanced-ads-settings-init', [ $this, 'settings_init' ], 9, 1 );
10
  }
11
 
12
  /**
18
  add_settings_section(
19
  'advanced_ads_adblocker_setting_section',
20
  __( 'Ad Blocker', 'advanced-ads' ),
21
+ [ $this, 'render_settings_section_callback' ],
22
  $hook
23
  );
24
 
25
  add_settings_field(
26
  'GA-tracking-id',
27
  __( 'Ad blocker counter', 'advanced-ads' ),
28
+ [ $this, 'render_settings_ga' ],
29
  $hook,
30
  'advanced_ads_adblocker_setting_section'
31
  );
modules/adblock-finder/config.php CHANGED
@@ -4,10 +4,10 @@
4
 
5
  $path = dirname( __FILE__ );
6
 
7
- return array(
8
- 'classmap' => array(
9
  'Advanced_Ads_Adblock_Finder' => $path . '/public/public.php',
10
  'Advanced_Ads_Adblock_Finder_Admin' => $path . '/admin/admin.php',
11
- ),
12
  'textdomain' => null,
13
- );
4
 
5
  $path = dirname( __FILE__ );
6
 
7
+ return [
8
+ 'classmap' => [
9
  'Advanced_Ads_Adblock_Finder' => $path . '/public/public.php',
10
  'Advanced_Ads_Adblock_Finder_Admin' => $path . '/admin/admin.php',
11
+ ],
12
  'textdomain' => null,
13
+ ];
modules/adblock-finder/public/public.php CHANGED
@@ -9,7 +9,7 @@ class Advanced_Ads_Adblock_Finder {
9
  * Advanced_Ads_Adblock_Finder constructor.
10
  */
11
  public function __construct() {
12
- add_action( 'wp_footer', array( $this, 'print_adblock_check_js' ), 9 );
13
  }
14
 
15
  /**
9
  * Advanced_Ads_Adblock_Finder constructor.
10
  */
11
  public function __construct() {
12
+ add_action( 'wp_footer', [ $this, 'print_adblock_check_js' ], 9 );
13
  }
14
 
15
  /**
modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php CHANGED
@@ -26,10 +26,10 @@ class Advanced_Ads_Ads_Txt_Admin {
26
  $this->strategy = $strategy;
27
  $this->public = $public;
28
 
29
- add_filter( 'advanced-ads-sanitize-settings', array( $this, 'toggle' ), 10, 1 );
30
- add_action( 'pre_update_option_advanced-ads-adsense', array( $this, 'update_adsense_option' ), 10, 2 );
31
- add_action( 'advanced-ads-settings-init', array( $this, 'add_settings' ) );
32
- add_action( self::ACTION, array( $this, 'ajax_refresh_notices' ) );
33
  }
34
 
35
 
@@ -103,14 +103,14 @@ class Advanced_Ads_Ads_Txt_Admin {
103
  add_settings_section(
104
  'advanced_ads_ads_txt_setting_section',
105
  'ads.txt',
106
- array( $this, 'render_ads_txt_section_callback' ),
107
  $hook
108
  );
109
 
110
  add_settings_field(
111
  'adsense-ads-txt-enable',
112
  '',
113
- array( $this, 'render_setting_toggle' ),
114
  $hook,
115
  'advanced_ads_ads_txt_setting_section'
116
  );
@@ -118,7 +118,7 @@ class Advanced_Ads_Ads_Txt_Admin {
118
  add_settings_field(
119
  'adsense-ads-txt-content',
120
  '',
121
- array( $this, 'render_setting_additional_content' ),
122
  $hook,
123
  'advanced_ads_ads_txt_setting_section'
124
  );
@@ -174,7 +174,7 @@ class Advanced_Ads_Ads_Txt_Admin {
174
  public function get_notices() {
175
  $url = home_url( '/' );
176
  $parsed_url = wp_parse_url( $url );
177
- $notices = array();
178
 
179
  if ( ! isset( $parsed_url['scheme'] ) || ! isset ( $parsed_url['host'] ) ) {
180
  return $notices;
@@ -188,10 +188,10 @@ class Advanced_Ads_Ads_Txt_Admin {
188
  }
189
 
190
  if ( Advanced_Ads_Ads_Txt_Utils::is_subdir() ) {
191
- $notices[] = array( 'advads-error-message', sprintf(
192
  esc_html__( 'The ads.txt file cannot be placed because the URL contains a subdirectory. You need to make the file available at %s', 'advanced-ads' ),
193
  sprintf( '<a href="%1$s" target="_blank">%1$s</a>', esc_url( $parsed_url['scheme'] . '://' . $parsed_url['host'] ) )
194
- ) );
195
  } else {
196
  if ( null === ( $file = $this->get_notice( 'get_file_info', $url ) ) ) {
197
  $this->notices_are_stale = true;
@@ -200,12 +200,12 @@ class Advanced_Ads_Ads_Txt_Admin {
200
 
201
  if ( ! is_wp_error( $file )) {
202
  if ( $file['exists'] ) {
203
- $notices[] = array( '', sprintf(
204
  esc_html__( 'The file is available on %s.', 'advanced-ads' ),
205
  $link
206
- ) );
207
  } else {
208
- $notices[] = array( '', esc_html__( 'The file was not created.', 'advanced-ads' ) );
209
  }
210
 
211
  if ( $file['is_third_party'] ) {
@@ -217,13 +217,13 @@ class Advanced_Ads_Ads_Txt_Admin {
217
  . __( 'Move the content of the existing ads.txt file into Advanced Ads and remove it.', 'advanced-ads' )
218
  . '</p>';
219
  }
220
- $notices['is_third_party'] = array( 'advads-error-message', $message );
221
  }
222
  } else {
223
- $notices[] = array( 'advads-error-message', sprintf(
224
  esc_html__( 'An error occured: %s.', 'advanced-ads' ),
225
  esc_html( $file->get_error_message() ) )
226
- );
227
  }
228
 
229
 
@@ -233,12 +233,12 @@ class Advanced_Ads_Ads_Txt_Admin {
233
  }
234
 
235
  if ( $need_file_on_root_domain ) {
236
- $notices[] = array( 'advads-ads-txt-nfor', sprintf(
237
  /* translators: %s the line that may need to be added manually */
238
  esc_html__( 'If your site is located on a subdomain, you need to add the following line to the ads.txt file of the root domain: %s', 'advanced-ads' ),
239
  // Without http://.
240
  '<code>subdomain=' . esc_html( $parsed_url['host'] ) . '</code>'
241
- ) );
242
  }
243
  }
244
 
@@ -297,7 +297,7 @@ class Advanced_Ads_Ads_Txt_Admin {
297
  return isset( $transient[ $func ] ) ? $transient[ $func ] : null;
298
  }
299
 
300
- $r = call_user_func( array( 'Advanced_Ads_Ads_Txt_Utils', $func ), $url );
301
 
302
  $transient[ $func ] = $r;
303
  set_transient( $key, $transient, WEEK_IN_SECONDS );
@@ -321,12 +321,12 @@ class Advanced_Ads_Ads_Txt_Admin {
321
  return '';
322
  }
323
 
324
- $data = array(
325
  'domain' => 'google.com',
326
  'account_id' => $adsense_id,
327
  'account_type' => 'DIRECT',
328
  'certification_authority' => 'f08c47fec0942fa0'
329
- );
330
  $result = implode( ', ', $data );
331
 
332
  return $result;
@@ -343,15 +343,15 @@ class Advanced_Ads_Ads_Txt_Admin {
343
  return;
344
  }
345
 
346
- $response = array();
347
- $action_notices = array();
348
  if ( isset( $_REQUEST['type'] ) ) {
349
  if ( 'remove_real_file' === $_REQUEST['type'] ) {
350
  $remove = $this->remove_real_file();
351
  if ( is_wp_error( $remove ) ) {
352
- $action_notices[] = array( 'advads-ads-txt-updated advads-notice-inline advads-error', $remove->get_error_message() );
353
  } else {
354
- $action_notices[] = array( 'advads-ads-txt-updated', __( 'The ads.txt is now managed with Advanced Ads.', 'advanced-ads' ) );
355
  $options = $this->strategy->get_options();
356
  $response['additional_content'] = esc_textarea( $options['custom'] );
357
  }
@@ -375,7 +375,7 @@ class Advanced_Ads_Ads_Txt_Admin {
375
  */
376
  private function fs_connect() {
377
  global $wp_filesystem;
378
- $fs_connect = Advanced_Ads_Filesystem::get_instance()->fs_connect( array( ABSPATH ) );
379
 
380
  if ( false === $fs_connect || is_wp_error( $fs_connect ) ) {
381
  $message = __( 'Unable to connect to the filesystem. Please confirm your credentials.', 'advanced-ads' );
26
  $this->strategy = $strategy;
27
  $this->public = $public;
28
 
29
+ add_filter( 'advanced-ads-sanitize-settings', [ $this, 'toggle' ], 10, 1 );
30
+ add_action( 'pre_update_option_advanced-ads-adsense', [ $this, 'update_adsense_option' ], 10, 2 );
31
+ add_action( 'advanced-ads-settings-init', [ $this, 'add_settings' ] );
32
+ add_action( self::ACTION, [ $this, 'ajax_refresh_notices' ] );
33
  }
34
 
35
 
103
  add_settings_section(
104
  'advanced_ads_ads_txt_setting_section',
105
  'ads.txt',
106
+ [ $this, 'render_ads_txt_section_callback' ],
107
  $hook
108
  );
109
 
110
  add_settings_field(
111
  'adsense-ads-txt-enable',
112
  '',
113
+ [ $this, 'render_setting_toggle' ],
114
  $hook,
115
  'advanced_ads_ads_txt_setting_section'
116
  );
118
  add_settings_field(
119
  'adsense-ads-txt-content',
120
  '',
121
+ [ $this, 'render_setting_additional_content' ],
122
  $hook,
123
  'advanced_ads_ads_txt_setting_section'
124
  );
174
  public function get_notices() {
175
  $url = home_url( '/' );
176
  $parsed_url = wp_parse_url( $url );
177
+ $notices = [];
178
 
179
  if ( ! isset( $parsed_url['scheme'] ) || ! isset ( $parsed_url['host'] ) ) {
180
  return $notices;
188
  }
189
 
190
  if ( Advanced_Ads_Ads_Txt_Utils::is_subdir() ) {
191
+ $notices[] = [ 'advads-error-message', sprintf(
192
  esc_html__( 'The ads.txt file cannot be placed because the URL contains a subdirectory. You need to make the file available at %s', 'advanced-ads' ),
193
  sprintf( '<a href="%1$s" target="_blank">%1$s</a>', esc_url( $parsed_url['scheme'] . '://' . $parsed_url['host'] ) )
194
+ ) ];
195
  } else {
196
  if ( null === ( $file = $this->get_notice( 'get_file_info', $url ) ) ) {
197
  $this->notices_are_stale = true;
200
 
201
  if ( ! is_wp_error( $file )) {
202
  if ( $file['exists'] ) {
203
+ $notices[] = [ '', sprintf(
204
  esc_html__( 'The file is available on %s.', 'advanced-ads' ),
205
  $link
206
+ ) ];
207
  } else {
208
+ $notices[] = [ '', esc_html__( 'The file was not created.', 'advanced-ads' ) ];
209
  }
210
 
211
  if ( $file['is_third_party'] ) {
217
  . __( 'Move the content of the existing ads.txt file into Advanced Ads and remove it.', 'advanced-ads' )
218
  . '</p>';
219
  }
220
+ $notices['is_third_party'] = [ 'advads-error-message', $message ];
221
  }
222
  } else {
223
+ $notices[] = [ 'advads-error-message', sprintf(
224
  esc_html__( 'An error occured: %s.', 'advanced-ads' ),
225
  esc_html( $file->get_error_message() ) )
226
+ ];
227
  }
228
 
229
 
233
  }
234
 
235
  if ( $need_file_on_root_domain ) {
236
+ $notices[] = [ 'advads-ads-txt-nfor', sprintf(
237
  /* translators: %s the line that may need to be added manually */
238
  esc_html__( 'If your site is located on a subdomain, you need to add the following line to the ads.txt file of the root domain: %s', 'advanced-ads' ),
239
  // Without http://.
240
  '<code>subdomain=' . esc_html( $parsed_url['host'] ) . '</code>'
241
+ ) ];
242
  }
243
  }
244
 
297
  return isset( $transient[ $func ] ) ? $transient[ $func ] : null;
298
  }
299
 
300
+ $r = call_user_func( [ 'Advanced_Ads_Ads_Txt_Utils', $func ], $url );
301
 
302
  $transient[ $func ] = $r;
303
  set_transient( $key, $transient, WEEK_IN_SECONDS );
321
  return '';
322
  }
323
 
324
+ $data = [
325
  'domain' => 'google.com',
326
  'account_id' => $adsense_id,
327
  'account_type' => 'DIRECT',
328
  'certification_authority' => 'f08c47fec0942fa0'
329
+ ];
330
  $result = implode( ', ', $data );
331
 
332
  return $result;
343
  return;
344
  }
345
 
346
+ $response = [];
347
+ $action_notices = [];
348
  if ( isset( $_REQUEST['type'] ) ) {
349
  if ( 'remove_real_file' === $_REQUEST['type'] ) {
350
  $remove = $this->remove_real_file();
351
  if ( is_wp_error( $remove ) ) {
352
+ $action_notices[] = [ 'advads-ads-txt-updated advads-notice-inline advads-error', $remove->get_error_message() ];
353
  } else {
354
+ $action_notices[] = [ 'advads-ads-txt-updated', __( 'The ads.txt is now managed with Advanced Ads.', 'advanced-ads' ) ];
355
  $options = $this->strategy->get_options();
356
  $response['additional_content'] = esc_textarea( $options['custom'] );
357
  }
375
  */
376
  private function fs_connect() {
377
  global $wp_filesystem;
378
+ $fs_connect = Advanced_Ads_Filesystem::get_instance()->fs_connect( [ ABSPATH ] );
379
 
380
  if ( false === $fs_connect || is_wp_error( $fs_connect ) ) {
381
  $message = __( 'Unable to connect to the filesystem. Please confirm your credentials.', 'advanced-ads' );
modules/ads-txt/admin/views/setting-additional-content.php CHANGED
@@ -8,10 +8,10 @@
8
  __( 'The following line will be added automatically because you connected your AdSense account with Advanced Ads: %s', 'advanced-ads' ),
9
  '<br><code>' . $adsense_line . '</code>'
10
  ),
11
- array(
12
- 'br' => array(),
13
- 'code' => array(),
14
- )
15
  );
16
  ?>
17
  </p>
8
  __( 'The following line will be added automatically because you connected your AdSense account with Advanced Ads: %s', 'advanced-ads' ),
9
  '<br><code>' . $adsense_line . '</code>'
10
  ),
11
+ [
12
+ 'br' => [],
13
+ 'code' => [],
14
+ ]
15
  );
16
  ?>
17
  </p>
modules/ads-txt/config.php CHANGED
@@ -5,13 +5,13 @@
5
 
6
  $path = dirname( __FILE__ );
7
 
8
- return array(
9
- 'classmap' => array(
10
  'Advanced_Ads_Ads_Txt_Public' => $path . '/public/class-advanced-ads-ads-txt-public.php',
11
  'Advanced_Ads_Ads_Txt_Strategy' => $path . '/includes/class-advanced-ads-ads-txt-strategy.php',
12
  'Advanced_Ads_Ads_Txt_Admin' => $path . '/admin/class-advanced-ads-ads-txt-admin.php',
13
  'Advanced_Ads_Ads_Txt_Utils' => $path . '/includes/class-advanced-ads-ads-txt-utils.php',
14
  'Advanced_Ads_Ads_Txt_Real_File'=> $path . '/includes/class-advanced-ads-ads-txt-real-file.php',
15
- ),
16
  'textdomain' => null,
17
- );
5
 
6
  $path = dirname( __FILE__ );
7
 
8
+ return [
9
+ 'classmap' => [
10
  'Advanced_Ads_Ads_Txt_Public' => $path . '/public/class-advanced-ads-ads-txt-public.php',
11
  'Advanced_Ads_Ads_Txt_Strategy' => $path . '/includes/class-advanced-ads-ads-txt-strategy.php',
12
  'Advanced_Ads_Ads_Txt_Admin' => $path . '/admin/class-advanced-ads-ads-txt-admin.php',
13
  'Advanced_Ads_Ads_Txt_Utils' => $path . '/includes/class-advanced-ads-ads-txt-utils.php',
14
  'Advanced_Ads_Ads_Txt_Real_File'=> $path . '/includes/class-advanced-ads-ads-txt-real-file.php',
15
+ ],
16
  'textdomain' => null,
17
+ ];
modules/ads-txt/includes/class-advanced-ads-ads-txt-real-file.php CHANGED
@@ -3,7 +3,7 @@
3
  * Represents a real ads.txt file.
4
  */
5
  class Advanced_Ads_Ads_Txt_Real_File {
6
- private $records = array();
7
 
8
  /**
9
  * Parse a real file.
@@ -12,7 +12,7 @@ class Advanced_Ads_Ads_Txt_Real_File {
12
  */
13
  public function parse_file( $file ) {
14
  $lines = preg_split( '/\r\n|\r|\n/', $file );
15
- $comments = array();
16
 
17
  foreach ( $lines as $line ) {
18
  $line = explode( '#', $line );
@@ -26,7 +26,7 @@ class Advanced_Ads_Ads_Txt_Real_File {
26
  }
27
 
28
  $rec = explode( ',', $line[0] );
29
- $data = array();
30
 
31
  foreach ( $rec as $k => $r ) {
32
  $r = trim( $r, " \n\r\t," );
@@ -40,7 +40,7 @@ class Advanced_Ads_Ads_Txt_Real_File {
40
  $this->add_record( implode( ', ', $data ), $comments );
41
  }
42
 
43
- $comments = array();
44
  }
45
  }
46
 
@@ -50,8 +50,8 @@ class Advanced_Ads_Ads_Txt_Real_File {
50
  * @string $data Record without comments.
51
  * @array $comments Comments related to the record.
52
  */
53
- private function add_record( $data, $comments = array() ) {
54
- $this->records[] = array( $data, $comments );
55
  }
56
 
57
  /**
3
  * Represents a real ads.txt file.
4
  */
5
  class Advanced_Ads_Ads_Txt_Real_File {
6
+ private $records = [];
7
 
8
  /**
9
  * Parse a real file.
12
  */
13
  public function parse_file( $file ) {
14
  $lines = preg_split( '/\r\n|\r|\n/', $file );
15
+ $comments = [];
16
 
17
  foreach ( $lines as $line ) {
18
  $line = explode( '#', $line );
26
  }
27
 
28
  $rec = explode( ',', $line[0] );
29
+ $data = [];
30
 
31
  foreach ( $rec as $k => $r ) {
32
  $r = trim( $r, " \n\r\t," );
40
  $this->add_record( implode( ', ', $data ), $comments );
41
  }
42
 
43
+ $comments = [];
44
  }
45
  }
46
 
50
  * @string $data Record without comments.
51
  * @array $comments Comments related to the record.
52
  */
53
+ private function add_record( $data, $comments = [] ) {
54
+ $this->records[] = [ $data, $comments ];
55
  }
56
 
57
  /**
modules/ads-txt/includes/class-advanced-ads-ads-txt-strategy.php CHANGED
@@ -146,9 +146,9 @@ class Advanced_Ads_Ads_Txt_Strategy {
146
 
147
  $blog_id = get_current_blog_id();
148
  $tmp_options = Advanced_Ads_Ads_Txt_Utils::remove_duplicate_lines(
149
- array(
150
  $blog_id => $this->options,
151
- )
152
  );
153
  $this->options = $tmp_options[ $blog_id ];
154
 
@@ -183,10 +183,10 @@ class Advanced_Ads_Ads_Txt_Strategy {
183
  if ( is_multisite() ) {
184
  $options = get_site_meta( get_current_blog_id(), self::OPTION, true );
185
  } else {
186
- $options = get_option( self::OPTION, array() );
187
  }
188
  if ( ! is_array( $options ) ) {
189
- $options = array();
190
  }
191
  $this->options = $this->load_default_options( $options );
192
 
@@ -211,7 +211,7 @@ class Advanced_Ads_Ads_Txt_Strategy {
211
  $options['custom'] = '';
212
  }
213
  if ( ! isset( $options['networks'] ) || ! is_array( $options['networks'] ) ) {
214
- $options['networks'] = array();
215
  }
216
 
217
  return $options;
146
 
147
  $blog_id = get_current_blog_id();
148
  $tmp_options = Advanced_Ads_Ads_Txt_Utils::remove_duplicate_lines(
149
+ [
150
  $blog_id => $this->options,
151
+ ]
152
  );
153
  $this->options = $tmp_options[ $blog_id ];
154
 
183
  if ( is_multisite() ) {
184
  $options = get_site_meta( get_current_blog_id(), self::OPTION, true );
185
  } else {
186
+ $options = get_option( self::OPTION, [] );
187
  }
188
  if ( ! is_array( $options ) ) {
189
+ $options = [];
190
  }
191
  $this->options = $this->load_default_options( $options );
192
 
211
  $options['custom'] = '';
212
  }
213
  if ( ! isset( $options['networks'] ) || ! is_array( $options['networks'] ) ) {
214
+ $options['networks'] = [];
215
  }
216
 
217
  return $options;
modules/ads-txt/includes/class-advanced-ads-ads-txt-utils.php CHANGED
@@ -20,13 +20,13 @@ class Advanced_Ads_Ads_Txt_Utils {
20
  $sslverify = apply_filters( 'https_local_ssl_verify', false );
21
  $response = wp_remote_get(
22
  trailingslashit( $url ) . 'ads.txt',
23
- array(
24
  'timeout' => 3,
25
  'sslverify' => $sslverify,
26
- 'headers' => array(
27
  'Cache-Control' => 'no-cache',
28
- ),
29
- )
30
  );
31
  $code = wp_remote_retrieve_response_code( $response );
32
  $content = wp_remote_retrieve_body( $response );
@@ -41,10 +41,10 @@ class Advanced_Ads_Ads_Txt_Utils {
41
  && ( false !== stripos( $content_type, 'text/plain' ) );
42
  $header_exists = false !== strpos( $content, Advanced_Ads_Ads_Txt_Public::TOP );
43
 
44
- $r = array(
45
  'exists' => $file_exists && $header_exists,
46
  'is_third_party' => $file_exists && ! $header_exists
47
- );
48
 
49
  return $r;
50
  }
@@ -79,14 +79,14 @@ class Advanced_Ads_Ads_Txt_Utils {
79
 
80
  if ( 3 === $count ) {
81
  // Example: `http://one.{net/org/gov/edu/co}.two`.
82
- $suffixes = array( 'net', 'org', 'gov', 'edu', 'co' );
83
  if ( in_array( $host_parts[ $count - 2 ], $suffixes, true ) ) {
84
  return false;
85
  }
86
 
87
  // Example: `one.com.au'.
88
  $suffix_and_tld = implode( '.', array_slice( $host_parts, 1 ) );
89
- if ( in_array( $suffix_and_tld, array( 'com.au', 'com.br', 'com.pl' ) ) ) {
90
  return false;
91
  }
92
 
@@ -98,9 +98,9 @@ class Advanced_Ads_Ads_Txt_Utils {
98
  */
99
  $no_www_url = $parsed_url['scheme'] . '://' . trailingslashit( $host_parts[1] . '.' . $host_parts[2] );
100
 
101
- add_action( 'requests-requests.before_redirect', array( __CLASS__, 'collect_locations' ) );
102
- wp_remote_get( $no_www_url, array( 'timeout' => 5, 'redirection' => 3 ) );
103
- remove_action( 'requests-requests.before_redirect', array( __CLASS__, 'collect_locations' ) );
104
 
105
  $no_www_url_parsed = wp_parse_url( self::$location );
106
  if ( isset( $no_www_url_parsed['host'] ) && $no_www_url_parsed['host'] === $host ) {
@@ -147,10 +147,10 @@ class Advanced_Ads_Ads_Txt_Utils {
147
  * }
148
  * @return array $blog_data Array of arrays of blog options, keyed by by blog IDs.
149
  */
150
- public static function remove_duplicate_lines( $blog_data, $options = array() ) {
151
  $to_comments = ! empty( $options['to_comments'] );
152
 
153
- $added_records = array();
154
  foreach ( $blog_data as $blog_id => &$blog_options ) {
155
  foreach ( $blog_options['networks'] as $id => $data ) {
156
  // Convert to comments or remove duplicate records that are not comments.
20
  $sslverify = apply_filters( 'https_local_ssl_verify', false );
21
  $response = wp_remote_get(
22
  trailingslashit( $url ) . 'ads.txt',
23
+ [
24
  'timeout' => 3,
25
  'sslverify' => $sslverify,
26
+ 'headers' => [
27
  'Cache-Control' => 'no-cache',
28
+ ],
29
+ ]
30
  );
31
  $code = wp_remote_retrieve_response_code( $response );
32
  $content = wp_remote_retrieve_body( $response );
41
  && ( false !== stripos( $content_type, 'text/plain' ) );
42
  $header_exists = false !== strpos( $content, Advanced_Ads_Ads_Txt_Public::TOP );
43
 
44
+ $r = [
45
  'exists' => $file_exists && $header_exists,
46
  'is_third_party' => $file_exists && ! $header_exists
47
+ ];
48
 
49
  return $r;
50
  }
79
 
80
  if ( 3 === $count ) {
81
  // Example: `http://one.{net/org/gov/edu/co}.two`.
82
+ $suffixes = [ 'net', 'org', 'gov', 'edu', 'co' ];
83
  if ( in_array( $host_parts[ $count - 2 ], $suffixes, true ) ) {
84
  return false;
85
  }
86
 
87
  // Example: `one.com.au'.
88
  $suffix_and_tld = implode( '.', array_slice( $host_parts, 1 ) );
89
+ if ( in_array( $suffix_and_tld, [ 'com.au', 'com.br', 'com.pl' ] ) ) {
90
  return false;
91
  }
92
 
98
  */
99
  $no_www_url = $parsed_url['scheme'] . '://' . trailingslashit( $host_parts[1] . '.' . $host_parts[2] );
100
 
101
+ add_action( 'requests-requests.before_redirect', [ __CLASS__, 'collect_locations' ] );
102
+ wp_remote_get( $no_www_url, [ 'timeout' => 5, 'redirection' => 3 ] );
103
+ remove_action( 'requests-requests.before_redirect', [ __CLASS__, 'collect_locations' ] );
104
 
105
  $no_www_url_parsed = wp_parse_url( self::$location );
106
  if ( isset( $no_www_url_parsed['host'] ) && $no_www_url_parsed['host'] === $host ) {
147
  * }
148
  * @return array $blog_data Array of arrays of blog options, keyed by by blog IDs.
149
  */
150
+ public static function remove_duplicate_lines( $blog_data, $options = [] ) {
151
  $to_comments = ! empty( $options['to_comments'] );
152
 
153
+ $added_records = [];
154
  foreach ( $blog_data as $blog_id => &$blog_options ) {
155
  foreach ( $blog_options['networks'] as $id => $data ) {
156
  // Convert to comments or remove duplicate records that are not comments.
modules/ads-txt/public/class-advanced-ads-ads-txt-public.php CHANGED
@@ -10,7 +10,7 @@ class Advanced_Ads_Ads_Txt_Public {
10
  */
11
  public function __construct( $strategy ) {
12
  $this->strategy = $strategy;
13
- add_action( 'init', array( $this, 'display' ) );
14
  }
15
 
16
  /**
@@ -80,16 +80,16 @@ class Advanced_Ads_Ads_Txt_Public {
80
  $need_file_on_root_domain = Advanced_Ads_Ads_Txt_Utils::need_file_on_root_domain();
81
 
82
  // Get all sites that include the current domain as part of their domains.
83
- $sites = get_sites( array(
84
  'search' => $domain,
85
- 'search_columns' => array( 'domain' ),
86
  'meta_key' => Advanced_Ads_Ads_Txt_Strategy::OPTION,
87
- ) );
88
 
89
  // Uses `subdomain=` variable.
90
- $referrals = array();
91
  // Included to the ads.txt file of the current domain.
92
- $not_refferals = array();
93
 
94
  foreach ( $sites as $site ) {
95
  if ( (int) $site->blog_id === get_current_blog_id() ) {
@@ -122,7 +122,7 @@ class Advanced_Ads_Ads_Txt_Public {
122
  join( ',', array_map( 'intval', $not_refferals ) )
123
  ) );
124
 
125
- $blog_data = array();
126
  foreach ( $results as $result ) {
127
  $blog_id = $result->blog_id;
128
 
@@ -132,7 +132,7 @@ class Advanced_Ads_Ads_Txt_Public {
132
  $blog_data[ $blog_id ] = $options;
133
  }
134
 
135
- $blog_data = Advanced_Ads_Ads_Txt_Utils::remove_duplicate_lines( $blog_data, array( 'to_comments' => true ) );
136
 
137
  foreach ( $blog_data as $blog_id => $blog_lines ) {
138
 
10
  */
11
  public function __construct( $strategy ) {
12
  $this->strategy = $strategy;
13
+ add_action( 'init', [ $this, 'display' ] );
14
  }
15
 
16
  /**
80
  $need_file_on_root_domain = Advanced_Ads_Ads_Txt_Utils::need_file_on_root_domain();
81
 
82
  // Get all sites that include the current domain as part of their domains.
83
+ $sites = get_sites( [
84
  'search' => $domain,
85
+ 'search_columns' => [ 'domain' ],
86
  'meta_key' => Advanced_Ads_Ads_Txt_Strategy::OPTION,
87
+ ] );
88
 
89
  // Uses `subdomain=` variable.
90
+ $referrals = [];
91
  // Included to the ads.txt file of the current domain.
92
+ $not_refferals = [];
93
 
94
  foreach ( $sites as $site ) {
95
  if ( (int) $site->blog_id === get_current_blog_id() ) {
122
  join( ',', array_map( 'intval', $not_refferals ) )
123
  ) );
124
 
125
+ $blog_data = [];
126
  foreach ( $results as $result ) {
127
  $blog_id = $result->blog_id;
128
 
132
  $blog_data[ $blog_id ] = $options;
133
  }
134
 
135
+ $blog_data = Advanced_Ads_Ads_Txt_Utils::remove_duplicate_lines( $blog_data, [ 'to_comments' => true ] );
136
 
137
  foreach ( $blog_data as $blog_id => $blog_lines ) {
138
 
modules/gadsense/admin/admin.php CHANGED
@@ -50,10 +50,10 @@ class Advanced_Ads_AdSense_Admin {
50
  private function __construct() {
51
  $this->data = Advanced_Ads_AdSense_Data::get_instance();
52
 
53
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
54
- add_action( 'admin_print_scripts', array( $this, 'print_scripts' ) );
55
- add_filter( 'advanced-ads-ad-notices', array( $this, 'ad_notices' ), 10, 3 );
56
- add_filter( 'advanced-ads-ad-settings-pre-save', array( $this, 'pre_save_post' ) );
57
  }
58
 
59
  /**
@@ -70,14 +70,14 @@ class Advanced_Ads_AdSense_Admin {
70
 
71
  // Remove ad size options for responsive AdSense ads.
72
  $content = json_decode( str_replace( "\n", '', wp_unslash( $advanced_ad['content'] ) ), true );
73
- if ( in_array( $content['unitType'], array(
74
  'responsive',
75
  'link',
76
  'link-responsive',
77
  'matched-content',
78
  'in-article',
79
  'in-feed',
80
- ), true )
81
  ) {
82
  $advanced_ad['width'] = '';
83
  $advanced_ad['height'] = '';
@@ -124,7 +124,7 @@ class Advanced_Ads_AdSense_Admin {
124
  ( 'post-new.php' === $pagenow && Advanced_Ads::POST_TYPE_SLUG === $post_type ) ||
125
  ( 'post.php' === $pagenow && Advanced_Ads::POST_TYPE_SLUG === $post_type && isset( $_GET['action'] ) && 'edit' === $_GET['action'] )
126
  ) {
127
- $scripts = array();
128
 
129
  // Allow modifications of script files to enqueue.
130
  $scripts = apply_filters( 'advanced-ads-gadsense-ad-param-script', $scripts );
@@ -143,7 +143,7 @@ class Advanced_Ads_AdSense_Admin {
143
  }
144
  }
145
 
146
- $styles = array();
147
 
148
  // Allow modifications of default style files to enqueue.
149
  $styles = apply_filters( 'advanced-ads-gadsense-ad-param-style', $styles );
@@ -191,17 +191,17 @@ class Advanced_Ads_AdSense_Admin {
191
  case 'ad-parameters-box':
192
  // Add warning if this is a responsive ad unit without custom sizes and position is set to left or right.
193
  // Hidden by default and made visible with JS.
194
- $notices[] = array(
195
  'text' => sprintf(
196
  // Translators: %s is a URL.
197
  __( 'Responsive AdSense ads don’t work reliably with <em>Position</em> set to left or right. Either switch the <em>Type</em> to "normal" or follow <a href="%s" target="_blank">this tutorial</a> if you want the ad to be wrapped in text.', 'advanced-ads' ),
198
  ADVADS_URL . 'adsense-responsive-custom-sizes/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-custom-sizes-tutorial'
199
  ),
200
  'class' => 'advads-ad-notice-responsive-position advads-notice-inline advads-error hidden',
201
- );
202
  // Show hint about AdSense In-feed add-on.
203
  if ( ! class_exists( 'Advanced_Ads_In_Feed', false ) && ! class_exists( 'Advanced_Ads_Pro_Admin', false ) ) {
204
- $notices[] = array(
205
  'text' => sprintf(
206
  // Translators: %s is a URL.
207
  __( '<a href="%s" target="_blank">Install the free AdSense In-feed add-on</a> in order to place ads between posts.', 'advanced-ads' ),
@@ -211,7 +211,7 @@ class Advanced_Ads_AdSense_Admin {
211
  )
212
  ),
213
  'class' => 'advads-ad-notice-in-feed-add-on advads-notice-inline advads-idea hidden',
214
- );
215
  }
216
  break;
217
  }
@@ -224,10 +224,10 @@ class Advanced_Ads_AdSense_Admin {
224
  */
225
  public static function enqueue_connect_adsense() {
226
  if ( ! wp_script_is( 'advads/connect-adsense', 'registered' ) ) {
227
- wp_enqueue_script( 'advads/connect-adsense', GADSENSE_BASE_URL . 'admin/assets/js/connect-adsense.js', array( 'jquery' ), ADVADS_VERSION );
228
  }
229
- if ( ! has_action( 'admin_footer', array( 'Advanced_Ads_AdSense_Admin', 'print_connect_adsense' ) ) ) {
230
- add_action( 'admin_footer', array( 'Advanced_Ads_AdSense_Admin', 'print_connect_adsense' ) );
231
  }
232
  }
233
 
@@ -242,7 +242,7 @@ class Advanced_Ads_AdSense_Admin {
242
  * Get Auto Ads messages.
243
  */
244
  public static function get_auto_ads_messages() {
245
- return array(
246
  'enabled' => sprintf(
247
  // Translators: %s is a URL.
248
  __( 'The AdSense verification and Auto ads code is already activated in the <a href="%s">AdSense settings</a>.', 'advanced-ads' ),
@@ -258,7 +258,7 @@ class Advanced_Ads_AdSense_Admin {
258
  ),
259
  esc_attr__( 'Activate', 'advanced-ads' )
260
  ),
261
- );
262
  }
263
 
264
  /**
50
  private function __construct() {
51
  $this->data = Advanced_Ads_AdSense_Data::get_instance();
52
 
53
+ add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
54
+ add_action( 'admin_print_scripts', [ $this, 'print_scripts' ] );
55
+ add_filter( 'advanced-ads-ad-notices', [ $this, 'ad_notices' ], 10, 3 );
56
+ add_filter( 'advanced-ads-ad-settings-pre-save', [ $this, 'pre_save_post' ] );
57
  }
58
 
59
  /**
70
 
71
  // Remove ad size options for responsive AdSense ads.
72
  $content = json_decode( str_replace( "\n", '', wp_unslash( $advanced_ad['content'] ) ), true );
73
+ if ( in_array( $content['unitType'], [
74
  'responsive',
75
  'link',
76
  'link-responsive',
77
  'matched-content',
78
  'in-article',
79
  'in-feed',
80
+ ], true )
81
  ) {
82
  $advanced_ad['width'] = '';
83
  $advanced_ad['height'] = '';
124
  ( 'post-new.php' === $pagenow && Advanced_Ads::POST_TYPE_SLUG === $post_type ) ||
125
  ( 'post.php' === $pagenow && Advanced_Ads::POST_TYPE_SLUG === $post_type && isset( $_GET['action'] ) && 'edit' === $_GET['action'] )
126
  ) {
127
+ $scripts = [];
128
 
129
  // Allow modifications of script files to enqueue.
130
  $scripts = apply_filters( 'advanced-ads-gadsense-ad-param-script', $scripts );
143
  }
144
  }
145
 
146
+ $styles = [];
147
 
148
  // Allow modifications of default style files to enqueue.
149
  $styles = apply_filters( 'advanced-ads-gadsense-ad-param-style', $styles );
191
  case 'ad-parameters-box':
192
  // Add warning if this is a responsive ad unit without custom sizes and position is set to left or right.
193
  // Hidden by default and made visible with JS.
194
+ $notices[] = [
195
  'text' => sprintf(
196
  // Translators: %s is a URL.
197
  __( 'Responsive AdSense ads don’t work reliably with <em>Position</em> set to left or right. Either switch the <em>Type</em> to "normal" or follow <a href="%s" target="_blank">this tutorial</a> if you want the ad to be wrapped in text.', 'advanced-ads' ),
198
  ADVADS_URL . 'adsense-responsive-custom-sizes/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-custom-sizes-tutorial'
199
  ),
200
  'class' => 'advads-ad-notice-responsive-position advads-notice-inline advads-error hidden',
201
+ ];
202
  // Show hint about AdSense In-feed add-on.
203
  if ( ! class_exists( 'Advanced_Ads_In_Feed', false ) && ! class_exists( 'Advanced_Ads_Pro_Admin', false ) ) {
204
+ $notices[] = [
205
  'text' => sprintf(
206
  // Translators: %s is a URL.
207
  __( '<a href="%s" target="_blank">Install the free AdSense In-feed add-on</a> in order to place ads between posts.', 'advanced-ads' ),
211
  )
212
  ),
213
  'class' => 'advads-ad-notice-in-feed-add-on advads-notice-inline advads-idea hidden',
214
+ ];
215
  }
216
  break;
217
  }
224
  */
225
  public static function enqueue_connect_adsense() {
226
  if ( ! wp_script_is( 'advads/connect-adsense', 'registered' ) ) {
227
+ wp_enqueue_script( 'advads/connect-adsense', GADSENSE_BASE_URL . 'admin/assets/js/connect-adsense.js', [ 'jquery' ], ADVADS_VERSION );
228
  }
229
+ if ( ! has_action( 'admin_footer', [ 'Advanced_Ads_AdSense_Admin', 'print_connect_adsense' ] ) ) {
230
+ add_action( 'admin_footer', [ 'Advanced_Ads_AdSense_Admin', 'print_connect_adsense' ] );
231
  }
232
  }
233
 
242
  * Get Auto Ads messages.
243
  */
244
  public static function get_auto_ads_messages() {
245
+ return [
246
  'enabled' => sprintf(
247
  // Translators: %s is a URL.
248
  __( 'The AdSense verification and Auto ads code is already activated in the <a href="%s">AdSense settings</a>.', 'advanced-ads' ),
258
  ),
259
  esc_attr__( 'Activate', 'advanced-ads' )
260
  ),
261
+ ];
262
  }
263
 
264
  /**
modules/gadsense/admin/dummy.php CHANGED
@@ -11,9 +11,9 @@ class Dummy_Type extends Advanced_Ads_Ad_Type_Abstract{
11
  $this->title = "ASDF Dummy";
12
  $this->description = "Some dummy description";
13
 
14
- $this->parameters = array(
15
  'content' => ''
16
- );
17
  }
18
  public function render_parameters($ad){
19
  $network = Dummy_Network::get_instance();
@@ -86,7 +86,7 @@ class Dummy_Network extends Advanced_Ads_Ad_Network {
86
 
87
  public function get_external_ad_units()
88
  {
89
- $units = array();
90
  for ($i=0; $i<42; $i++){
91
  $ad_unit = new Advanced_Ads_Ad_Network_Ad_Unit("RAW DATA");
92
  $ad_unit->id = "Dummy" . $i;
@@ -121,10 +121,10 @@ class Dummy_Network extends Advanced_Ads_Ad_Network {
121
  require_once GADSENSE_BASE_PATH . 'admin/views/external-ads-dummy.php';
122
  $html_ad_selector = ob_get_clean();
123
 
124
- $response = array(
125
  'status' => true,
126
  'html' => $html_ad_selector,
127
- );
128
  header( 'Content-Type: application/json' );
129
  echo wp_json_encode( $response );
130
  die();
11
  $this->title = "ASDF Dummy";
12
  $this->description = "Some dummy description";
13
 
14
+ $this->parameters = [
15
  'content' => ''
16
+ ];
17
  }
18
  public function render_parameters($ad){
19
  $network = Dummy_Network::get_instance();
86
 
87
  public function get_external_ad_units()
88
  {
89
+ $units = [];
90
  for ($i=0; $i<42; $i++){
91
  $ad_unit = new Advanced_Ads_Ad_Network_Ad_Unit("RAW DATA");
92
  $ad_unit->id = "Dummy" . $i;
121
  require_once GADSENSE_BASE_PATH . 'admin/views/external-ads-dummy.php';
122
  $html_ad_selector = ob_get_clean();
123
 
124
+ $response = [
125
  'status' => true,
126
  'html' => $html_ad_selector,
127
+ ];
128
  header( 'Content-Type: application/json' );
129
  echo wp_json_encode( $response );
130
  die();
modules/gadsense/admin/views/adsense-account.php CHANGED
@@ -38,12 +38,12 @@ $alerts_heading = $adsense_id
38
  '<a target="_blank" href="https://www.google.com/adsense/new/u/1/' . $adsense_id . '/">',
39
  '</a>'
40
  ),
41
- array(
42
- 'a' => array(
43
  'target' => true,
44
  'href' => true,
45
- ),
46
- )
47
  )
48
  : __( 'AdSense warnings', 'advanced-ads' );
49
 
@@ -65,9 +65,9 @@ $alerts_advads_messages = Advanced_Ads_Adsense_MAPI::get_adsense_alert_messag
65
  <?php foreach ( $alerts['items'] as $alert_id => $alert ) : ?>
66
  <?php $internal_id = isset( $alert['id'] ) ? $alert['id'] : str_replace( '-', '_', strtoupper( $alert['type'] ) ); ?>
67
  <?php if ( isset( $alerts_advads_messages[ $internal_id ] ) ) : ?>
68
- <li><?php echo wp_kses( $alerts_advads_messages[ $internal_id ], array( 'a' => array( 'href' => true, 'target' => true, 'class' => true ) ) ); ?>&nbsp;<a href="#" class="mapi-dismiss-alert" data-id="<?php echo esc_attr( $alert_id ); ?>"><?php echo esc_html( $alerts_dismiss ); ?></a></li>
69
  <?php else : ?>
70
- <li><?php echo wp_kses( $alert['message'], array( 'a' => array( 'href' => true, 'target' => true, 'class' => true ) ) ); ?>&nbsp;<a href="#" class="mapi-dismiss-alert" data-id="<?php echo esc_attr( $alert_id ); ?>"><?php echo esc_html( $alerts_dismiss ); ?></a></li>
71
  <?php endif; ?>
72
  <?php endforeach; ?>
73
  </ul>
@@ -83,19 +83,19 @@ $alerts_advads_messages = Advanced_Ads_Adsense_MAPI::get_adsense_alert_messag
83
  }
84
  if ( ! empty( $message ) ) {
85
  echo '<div id="mapi-connect-errors" class="notice error inline"><p class="advads-notice-inline advads-error">';
86
- echo wp_kses( $message, array(
87
- 'a' => array(
88
- 'id' => array(),
89
- 'class' => array(),
90
- 'href' => array(),
91
- 'style' => array(),
92
- ),
93
- 'i' => array(
94
- 'id' => array(),
95
- 'class' => array(),
96
- 'style' => array(),
97
- ),
98
- ) );
99
  echo '</p></div>';
100
  }
101
  }
@@ -136,12 +136,12 @@ $alerts_advads_messages = Advanced_Ads_Adsense_MAPI::get_adsense_alert_messag
136
  wp_kses(
137
  // translators: %1$s is an opening a tag, %2$s is the closing one
138
  __( 'See all %1$srecommended ad networks%2$s.', 'advanced-ads' ),
139
- array(
140
- 'a' => array(
141
- 'href' => array(),
142
- 'target' => array(),
143
- ),
144
- )
145
  ),
146
  '<a href="' . esc_url( ADVADS_URL ) . ' recommended-ad-networks/?utm_source=advanced-ads&utm_medium=link&utm_campaign=recommendations" target="_blank">',
147
  '</a>'
@@ -210,12 +210,12 @@ else : ?>
210
  wp_kses(
211
  // translators: %1$s is the opening link tag to our manual; %2$s is the appropriate closing link tag; %3$s is the opening link tag to our help forum; %4$s is the appropriate closing link tag
212
  __( 'Problems with AdSense? Check out the %1$smanual%2$s or %3$sask here%4$s.', 'advanced-ads' ),
213
- array(
214
- 'a' => array(
215
- 'href' => array(),
216
- 'target' => array(),
217
- ),
218
- )
219
  ),
220
  '<a href="' . esc_url( ADVADS_URL ) . 'adsense-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-manual-check" target="_blank">',
221
  '</a>',
@@ -228,12 +228,12 @@ else : ?>
228
  wp_kses(
229
  // translators: %1$s is an opening a tag, %2$s is the closing one
230
  __( 'See all %1$srecommended ad networks%2$s.', 'advanced-ads' ),
231
- array(
232
- 'a' => array(
233
- 'href' => array(),
234
- 'target' => array(),
235
- ),
236
- )
237
  ),
238
  '<a href="' . esc_url( ADVADS_URL ) . ' recommended-ad-networks/?utm_source=advanced-ads&utm_medium=link&utm_campaign=recommendations" target="_blank">',
239
  '</a>'
@@ -258,11 +258,11 @@ else : ?>
258
  AdsenseMAPI,
259
  <?php
260
  echo wp_json_encode(
261
- array(
262
  'alertsMsg' => $alerts_advads_messages,
263
  'alertsHeadingMsg' => $alerts_heading,
264
- 'alertsDismissMsg' => wp_kses( $alerts_dismiss, array() ),
265
- )
266
  )
267
  ?>
268
  );
38
  '<a target="_blank" href="https://www.google.com/adsense/new/u/1/' . $adsense_id . '/">',
39
  '</a>'
40
  ),
41
+ [
42
+ 'a' => [
43
  'target' => true,
44
  'href' => true,
45
+ ],
46
+ ]
47
  )
48
  : __( 'AdSense warnings', 'advanced-ads' );
49
 
65
  <?php foreach ( $alerts['items'] as $alert_id => $alert ) : ?>
66
  <?php $internal_id = isset( $alert['id'] ) ? $alert['id'] : str_replace( '-', '_', strtoupper( $alert['type'] ) ); ?>
67
  <?php if ( isset( $alerts_advads_messages[ $internal_id ] ) ) : ?>
68
+ <li><?php echo wp_kses( $alerts_advads_messages[ $internal_id ], [ 'a' => [ 'href' => true, 'target' => true, 'class' => true ] ] ); ?>&nbsp;<a href="#" class="mapi-dismiss-alert" data-id="<?php echo esc_attr( $alert_id ); ?>"><?php echo esc_html( $alerts_dismiss ); ?></a></li>
69
  <?php else : ?>
70
+ <li><?php echo wp_kses( $alert['message'], [ 'a' => [ 'href' => true, 'target' => true, 'class' => true ] ] ); ?>&nbsp;<a href="#" class="mapi-dismiss-alert" data-id="<?php echo esc_attr( $alert_id ); ?>"><?php echo esc_html( $alerts_dismiss ); ?></a></li>
71
  <?php endif; ?>
72
  <?php endforeach; ?>
73
  </ul>
83
  }
84
  if ( ! empty( $message ) ) {
85
  echo '<div id="mapi-connect-errors" class="notice error inline"><p class="advads-notice-inline advads-error">';
86
+ echo wp_kses( $message, [
87
+ 'a' => [
88
+ 'id' => [],
89
+ 'class' => [],
90
+ 'href' => [],
91
+ 'style' => [],
92
+ ],
93
+ 'i' => [
94
+ 'id' => [],
95
+ 'class' => [],
96
+ 'style' => [],
97
+ ],
98
+ ] );
99
  echo '</p></div>';
100
  }
101
  }
136
  wp_kses(
137
  // translators: %1$s is an opening a tag, %2$s is the closing one
138
  __( 'See all %1$srecommended ad networks%2$s.', 'advanced-ads' ),
139
+ [
140
+ 'a' => [
141
+ 'href' => [],
142
+ 'target' => [],
143
+ ],
144
+ ]
145
  ),
146
  '<a href="' . esc_url( ADVADS_URL ) . ' recommended-ad-networks/?utm_source=advanced-ads&utm_medium=link&utm_campaign=recommendations" target="_blank">',
147
  '</a>'
210
  wp_kses(
211
  // translators: %1$s is the opening link tag to our manual; %2$s is the appropriate closing link tag; %3$s is the opening link tag to our help forum; %4$s is the appropriate closing link tag
212
  __( 'Problems with AdSense? Check out the %1$smanual%2$s or %3$sask here%4$s.', 'advanced-ads' ),
213
+ [
214
+ 'a' => [
215
+ 'href' => [],
216
+ 'target' => [],
217
+ ],
218
+ ]
219
  ),
220
  '<a href="' . esc_url( ADVADS_URL ) . 'adsense-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-manual-check" target="_blank">',
221
  '</a>',
228
  wp_kses(
229
  // translators: %1$s is an opening a tag, %2$s is the closing one
230
  __( 'See all %1$srecommended ad networks%2$s.', 'advanced-ads' ),
231
+ [
232
+ 'a' => [
233
+ 'href' => [],
234
+ 'target' => [],
235
+ ],
236
+ ]
237
  ),
238
  '<a href="' . esc_url( ADVADS_URL ) . ' recommended-ad-networks/?utm_source=advanced-ads&utm_medium=link&utm_campaign=recommendations" target="_blank">',
239
  '</a>'
258
  AdsenseMAPI,
259
  <?php
260
  echo wp_json_encode(
261
+ [
262
  'alertsMsg' => $alerts_advads_messages,
263
  'alertsHeadingMsg' => $alerts_heading,
264
+ 'alertsDismissMsg' => wp_kses( $alerts_dismiss, [] ),
265
+ ]
266
  )
267
  ?>
268
  );
modules/gadsense/admin/views/adsense-ad-parameters.php CHANGED
@@ -119,7 +119,7 @@ if( $pub_id_errors ) : ?>
119
  </select>
120
  <a href="<?php echo esc_url( ADVADS_URL ) . 'adsense-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-ad-types'; ?>" target="_blank"><?php esc_html_e( 'manual', 'advanced-ads' ); ?></a>
121
  </div>
122
- <?php if ( in_array( $unit_type, array( 'link', 'link-responsive' ), true ) ) : ?>
123
  <p class="advads-message-warning"><?php esc_html_e( 'Google AdSense deprecated Link Units. Please choose another type.', 'advanced-ads' ); ?>
124
  <a href="<?php echo esc_url( ADVADS_URL ); ?>adsense-link-units/"" target="_blank" rel="noopener">
125
  <?php esc_html_e( 'Learn more', 'advanced-ads' ); ?>
119
  </select>
120
  <a href="<?php echo esc_url( ADVADS_URL ) . 'adsense-ads/?utm_source=advanced-ads&utm_medium=link&utm_campaign=adsense-ad-types'; ?>" target="_blank"><?php esc_html_e( 'manual', 'advanced-ads' ); ?></a>
121
  </div>
122
+ <?php if ( in_array( $unit_type, [ 'link', 'link-responsive' ], true ) ) : ?>
123
  <p class="advads-message-warning"><?php esc_html_e( 'Google AdSense deprecated Link Units. Please choose another type.', 'advanced-ads' ); ?>
124
  <a href="<?php echo esc_url( ADVADS_URL ); ?>adsense-link-units/"" target="_blank" rel="noopener">
125
  <?php esc_html_e( 'Learn more', 'advanced-ads' ); ?>
modules/gadsense/admin/views/adsense-report.php CHANGED
@@ -20,7 +20,7 @@ $data_timestamp->setTimezone( $time_zone );
20
  <div class="advads-stats-dd-container">
21
  <div class="advads-stats-dd-button"><span class="dashicons dashicons-admin-multisite"></span>
22
  <div class="advads-stats-dd-items">
23
- <div class="advads-stats-dd-item<?php echo in_array( $report_filter, array( '*', '' ), true ) ? ' current-filter' : ''; ?>" data-domain="*">
24
  <?php esc_html_e( 'All', 'advanced-ads' ); ?>
25
  </div><!-- .advads-stats-dd-item -->
26
  <?php foreach ( $report_domains as $domain_name ) : ?>
20
  <div class="advads-stats-dd-container">
21
  <div class="advads-stats-dd-button"><span class="dashicons dashicons-admin-multisite"></span>
22
  <div class="advads-stats-dd-items">
23
+ <div class="advads-stats-dd-item<?php echo in_array( $report_filter, [ '*', '' ], true ) ? ' current-filter' : ''; ?>" data-domain="*">
24
  <?php esc_html_e( 'All', 'advanced-ads' ); ?>
25
  </div><!-- .advads-stats-dd-item -->
26
  <?php foreach ( $report_domains as $domain_name ) : ?>
modules/gadsense/admin/views/borlabs-cookie-auto-ads-warning.php CHANGED
@@ -2,9 +2,9 @@
2
  wp_kses(
3
  /* translators: 1: the plugin name that is managing the Auto ads code. */
4
  __( 'Advanced Ads detected that <strong>%s</strong> is managing the Auto ads code and will therefore not add it.', 'advanced-ads' ),
5
- array(
6
- 'strong' => array(),
7
- )
8
  ),
9
  'Borlabs Cookies'
10
  );
2
  wp_kses(
3
  /* translators: 1: the plugin name that is managing the Auto ads code. */
4
  __( 'Advanced Ads detected that <strong>%s</strong> is managing the Auto ads code and will therefore not add it.', 'advanced-ads' ),
5
+ [
6
+ 'strong' => [],
7
+ ]
8
  ),
9
  'Borlabs Cookies'
10
  );
modules/gadsense/admin/views/external-ads-list.php CHANGED
@@ -18,7 +18,7 @@ if ( ! isset( $hide_idle_ads ) ) {
18
  $hide_idle_ads = true;
19
  }
20
  if ( ! isset( $ad_units ) ) {
21
- $ad_units = array();
22
  }
23
 
24
  ?>
@@ -114,10 +114,10 @@ if ( ! isset( $ad_units ) ) {
114
  <li>
115
  <?php
116
  /* Translators: 1: opening tag for a link to create an ad manually 2: closing a tag */
117
- printf( wp_kses( __( '%1$sCreate an AdSense code manually%2$s: Select the <em>Normal</em> or <em>Responsive</em> type and the size.', 'advanced-ads' ), array(
118
- 'em' => array(),
119
- 'strong' => array(),
120
- ) ), '<a href="#" class="mapi-close-selector-link prevent-default">', '</a>' );
121
  ?>
122
  </li>
123
  <li>
18
  $hide_idle_ads = true;
19
  }
20
  if ( ! isset( $ad_units ) ) {
21
+ $ad_units = [];
22
  }
23
 
24
  ?>
114
  <li>
115
  <?php
116
  /* Translators: 1: opening tag for a link to create an ad manually 2: closing a tag */
117
+ printf( wp_kses( __( '%1$sCreate an AdSense code manually%2$s: Select the <em>Normal</em> or <em>Responsive</em> type and the size.', 'advanced-ads' ), [
118
+ 'em' => [],
119
+ 'strong' => [],
120
+ ] ), '<a href="#" class="mapi-close-selector-link prevent-default">', '</a>' );
121
  ?>
122
  </li>
123
  <li>
modules/gadsense/config.php CHANGED
@@ -4,8 +4,8 @@
4
 
5
  $path = dirname( __FILE__ );
6
 
7
- return array(
8
- 'classmap' => array(
9
  'Advanced_Ads_Ad_Type_Adsense' => $path . '/includes/class-ad-type-adsense.php',
10
  'Advanced_Ads_AdSense_Data' => $path . '/includes/class-gadsense-data.php',
11
  'Advanced_Ads_AdSense_MAPI' => $path . '/includes/class-mapi.php',
@@ -16,6 +16,6 @@ return array(
16
  'Advanced_Ads_AdSense_Report_Api' => $path . '/includes/adsense-report-api.php',
17
 
18
  'Advanced_Ads_Network_Adsense' => $path . '/includes/class-network-adsense.php',
19
- ),
20
  'textdomain' => null,
21
- );
4
 
5
  $path = dirname( __FILE__ );
6
 
7
+ return [
8
+ 'classmap' => [
9
  'Advanced_Ads_Ad_Type_Adsense' => $path . '/includes/class-ad-type-adsense.php',
10
  'Advanced_Ads_AdSense_Data' => $path . '/includes/class-gadsense-data.php',
11
  'Advanced_Ads_AdSense_MAPI' => $path . '/includes/class-mapi.php',
16
  'Advanced_Ads_AdSense_Report_Api' => $path . '/includes/adsense-report-api.php',
17
 
18
  'Advanced_Ads_Network_Adsense' => $path . '/includes/class-network-adsense.php',
19
+ ],
20
  'textdomain' => null,
21
+ ];
modules/gadsense/includes/adsense-report-api.php CHANGED
@@ -51,7 +51,7 @@ class Advanced_Ads_AdSense_Report_Api {
51
  $this->access_token = Advanced_Ads_AdSense_MAPI::get_access_token( $publisher_id );
52
  $this->publisher_id = $publisher_id;
53
 
54
- $endpoint_args = array(
55
  'startDate.year' => '%SY%', // Start date's year - integer (4 digits).
56
  'startDate.month' => '%SM%', // Start date's month - integer.
57
  'startDate.day' => '%SD%', // Start date's integer - integer.
@@ -62,8 +62,8 @@ class Advanced_Ads_AdSense_Report_Api {
62
  'dimension2' => 'DATE', // Secondary reporting dimension.
63
  'metrics' => 'ESTIMATED_EARNINGS', // Report metrics.
64
  'reportingTimeZone' => 'ACCOUNT_TIME_ZONE', // Time zone used in report data.
65
- );
66
- $this->endpoint_url = str_replace( array( 'dimension1', 'dimension2' ), 'dimensions', add_query_arg( $endpoint_args, 'https://adsense.googleapis.com/v2/accounts/%pubid%/reports:generate' ) );
67
  }
68
 
69
  /**
@@ -81,7 +81,7 @@ class Advanced_Ads_AdSense_Report_Api {
81
  * @return array Array of error messages.
82
  */
83
  public function get_token_error() {
84
- return is_string( $this->access_token ) ? array() : $this->access_token;
85
  }
86
 
87
  /**
@@ -104,7 +104,7 @@ class Advanced_Ads_AdSense_Report_Api {
104
  $start_date = $today->sub( date_interval_create_from_date_string( '28 days' ) );
105
  // Replace placeholder in the endpoint with actual arguments.
106
  $url = str_replace(
107
- array(
108
  '%pubid%',
109
  '%DIM%',
110
  '%SY%',
@@ -113,8 +113,8 @@ class Advanced_Ads_AdSense_Report_Api {
113
  '%EY%',
114
  '%EM%',
115
  '%ED%',
116
- ),
117
- array(
118
  $this->publisher_id,
119
  $dimension,
120
  $start_date->format( 'Y' ),
@@ -123,44 +123,44 @@ class Advanced_Ads_AdSense_Report_Api {
123
  $today->format( 'Y' ),
124
  $today->format( 'n' ),
125
  $today->format( 'j' ),
126
- ),
127
  $this->endpoint_url
128
  );
129
 
130
- $headers = array(
131
  'Authorization' => 'Bearer ' . $this->access_token,
132
- );
133
 
134
- $response = wp_remote_get( $url, array( 'headers' => $headers ) );
135
  Advanced_Ads_AdSense_MAPI::log( 'Fetched AdSense Report from ' . $url );
136
 
137
  if ( is_wp_error( $response ) ) {
138
- return array(
139
  'status' => false,
140
  // translators: AdSense ID.
141
  'msg' => sprintf( esc_html__( 'Error while retrieving report for "%s".', 'advanced-ads' ), $this->publisher_id ),
142
  'raw' => $response->get_error_message(),
143
- );
144
  }
145
 
146
  $response_body = json_decode( $response['body'], true );
147
 
148
  if ( ! isset( $response_body['startDate'] ) ) {
149
- return array(
150
  'status' => false,
151
  // translators: AdSense ID.
152
  'msg' => sprintf( esc_html__( 'Invalid response while retrieving report for "%s".', 'advanced-ads' ), $this->publisher_id ),
153
  'raw' => $response['body'],
154
- );
155
  }
156
 
157
  $response_body['api_version'] = self::API_VERSION;
158
  $response_body['timestamp'] = time();
159
 
160
- return array(
161
  'status' => true,
162
  'response_body' => $response_body,
163
- );
164
  }
165
 
166
  }
51
  $this->access_token = Advanced_Ads_AdSense_MAPI::get_access_token( $publisher_id );
52
  $this->publisher_id = $publisher_id;
53
 
54
+ $endpoint_args = [
55
  'startDate.year' => '%SY%', // Start date's year - integer (4 digits).
56
  'startDate.month' => '%SM%', // Start date's month - integer.
57
  'startDate.day' => '%SD%', // Start date's integer - integer.
62
  'dimension2' => 'DATE', // Secondary reporting dimension.
63
  'metrics' => 'ESTIMATED_EARNINGS', // Report metrics.
64
  'reportingTimeZone' => 'ACCOUNT_TIME_ZONE', // Time zone used in report data.
65
+ ];
66
+ $this->endpoint_url = str_replace( [ 'dimension1', 'dimension2' ], 'dimensions', add_query_arg( $endpoint_args, 'https://adsense.googleapis.com/v2/accounts/%pubid%/reports:generate' ) );
67
  }
68
 
69
  /**
81
  * @return array Array of error messages.
82
  */
83
  public function get_token_error() {
84
+ return is_string( $this->access_token ) ? [] : $this->access_token;
85
  }
86
 
87
  /**
104
  $start_date = $today->sub( date_interval_create_from_date_string( '28 days' ) );
105
  // Replace placeholder in the endpoint with actual arguments.
106
  $url = str_replace(
107
+ [
108
  '%pubid%',
109
  '%DIM%',
110
  '%SY%',
113
  '%EY%',
114
  '%EM%',
115
  '%ED%',
116
+ ],
117
+ [
118
  $this->publisher_id,
119
  $dimension,
120
  $start_date->format( 'Y' ),
123
  $today->format( 'Y' ),
124
  $today->format( 'n' ),
125
  $today->format( 'j' ),
126
+ ],
127
  $this->endpoint_url
128
  );
129
 
130
+ $headers = [
131
  'Authorization' => 'Bearer ' . $this->access_token,
132
+ ];
133
 
134
+ $response = wp_remote_get( $url, [ 'headers' => $headers ] );
135
  Advanced_Ads_AdSense_MAPI::log( 'Fetched AdSense Report from ' . $url );
136
 
137
  if ( is_wp_error( $response ) ) {
138
+ return [
139
  'status' => false,
140
  // translators: AdSense ID.
141
  'msg' => sprintf( esc_html__( 'Error while retrieving report for "%s".', 'advanced-ads' ), $this->publisher_id ),
142
  'raw' => $response->get_error_message(),
143
+ ];
144
  }
145
 
146
  $response_body = json_decode( $response['body'], true );
147
 
148
  if ( ! isset( $response_body['startDate'] ) ) {
149
+ return [
150
  'status' => false,
151
  // translators: AdSense ID.
152
  'msg' => sprintf( esc_html__( 'Invalid response while retrieving report for "%s".', 'advanced-ads' ), $this->publisher_id ),
153
  'raw' => $response['body'],
154
+ ];
155
  }
156
 
157
  $response_body['api_version'] = self::API_VERSION;
158
  $response_body['timestamp'] = time();
159
 
160
+ return [
161
  'status' => true,
162
  'response_body' => $response_body,
163
+ ];
164
  }
165
 
166
  }
modules/gadsense/includes/adsense-report-data.php CHANGED
@@ -66,7 +66,7 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
66
  *
67
  * @var array
68
  */
69
- private $domains = array();
70
 
71
  /**
72
  * Instance constructor.
@@ -110,13 +110,13 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
110
  * @return string the serialized data.
111
  */
112
  public function serialize() {
113
- return serialize( array(
114
  'earnings' => $this->earnings,
115
  'type' => $this->type,
116
  'timestamp' => $this->timestamp,
117
  'currency' => $this->currency,
118
  'domains' => $this->domains,
119
- ) );
120
  }
121
 
122
  /**
@@ -128,14 +128,14 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
128
  try {
129
  $unwrapped = unserialize( $data );
130
  } catch ( Exception $ex ) {
131
- $unwrapped = array();
132
  }
133
 
134
  $this->earnings = isset( $unwrapped['earnings'] ) ? $unwrapped['earnings'] : null;
135
  $this->type = isset( $unwrapped['type'] ) ? $unwrapped['type'] : null;
136
  $this->timestamp = isset( $unwrapped['timestamp'] ) ? $unwrapped['timestamp'] : 0;
137
  $this->currency = isset( $unwrapped['currency'] ) ? $unwrapped['currency'] : '';
138
- $this->domains = isset( $unwrapped['domains'] ) ? $unwrapped['domains'] : array();
139
  }
140
 
141
  /**
@@ -144,7 +144,7 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
144
  * @param array $response API call response from Google.
145
  */
146
  public function update_data_from_response( $response ) {
147
- $headers = array();
148
  $this->version = $response['api_version'];
149
  $this->timestamp = $response['timestamp'];
150
  foreach ( $response['headers'] as $header ) {
@@ -153,7 +153,7 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
153
  }
154
  $headers[] = $header['name'];
155
  }
156
- $earnings = array();
157
 
158
  if ( ! empty( $response['rows'] ) ) {
159
  foreach ( $response['rows'] as $row ) {
@@ -233,13 +233,13 @@ class Advanced_Ads_AdSense_Report_Data implements Serializable {
233
  $yesterday = $today->sub( date_interval_create_from_date_string( '1 day' ) );
234
  $prev7 = $today->sub( date_interval_create_from_date_string( '7 days' ) );
235
  $prev28 = $today->sub( date_interval_create_from_date_string( '28 days' ) );
236
- $sums = array(
237
  'today' => 0,
238
  'yesterday' => 0,
239
  '7days' => 0,
240
  'this_month' => 0,
241
  '28days' => 0,
242
- );
243
 
244
  // Unit type reports should always have the ad unit id specified.
245
  if ( $filter === '' && $this->type === 'unit' ) {
66
  *
67
  * @var array
68
  */
69
+ private $domains = [];
70
 
71
  /**
72
  * Instance constructor.
110
  * @return string the serialized data.
111
  */
112
  public function serialize() {
113
+ return serialize( [
114
  'earnings' => $this->earnings,
115
  'type' => $this->type,
116
  'timestamp' => $this->timestamp,
117
  'currency' => $this->currency,
118
  'domains' => $this->domains,
119
+ ] );
120
  }
121
 
122
  /**
128
  try {
129
  $unwrapped = unserialize( $data );
130
  } catch ( Exception $ex ) {
131
+ $unwrapped = [];
132
  }
133
 
134
  $this->earnings = isset( $unwrapped['earnings'] ) ? $unwrapped['earnings'] : null;
135
  $this->type = isset( $unwrapped['type'] ) ? $unwrapped['type'] : null;
136
  $this->timestamp = isset( $unwrapped['timestamp'] ) ? $unwrapped['timestamp'] : 0;
137
  $this->currency = isset( $unwrapped['currency'] ) ? $unwrapped['currency'] : '';
138
+ $this->domains = isset( $unwrapped['domains'] ) ? $unwrapped['domains'] : [];
139
  }
140
 
141
  /**
144
  * @param array $response API call response from Google.
145
  */
146
  public function update_data_from_response( $response ) {
147
+ $headers = [];
148
  $this->version = $response['api_version'];
149
  $this->timestamp = $response['timestamp'];
150
  foreach ( $response['headers'] as $header ) {
153
  }
154
  $headers[] = $header['name'];
155
  }
156
+ $earnings = [];
157
 
158
  if ( ! empty( $response['rows'] ) ) {
159
  foreach ( $response['rows'] as $row ) {
233
  $yesterday = $today->sub( date_interval_create_from_date_string( '1 day' ) );
234
  $prev7 = $today->sub( date_interval_create_from_date_string( '7 days' ) );
235
  $prev28 = $today->sub( date_interval_create_from_date_string( '28 days' ) );
236
+ $sums = [
237
  'today' => 0,
238
  'yesterday' => 0,
239
  '7days' => 0,
240
  'this_month' => 0,
241
  '28days' => 0,
242
+ ];
243
 
244
  // Unit type reports should always have the ad unit id specified.
245
  if ( $filter === '' && $this->type === 'unit' ) {
modules/gadsense/includes/class-ad-type-adsense.php CHANGED
@@ -33,9 +33,9 @@ class Advanced_Ads_Ad_Type_Adsense extends Advanced_Ads_Ad_Type_Abstract {
33
  public function __construct() {
34
  $this->title = __( 'AdSense ad', 'advanced-ads' );
35
  $this->description = __( 'Use ads from your Google AdSense account', 'advanced-ads' );
36
- $this->parameters = array(
37
  'content' => '',
38
- );
39
  }
40
 
41
  /**
@@ -44,7 +44,7 @@ class Advanced_Ads_Ad_Type_Adsense extends Advanced_Ads_Ad_Type_Abstract {
44
  * @return array
45
  */
46
  public static function get_ad_types() {
47
- return array(
48
  'normal' => __( 'Normal', 'advanced-ads' ),
49
  'responsive' => __( 'Responsive', 'advanced-ads' ),
50
  'matched-content' => __( 'Multiplex', 'advanced-ads' ),
@@ -52,7 +52,7 @@ class Advanced_Ads_Ad_Type_Adsense extends Advanced_Ads_Ad_Type_Abstract {
52
  'link-responsive' => __( 'Link ads (Responsive)', 'advanced-ads' ),
53
  'in-article' => __( 'In-article', 'advanced-ads' ),
54
  'in-feed' => __( 'In-feed', 'advanced-ads' ),
55
- );
56
  }
57
 
58
  /**
@@ -104,11 +104,11 @@ class Advanced_Ads_Ad_Type_Adsense extends Advanced_Ads_Ad_Type_Abstract {
104
  $unit_height = 0;
105
  $json_content = '';
106
  $unit_resize = '';
107
- $extra_params = array(
108
  'default_width' => '',
109
  'default_height' => '',
110
- 'at_media' => array(),
111
- );
112
 
113
  $db = Advanced_Ads_AdSense_Data::get_instance();
114
  $pub_id = trim( $db->get_adsense_id( $ad ) );
@@ -224,7 +224,7 @@ class Advanced_Ads_Ad_Type_Adsense extends Advanced_Ads_Ad_Type_Abstract {
224
  $content = wp_unslash( $content );
225
  $ad_unit = json_decode( $content, true );
226
  if ( empty( $ad_unit ) ) {
227
- $ad_unit = array();
228
  }
229
  // remove this slotId from unsupported_ads
230
  $mapi_options = Advanced_Ads_AdSense_MAPI::get_option();
@@ -282,7 +282,7 @@ class Advanced_Ads_Ad_Type_Adsense extends Advanced_Ads_Ad_Type_Abstract {
282
 
283
  // "link" was a static format until AdSense stopped filling them in March 2021. Their responsive format serves as a fallback recommended by AdSense
284
  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
285
- $is_static_normal_content = ! in_array( $content->unitType, array( 'responsive', 'link', 'link-responsive', 'matched-content', 'in-article', 'in-feed' ), true );
286
 
287
  $output = apply_filters( 'advanced-ads-gadsense-output', false, $ad, $pub_id, $content );
288
  if ( false !== $output ) {
@@ -296,7 +296,7 @@ class Advanced_Ads_Ad_Type_Adsense extends Advanced_Ads_Ad_Type_Abstract {
296
 
297
  // add notice when a link unit is used
298
  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
299
- if ( in_array( $content->unitType, array( 'link', 'link-responsive' ), true ) ) {
300
  Advanced_Ads_Ad_Health_Notices::get_instance()->add( 'adsense_link_units_deprecated' );
301
  }
302
 
33
  public function __construct() {
34
  $this->title = __( 'AdSense ad', 'advanced-ads' );
35
  $this->description = __( 'Use ads from your Google AdSense account', 'advanced-ads' );
36
+ $this->parameters = [
37
  'content' => '',
38
+ ];
39
  }
40
 
41
  /**
44
  * @return array
45
  */
46
  public static function get_ad_types() {
47
+ return [
48
  'normal' => __( 'Normal', 'advanced-ads' ),
49
  'responsive' => __( 'Responsive', 'advanced-ads' ),
50
  'matched-content' => __( 'Multiplex', 'advanced-ads' ),
52
  'link-responsive' => __( 'Link ads (Responsive)', 'advanced-ads' ),
53
  'in-article' => __( 'In-article', 'advanced-ads' ),
54
  'in-feed' => __( 'In-feed', 'advanced-ads' ),
55
+ ];
56
  }
57
 
58
  /**
104
  $unit_height = 0;
105
  $json_content = '';
106
  $unit_resize = '';
107
+ $extra_params = [
108
  'default_width' => '',
109
  'default_height' => '',
110
+ 'at_media' => [],
111
+ ];
112
 
113
  $db = Advanced_Ads_AdSense_Data::get_instance();
114
  $pub_id = trim( $db->get_adsense_id( $ad ) );
224
  $content = wp_unslash( $content );
225
  $ad_unit = json_decode( $content, true );
226
  if ( empty( $ad_unit ) ) {
227
+ $ad_unit = [];
228
  }
229
  // remove this slotId from unsupported_ads
230
  $mapi_options = Advanced_Ads_AdSense_MAPI::get_option();
282
 
283
  // "link" was a static format until AdSense stopped filling them in March 2021. Their responsive format serves as a fallback recommended by AdSense
284
  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
285
+ $is_static_normal_content = ! in_array( $content->unitType, [ 'responsive', 'link', 'link-responsive', 'matched-content', 'in-article', 'in-feed' ], true );
286
 
287
  $output = apply_filters( 'advanced-ads-gadsense-output', false, $ad, $pub_id, $content );
288
  if ( false !== $output ) {
296
 
297
  // add notice when a link unit is used
298
  // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
299
+ if ( in_array( $content->unitType, [ 'link', 'link-responsive' ], true ) ) {
300
  Advanced_Ads_Ad_Health_Notices::get_instance()->add( 'adsense_link_units_deprecated' );
301
  }
302
 
modules/gadsense/includes/class-adsense-report.php CHANGED
@@ -63,7 +63,7 @@ class Advanced_Ads_AdSense_Report {
63
  */
64
  public function refresh_report() {
65
  $api_helper = new Advanced_Ads_AdSense_Report_Api( $this->type );
66
- $error = array();
67
 
68
  if ( $api_helper->has_token() ) {
69
  $response = $api_helper->call_google();
@@ -155,7 +155,7 @@ class Advanced_Ads_AdSense_Report {
155
  * @return string HTML of the individual cell.
156
  */
157
  private function get_earning_cell( $sum, $index ) {
158
- $period_strings = array(
159
  'today' => esc_html__( 'Today', 'advanced-ads' ),
160
  'yesterday' => esc_html__( 'Yesterday', 'advanced-ads' ),
161
  /* translators: 1: The number of days. */
@@ -163,7 +163,7 @@ class Advanced_Ads_AdSense_Report {
163
  'this_month' => esc_html__( 'This Month', 'advanced-ads' ),
164
  /* translators: 1: The number of days. */
165
  '28days' => sprintf( esc_html__( 'Last %1$d days', 'advanced-ads' ), 28 ),
166
- );
167
 
168
  $markup = '<div class="advads-flex1 advads-stats-box"><div>' . $period_strings[ $index ] . '</div>';
169
  $markup .= '<div class="advads-stats-box-main">';
63
  */
64
  public function refresh_report() {
65
  $api_helper = new Advanced_Ads_AdSense_Report_Api( $this->type );
66
+ $error = [];
67
 
68
  if ( $api_helper->has_token() ) {
69
  $response = $api_helper->call_google();
155
  * @return string HTML of the individual cell.
156
  */
157
  private function get_earning_cell( $sum, $index ) {
158
+ $period_strings = [
159
  'today' => esc_html__( 'Today', 'advanced-ads' ),
160
  'yesterday' => esc_html__( 'Yesterday', 'advanced-ads' ),
161
  /* translators: 1: The number of days. */
163
  'this_month' => esc_html__( 'This Month', 'advanced-ads' ),
164
  /* translators: 1: The number of days. */
165
  '28days' => sprintf( esc_html__( 'Last %1$d days', 'advanced-ads' ), 28 ),
166
+ ];
167
 
168
  $markup = '<div class="advads-flex1 advads-stats-box"><div>' . $period_strings[ $index ] . '</div>';
169
  $markup .= '<div class="advads-stats-box-main">';
modules/gadsense/includes/class-gadsense-data.php CHANGED
@@ -8,7 +8,7 @@ class Advanced_Ads_AdSense_Data {
8
 
9
  private function __construct() {
10
 
11
- $options = get_option(GADSENSE_OPT_NAME, array());
12
 
13
  // set defaults
14
  if (!isset($options['adsense-id'])) {
@@ -36,9 +36,9 @@ class Advanced_Ads_AdSense_Data {
36
  $this->options = $options;
37
 
38
  // Resizing method for responsive ads
39
- $this->resizing = array(
40
  'auto' => __('Auto', 'advanced-ads'),
41
- );
42
  }
43
 
44
  /**
8
 
9
  private function __construct() {
10
 
11
+ $options = get_option(GADSENSE_OPT_NAME, []);
12
 
13
  // set defaults
14
  if (!isset($options['adsense-id'])) {
36
  $this->options = $options;
37
 
38
  // Resizing method for responsive ads
39
+ $this->resizing = [
40
  'auto' => __('Auto', 'advanced-ads'),
41
+ ];
42
  }
43
 
44
  /**
modules/gadsense/includes/class-mapi.php CHANGED
@@ -19,61 +19,61 @@ class Advanced_Ads_AdSense_MAPI {
19
 
20
  private static $instance = null;
21
 
22
- private static $default_options = array();
23
 
24
- private static $empty_account_data = array(
25
- 'default_app' => array(
26
  'access_token' => '',
27
  'refresh_token' => '',
28
  'expires' => 0,
29
  'token_type' => '',
30
- ),
31
- 'user_app' => array(
32
  'access_token' => '',
33
  'refresh_token' => '',
34
  'expires' => 0,
35
  'token_type' => '',
36
- ),
37
- 'ad_units' => array(),
38
- 'details' => array(),
39
- 'alerts' => array(),
40
- );
41
 
42
  /**
43
  * Instance constructor
44
  */
45
  private function __construct() {
46
 
47
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_scripts' ) );
48
 
49
- add_action( 'wp_ajax_advads_gadsense_mapi_confirm_code', array( $this, 'ajax_confirm_code' ) );
50
  //add_action( 'wp_ajax_advads_gadsense_mapi_get_adUnits', array( $this, 'ajax_get_adUnits' ) );
51
- add_action( 'wp_ajax_advads_gadsense_mapi_get_details', array( $this, 'ajax_get_account_details' ) );
52
- add_action( 'wp_ajax_advads_gadsense_mapi_select_account', array( $this, 'ajax_account_selected' ) );
53
- add_action( 'wp_ajax_advads_mapi_get_adCode', array( $this, 'ajax_get_adCode' ) );
54
- add_action( 'wp_ajax_advads-mapi-reconstructed-code', array( $this, 'ajax_save_reconstructed_code' ) );
55
- add_action( 'wp_ajax_advads-mapi-save-manual-code', array( $this, 'ajax_save_manual_code' ) );
56
- add_action( 'wp_ajax_advads-mapi-revoke-token', array( $this, 'ajax_revoke_tokken' ) );
57
- add_action( 'wp_ajax_advads-mapi-get-alerts', array( $this, 'ajax_get_account_alerts' ) );
58
- add_action( 'wp_ajax_advads-mapi-dismiss-alert', array( $this, 'ajax_dismiss_alert' ) );
59
- add_action( 'wp_ajax_advads_adsense_report_refresh', array( 'Advanced_Ads_Overview_Widgets_Callbacks', 'ajax_gadsense_dashboard' ) );
60
-
61
- add_action( 'admin_footer', array( $this, 'admin_footer' ) );
62
-
63
- self::$default_options = array(
64
- 'accounts' => array(),
65
- 'ad_codes' => array(),
66
- 'unsupported_units' => array(),
67
- 'quota' => array(
68
  'count' => self::CALL_PER_24H,
69
  'ts' => 0,
70
- ),
71
- 'connect_error' => array(),
72
- );
73
 
74
- add_filter( 'advanced-ads-support-messages', array( 'Advanced_Ads_AdSense_MAPI', 'adsense_warnings_check' ) );
75
 
76
- add_action( 'wp_loaded', array( $this, 'update_ad_health_notices' ) );
77
 
78
  }
79
 
@@ -93,10 +93,10 @@ class Advanced_Ads_AdSense_MAPI {
93
  if ( isset( $connection_error_messages[ $mapi_options['connect_error']['reason'] ] ) ) {
94
  $health_class->add( 'adsense_connect_' . $mapi_options['connect_error']['reason'] );
95
  } else {
96
- $health_class->add( 'adsense_connect_' . $mapi_options['connect_error']['reason'], array(
97
  'text' => esc_html__( 'Last AdSense account connection attempt failed.', 'advanced-ads' ) . ' ' . $mapi_options['connect_error']['message'],
98
  'type' => 'problem',
99
- ) );
100
  }
101
 
102
  foreach( $health_class->notices as $key => $value ) {
@@ -126,7 +126,7 @@ class Advanced_Ads_AdSense_MAPI {
126
  if ( is_array( $alerts ) && isset( $alerts['items'] ) && is_array( $alerts['items'] ) && $alerts['items'] ) {
127
 
128
  $alerts_advads_messages = Advanced_Ads_Adsense_MAPI::get_adsense_alert_messages();
129
- $item_ids = array();
130
 
131
  foreach ( $alerts['items'] as $internal_id => $item ) {
132
  $item_id = isset( $item['id'] ) ? $item['id'] : str_replace( '-', '_', strtoupper( $item['type'] ) );
@@ -136,17 +136,17 @@ class Advanced_Ads_AdSense_MAPI {
136
  } else {
137
  $health_class->add(
138
  'adsense_alert_' . $item_id,
139
- array(
140
  'text' => $item['message'] . ' ' . self::get_adsense_error_link( $item_id ),
141
  'type' => 'problem',
142
- )
143
  );
144
  }
145
 
146
  }
147
 
148
  // Remove notices that no more exist in the AdSense account (or have been dismissed).
149
- $_remove_ids = array();
150
  foreach( $health_class->notices as $key => $value ) {
151
  if ( false !== stripos( $key, 'adsense_alert_' ) ) {
152
  $alert_id = substr( $key, strlen( 'adsense_alert_' ) );
@@ -177,18 +177,18 @@ class Advanced_Ads_AdSense_MAPI {
177
  $options = $this->get_option();
178
  $now = time();
179
  if ( self::use_user_app() ) {
180
- return array( 'count' => PHP_INT_MAX );
181
  } else {
182
  if ( $now > $options['quota']['ts'] + ( 24 * 3600 ) ) {
183
- return array(
184
  'count' => self::CALL_PER_24H,
185
- );
186
  } else {
187
  $msg = $this->get_quota_msg();
188
- return array(
189
  'count' => $options['quota']['count'],
190
  'msg' => $msg,
191
- );
192
  }
193
  }
194
  }
@@ -325,34 +325,34 @@ class Advanced_Ads_AdSense_MAPI {
325
  foreach ( Advanced_Ads_Network_Adsense::get_instance()->get_external_ad_units() as $unit ) {
326
  if (
327
  isset( $unit->raw )
328
- && in_array( $unit->raw['contentAdsSettings']['type'], array( 'ARTICLE', 'FEED', 'MATCHED_CONTENT' ), true )
329
  && $ad_unit === $unit->id
330
  && ! array_key_exists( $ad_unit, $options['ad_codes'] )
331
  ) {
332
  $options['unsupported_units'][ $ad_unit ] = 1;
333
  update_option( self::OPTNAME, $options );
334
 
335
- return array(
336
  'status' => false,
337
  'msg' => 'doesNotSupportAdUnitType',
338
- );
339
  }
340
  }
341
 
342
  if ( ! isset( $access_token['msg'] ) ) {
343
- $headers = array(
344
  'Authorization' => 'Bearer ' . $access_token,
345
- );
346
- $response = wp_remote_get( $url, array( 'headers' => $headers ) );
347
  self::log( 'Get ad code for ad Unit [' . $ad_unit . ']' );
348
 
349
  if ( is_wp_error( $response ) ) {
350
- return array(
351
  'status' => false,
352
  // translators: %s: ad unit ID.
353
  'msg' => sprintf( esc_html__( 'Error while retrieving ad code for "%s".', 'advanced-ads' ), $ad_unit ),
354
  'raw' => $response->get_error_message(),
355
- );
356
  }
357
  $ad_code = json_decode( $response['body'], true );
358
  if ( $ad_code === null || ! isset( $ad_code['adCode'] ) ) {
@@ -368,18 +368,18 @@ class Advanced_Ads_AdSense_MAPI {
368
  }
369
  update_option( self::OPTNAME, $options );
370
 
371
- return array(
372
  'status' => false,
373
  'msg' => 'doesNotSupportAdUnitType',
374
- );
375
  }
376
 
377
- return array(
378
  'status' => false,
379
  // translators: %s: ad unit ID.
380
  'msg' => sprintf( esc_html__( 'Invalid response while retrieving ad code for "%s".', 'advanced-ads' ), $ad_unit ),
381
  'raw' => $response['body'],
382
- );
383
  }
384
  $options['ad_codes'][ $ad_unit ] = $ad_code['adCode'];
385
  if ( isset( $options['unsupported_units'][ $ad_unit ] ) ) {
@@ -404,7 +404,7 @@ class Advanced_Ads_AdSense_MAPI {
404
  public static function convert_ad_unit_format( $ad_unit ) {
405
  $chunks = explode( '/', $ad_unit['name'] );
406
 
407
- return array(
408
  'name' => $ad_unit['displayName'],
409
  'nameV2' => $ad_unit['name'],
410
  'id' => $ad_unit['reportingDimensionId'],
@@ -412,7 +412,7 @@ class Advanced_Ads_AdSense_MAPI {
412
  'status' => $ad_unit['state'],
413
  'contentAdsSettings' => $ad_unit['contentAdsSettings'],
414
  'reportingDimensionId' => $ad_unit['reportingDimensionId'],
415
- );
416
  }
417
 
418
  /**
@@ -431,21 +431,21 @@ class Advanced_Ads_AdSense_MAPI {
431
  return $access_token;
432
  }
433
 
434
- $response = wp_remote_get( $url, array( 'headers' => array( 'Authorization' => 'Bearer ' . $access_token ) ) );
435
  self::log( 'Get ad units list for ca-' . $account );
436
 
437
  if ( is_wp_error( $response ) ) {
438
- return array(
439
  'status' => false,
440
  // translators: %s is the publisher ID.
441
  'msg' => sprintf( esc_html__( 'Error while retrieving ad unit list for "%s".', 'advanced-ads' ), $account ),
442
  'raw' => $response->get_error_message(),
443
- );
444
  }
445
 
446
  if ( trim( $response['body'] ) === '{}' ) {
447
  // Empty account.
448
- return array(
449
  'status' => false,
450
  'msg' => sprintf(
451
  // translators: %1$s is the AdSense publisher ID; %2$s a starting a tag to the AdSense ad unit list and %3$s the closing link.
@@ -455,7 +455,7 @@ class Advanced_Ads_AdSense_MAPI {
455
  '</a>'
456
  ),
457
  'raw' => $response['body'],
458
- );
459
  }
460
 
461
  $response_body = json_decode( trim( $response['body'] ), true );
@@ -480,18 +480,18 @@ class Advanced_Ads_AdSense_MAPI {
480
  }
481
  }
482
 
483
- return array(
484
  'status' => false,
485
  'msg' => $error_message,
486
  'raw' => trim( $response['body'] ),
487
- );
488
  }
489
 
490
  $options = self::get_option();
491
 
492
  if ( ! isset( $response_body['nextPageToken'] ) ) {
493
  // Results fit into a single page (of 350 items).
494
- $new_ad_units = array();
495
 
496
  foreach ( $response_body['adUnits'] as $item ) {
497
  $item = self::convert_ad_unit_format( $item );
@@ -501,12 +501,12 @@ class Advanced_Ads_AdSense_MAPI {
501
  $options['accounts'][ $account ]['ad_units'] = $new_ad_units;
502
  update_option( self::OPTNAME, $options );
503
 
504
- return array( 'done' => true );
505
  }
506
 
507
  // There are more than 350 items in the account.
508
  $page_token = $response_body['nextPageToken'];
509
- $new_ad_units = array();
510
 
511
  foreach ( $response_body['adUnits'] as $item ) {
512
  $item = self::convert_ad_unit_format( $item );
@@ -524,20 +524,20 @@ class Advanced_Ads_AdSense_MAPI {
524
  }
525
 
526
  $next_url = $url . '&pageToken=' . urlencode( $page_token );
527
- $headers = array(
528
  'Authorization' => 'Bearer ' . $access_token,
529
- );
530
- $response = wp_remote_get( $next_url, array( 'headers' => $headers ) );
531
  self::log( 'Get ad unit list for ca-' . $account . ' page ' . $page );
532
  $page++;
533
 
534
  if ( is_wp_error( $response ) ) {
535
- return array(
536
  'status' => false,
537
  // translators: the publisher ID.
538
  'msg' => sprintf( esc_html__( 'Error while retrieving ad unit list for "%s".', 'advanced-ads' ), $account ),
539
  'raw' => $response->get_error_message(),
540
- );
541
  }
542
 
543
  $response_body = json_decode( $response['body'], true );
@@ -553,7 +553,7 @@ class Advanced_Ads_AdSense_MAPI {
553
  $options['accounts'][ $account ]['ad_units'] = $new_ad_units;
554
  update_option( self::OPTNAME, $options );
555
 
556
- return array( 'done' => true );
557
  }
558
 
559
  /**
@@ -595,18 +595,18 @@ class Advanced_Ads_AdSense_MAPI {
595
  // Account does not exist.
596
  if ( ! empty( $options['accounts'] ) ) {
597
  // There is another account connected.
598
- return array(
599
  'status' => false,
600
  'msg' => esc_html__( 'It seems that some changes have been made in the Advanced Ads settings. Please refresh this page.', 'advanced-ads' ),
601
  'reload' => true,
602
- );
603
  } else {
604
  // No account at all.
605
- return array(
606
  'status' => false,
607
- 'msg' => wp_kses( sprintf( __( 'Advanced Ads does not have access to your account (<code>%s</code>) anymore.', 'advanced-ads' ), $account ), array( 'code' => true ) ),
608
  'reload' => true,
609
- );
610
  }
611
  }
612
  }
@@ -633,24 +633,24 @@ class Advanced_Ads_AdSense_MAPI {
633
  }
634
 
635
  $url = 'https://www.googleapis.com/oauth2/v4/token';
636
- $args = array(
637
- 'body' => array(
638
  'refresh_token' => $refresh_token,
639
  'client_id' => $cid,
640
  'client_secret' => $cs,
641
  'grant_type' => 'refresh_token',
642
- ),
643
- );
644
 
645
  $response = wp_remote_post( $url, $args );
646
  self::log( 'Refresh access token' );
647
 
648
  if ( is_wp_error( $response ) ) {
649
- return array(
650
  'status' => false,
651
  'msg' => sprintf( esc_html__( 'error while renewing access token for "%s"', 'advanced-ads' ), $account ),
652
  'raw' => $response->get_error_message(),
653
- );
654
  } else {
655
  $tokens = json_decode( $response['body'], true );
656
  // checking for the $tokens is not enough. it can be empty.
@@ -666,12 +666,12 @@ class Advanced_Ads_AdSense_MAPI {
666
  $options['accounts'][ $account ]['default_app']['expires'] = $expires;
667
  }
668
  update_option( self::OPTNAME, $options );
669
- return array(
670
  'status' => true,
671
  'access_token' => $tokens['access_token'],
672
- );
673
  } else {
674
- return array(
675
  'status' => false,
676
  'msg' => sprintf(
677
  // translators: %s AdSense account ID
@@ -679,7 +679,7 @@ class Advanced_Ads_AdSense_MAPI {
679
  $account
680
  ) . ' ' . __( 'You could try to connect again under Advanced Ads > Settings > AdSense.', 'advanced-ads' ),
681
  'raw' => $response['body'],
682
- );
683
  }
684
  }
685
  }
@@ -703,17 +703,17 @@ class Advanced_Ads_AdSense_MAPI {
703
  $token = $options['accounts'][ $adsense_id ]['default_app']['refresh_token'];
704
  }
705
  $url = 'https://accounts.google.com/o/oauth2/revoke?token=' . $token;
706
- $args = array(
707
  'timeout' => 5,
708
- 'header' => array( 'Content-type' => 'application/x-www-form-urlencoded' ),
709
- );
710
 
711
  $response = wp_remote_post( $url, $args );
712
 
713
  self::log( 'Revoke API access for ca-' . $adsense_id );
714
 
715
  if ( is_wp_error( $response ) ) {
716
- echo json_encode( array( 'status' => false ) );
717
  } else {
718
  // remove all the adsense stats
719
  global $wpdb;
@@ -723,7 +723,7 @@ class Advanced_Ads_AdSense_MAPI {
723
  header( 'Content-Type: application/json' );
724
  unset( $options['accounts'][ $adsense_id ] );
725
  update_option( self::OPTNAME, $options );
726
- echo json_encode( array( 'status' => true ) );
727
  }
728
  }
729
  die;
@@ -745,9 +745,9 @@ class Advanced_Ads_AdSense_MAPI {
745
  $publisher_id = sanitize_text_field( wp_unslash( isset( $_POST['parsed_code']['pubId'] ) ? $_POST['parsed_code']['pubId'] : '' ) );
746
  if ( ! $this->check_valid_publisher( $publisher_id ) ) {
747
  wp_send_json_error(
748
- array(
749
  'message' => __( 'This ad code is from a different AdSense Account', 'advanced-ads' ),
750
- ),
751
  400
752
  );
753
  }
@@ -771,7 +771,7 @@ class Advanced_Ads_AdSense_MAPI {
771
  unset( $options['unsupported_units'][ $slot_id ] );
772
  }
773
 
774
- wp_send_json_success( array( 'updated' => update_option( self::OPTNAME, $options ) ) );
775
  }
776
 
777
  /**
@@ -802,7 +802,7 @@ class Advanced_Ads_AdSense_MAPI {
802
  $options['ad_codes'][ 'ca-' . $adsense_id . ':' . $slot ] = $code;
803
  update_option( self::OPTNAME, $options );
804
  header( 'Content-Type: application/json' );
805
- echo json_encode( array( 'status' => true ) );
806
  }
807
  die;
808
  }
@@ -828,10 +828,10 @@ class Advanced_Ads_AdSense_MAPI {
828
  header( 'Content-Type: application/json' );
829
  $quota_msg = $this->get_quota_msg();
830
  echo wp_json_encode(
831
- array(
832
  'quota' => 0,
833
  'quotaMsg' => $quota_msg,
834
- )
835
  );
836
  die;
837
  }
@@ -850,10 +850,10 @@ class Advanced_Ads_AdSense_MAPI {
850
  }
851
  );
852
  $ad_unit = reset( $ad_units );
853
- $response = array(
854
  'code' => $code,
855
  'type' => self::format_ad_data( $ad_unit, 'type' ),
856
- );
857
 
858
  /**
859
  * Add quota info for default API creds
@@ -892,7 +892,7 @@ class Advanced_Ads_AdSense_MAPI {
892
  $id = stripslashes( $_POST['id'] );
893
  $options = self::get_option();
894
 
895
- $items = array();
896
 
897
  // the account exists.
898
  if ( isset( $options['accounts'][ $account ] ) ) {
@@ -905,11 +905,11 @@ class Advanced_Ads_AdSense_MAPI {
905
  }
906
  }
907
  header( 'Content-Type: application/json' );
908
- echo json_encode( array(
909
  'status' => true,
910
  'alerts' => $items,
911
  'length' => count( $items ),
912
- ) );
913
  }
914
  die;
915
  }
@@ -934,7 +934,7 @@ class Advanced_Ads_AdSense_MAPI {
934
 
935
  if ( isset( $_POST['inlineAttempt'] ) ) {
936
  if ( ! is_array( $options['accounts'][ $account ]['alerts'] ) ) {
937
- $options['accounts'][ $account ]['alerts'] = array();
938
  }
939
  $options['accounts'][ $account ]['alerts']['inlineAttempt'] = time();
940
  update_option( self::OPTNAME, $options );
@@ -942,10 +942,10 @@ class Advanced_Ads_AdSense_MAPI {
942
 
943
  // the token is valid.
944
  if ( ! isset( $access_token['msg'] ) ) {
945
- $headers = array(
946
  'Authorization' => 'Bearer ' . $access_token,
947
- );
948
- $response = wp_remote_get( $url, array( 'headers' => $headers ) );
949
 
950
  $this->log( 'Get AdSense alerts for ' . $account );
951
 
@@ -955,7 +955,7 @@ class Advanced_Ads_AdSense_MAPI {
955
 
956
  // the response body is valid.
957
  if ( is_array( $alerts ) && isset( $alerts['alerts'] ) ) {
958
- $items = array();
959
  foreach ( $alerts['alerts'] as $item ) {
960
  // Do not store alerts of type "INFO".
961
  if ( strcasecmp( $item['severity'], 'INFO' ) !== 0 ) {
@@ -966,35 +966,35 @@ class Advanced_Ads_AdSense_MAPI {
966
  // filter alerts that are not relevant to the user
967
  $items = self::filter_account_alerts( $items );
968
 
969
- $alerts_array = array(
970
  'items' => $items ,
971
  'lastCheck' => time(),
972
- );
973
 
974
  $options['accounts'][ $account ]['alerts'] = $alerts_array;
975
  update_option( self::OPTNAME, $options );
976
- $results = array(
977
  'status' => true,
978
  'alerts' => $items,
979
  'length' => count( $items ),
980
- );
981
  header( 'Content-Type:application/json' );
982
  echo wp_json_encode( $results );
983
  } else {
984
- $results = array(
985
  'status' => false,
986
  'msg' => esc_html__( 'Invalid response body while retrieving account alerts', 'advanced-ads' ),
987
- );
988
  header( 'Content-Type:application/json' );
989
  echo wp_json_encode( $results );
990
  }
991
 
992
  } else {
993
- $results = array(
994
  'status' => false,
995
  'msg' => esc_html__( 'error while retrieving account alerts', 'advanced-ads' ),
996
  'raw' => $response->get_error_message(),
997
- );
998
  header( 'Content-Type:application/json' );
999
  echo wp_json_encode( $results );
1000
  }
@@ -1005,7 +1005,7 @@ class Advanced_Ads_AdSense_MAPI {
1005
 
1006
  } else {
1007
  header( 'Content-Type:application/json' );
1008
- echo wp_json_encode( array( 'status' => false ) );
1009
  }
1010
 
1011
  }
@@ -1030,10 +1030,10 @@ class Advanced_Ads_AdSense_MAPI {
1030
  Advanced_Ads_AdSense_Admin::get_mapi_ad_selector();
1031
  $ad_selector = ob_get_clean();
1032
 
1033
- $response = array(
1034
  'status' => true,
1035
  'html' => $ad_selector,
1036
- );
1037
 
1038
  /**
1039
  * Add quota info for default API creds
@@ -1072,16 +1072,16 @@ class Advanced_Ads_AdSense_MAPI {
1072
 
1073
  if ( $token_data && $account ) {
1074
  self::save_token_from_data( $token_data, $account );
1075
- wp_send_json( array( 'status' => true ) );
1076
  }
1077
  $error = 'Token data missing';
1078
  if ( $token_data ) {
1079
  $error = 'No account provided';
1080
  }
1081
- wp_send_json( array(
1082
  'status' => false,
1083
  'error_msg' => $error,
1084
- ) );
1085
 
1086
  }
1087
 
@@ -1105,40 +1105,40 @@ class Advanced_Ads_AdSense_MAPI {
1105
 
1106
  if ( ! is_array( $token_data ) ) {
1107
  wp_send_json(
1108
- array(
1109
  'status' => false,
1110
  'error_msg' => esc_html__( 'No token provided. Token data needed to get account details.', 'advanced-ads' ),
1111
- )
1112
  );
1113
  }
1114
 
1115
- $headers = array( 'Authorization' => 'Bearer ' . $token_data['access_token'] );
1116
- $response = wp_remote_get( $url, array( 'headers' => $headers ) );
1117
 
1118
  self::log( 'Get account details from new access token' );
1119
 
1120
  if ( is_wp_error( $response ) ) {
1121
- wp_send_json( array(
1122
  'status' => false,
1123
  'error_msg' => $response->get_error_message(),
1124
- ) );
1125
  }
1126
  if ( trim( $response['body'] ) === '{}' ) {
1127
  // Empty, disapproved or other reason.
1128
  $options = self::get_option();
1129
- $options['connect_error'] = array(
1130
  'message' => esc_html__( 'No AdSense account data found.', 'advanced-ads' ),
1131
  'reason' => 'noAdsenseData',
1132
- );
1133
  update_option( self::OPTNAME, $options );
1134
- wp_send_json_error( array( 'error' => esc_html__( 'No AdSense account data found.', 'advanced-ads' ) ), 404 );
1135
  }
1136
 
1137
  $accounts = json_decode( trim( $response['body'] ), true );
1138
 
1139
  if ( isset( $accounts['accounts'] ) ) {
1140
  $pub_id = explode( '/', $accounts['accounts'][0]['name'] )[1];
1141
- $child_accounts = wp_remote_get( str_replace( '%pubid%', $pub_id, $list_child_url ), array( 'headers' => $headers ) );
1142
 
1143
  if ( is_wp_error( $child_accounts ) ) {
1144
  wp_send_json_error( $child_accounts, 500 );
@@ -1147,35 +1147,35 @@ class Advanced_Ads_AdSense_MAPI {
1147
  if ( trim( $child_accounts['body'] ) === '{}' ) {
1148
  // Standard AdSense account.
1149
  self::save_token_from_data( $token_data, $accounts['accounts'][0] );
1150
- wp_send_json_success( array(
1151
  'reload' => true,
1152
- ) );
1153
  }
1154
  if ( $accounts_list !== null ) {
1155
  // Network account.
1156
- $details = array();
1157
  $html = '';
1158
- $details[ $pub_id ] = array(
1159
  'id' => $pub_id,
1160
  'name' => $accounts['accounts'][0]['displayName'],
1161
- );
1162
  $html .= sprintf( '<option value="%1$s">%2$s [%3$s]</option>', esc_attr( $pub_id ), esc_html( $accounts['accounts'][0]['displayName'] ), esc_html( $pub_id ) );
1163
 
1164
  foreach ( $accounts_list['accounts'] as $item ) {
1165
  $account_id = explode( '/', $item['name'] )[1];
1166
- $details[ $account_id ] = array(
1167
  'id' => $account_id,
1168
  'name' => $item['displayName'],
1169
- );
1170
  $html .= sprintf( '<option value="%1$s">%2$s [%3$s]</option>', esc_attr( $account_id ), esc_html( $item['displayName'] ), esc_html( $account_id ) );
1171
  }
1172
- wp_send_json_success( array(
1173
  'details' => $details,
1174
  'html' => $html,
1175
  'token_data' => $token_data,
1176
- ) );
1177
  }
1178
- wp_send_json_error( array( 'message' => 'unexpected response - get child accounts' ), 400 );
1179
  }
1180
  }
1181
 
@@ -1203,16 +1203,16 @@ class Advanced_Ads_AdSense_MAPI {
1203
  $redirect_uri = self::REDIRECT_URI;
1204
  $grant_type = 'authorization_code';
1205
 
1206
- $args = array(
1207
  'timeout' => 10,
1208
- 'body' => array(
1209
  'code' => $code,
1210
  'client_id' => $cid,
1211
  'client_secret' => $cs,
1212
  'redirect_uri' => $redirect_uri,
1213
  'grant_type' => $grant_type,
1214
- ),
1215
- );
1216
 
1217
  $response = wp_remote_post( $code_url, $args );
1218
 
@@ -1220,11 +1220,11 @@ class Advanced_Ads_AdSense_MAPI {
1220
 
1221
  if ( is_wp_error( $response ) ) {
1222
  return json_encode(
1223
- array(
1224
  'status' => false,
1225
  'msg' => 'error while submitting code',
1226
  'raw' => $response->get_error_message(),
1227
- )
1228
  );
1229
  } else {
1230
  $token = json_decode( $response['body'], true );
@@ -1234,19 +1234,19 @@ class Advanced_Ads_AdSense_MAPI {
1234
  $token['expires'] = $expires;
1235
  header( 'Content-Type: application/json' );
1236
  echo json_encode(
1237
- array(
1238
  'status' => true,
1239
  'token_data' => $token,
1240
- )
1241
  );
1242
 
1243
  } else {
1244
  header( 'Content-Type: application/json' );
1245
  echo json_encode(
1246
- array(
1247
  'status' => false,
1248
  'response_body' => $response['body'],
1249
- )
1250
  );
1251
  }
1252
  }
@@ -1261,7 +1261,7 @@ class Advanced_Ads_AdSense_MAPI {
1261
  */
1262
  public function admin_scripts( $hook ) {
1263
  if ( 'advanced-ads_page_advanced-ads-settings' == $hook ) {
1264
- wp_enqueue_script( 'gasense/mapi/settings', GADSENSE_BASE_URL . 'admin/assets/js/mapi-settings.js', array( 'jquery', 'wp-util' ), ADVADS_VERSION );
1265
  }
1266
  }
1267
 
@@ -1276,7 +1276,7 @@ class Advanced_Ads_AdSense_MAPI {
1276
  $refresh_alerts = false;
1277
 
1278
  // default value, never checked for alerts.
1279
- if ( array() === $alerts && $has_token ) {
1280
  $refresh_alerts = true;
1281
  }
1282
  if ( $has_token && is_array( $alerts ) ) {
@@ -1338,15 +1338,15 @@ class Advanced_Ads_AdSense_MAPI {
1338
  * Sort ad units list alphabetically
1339
  */
1340
  public static function get_sorted_adunits( $adunits ) {
1341
- $units_sorted_by_name = array();
1342
- $units_by_id = array();
1343
  foreach ( $adunits as $unit ) {
1344
  $units_sorted_by_name[ $unit['name'] ] = $unit['id'];
1345
  $units_by_id[ $unit['id'] ] = $unit;
1346
  }
1347
  ksort( $units_sorted_by_name );
1348
  $units_sorted_by_name = array_flip( $units_sorted_by_name );
1349
- $results = array();
1350
  foreach ( $units_sorted_by_name as $id => $name ) {
1351
  $results[ $name ] = $units_by_id[ $id ];
1352
  }
@@ -1467,25 +1467,25 @@ class Advanced_Ads_AdSense_MAPI {
1467
  $options['accounts'][ $adsense_id ] = self::$empty_account_data;
1468
  }
1469
  if ( self::use_user_app() ) {
1470
- $options['accounts'][ $adsense_id ]['user_app'] = array(
1471
  'access_token' => $token['access_token'],
1472
  'refresh_token' => $token['refresh_token'],
1473
  'expires' => $token['expires'],
1474
  'token_type' => $token['token_type'],
1475
- );
1476
  } else {
1477
- $options['accounts'][ $adsense_id ]['default_app'] = array(
1478
  'access_token' => $token['access_token'],
1479
  'refresh_token' => $token['refresh_token'],
1480
  'expires' => $token['expires'],
1481
  'token_type' => $token['token_type'],
1482
- );
1483
  }
1484
- $options['accounts'][ $adsense_id ]['details'] = array(
1485
  'id' => $adsense_id,
1486
  'name' => isset( $details['displayName'] ) ? $details['displayName'] : $details['name'],
1487
- );
1488
- $options['connect_error'] = array();
1489
  update_option( self::OPTNAME, $options );
1490
 
1491
  $gadsense_data = Advanced_Ads_AdSense_Data::get_instance();
@@ -1511,7 +1511,7 @@ class Advanced_Ads_AdSense_MAPI {
1511
  $alerts = $options['accounts'][ $pub_id ]['alerts'];
1512
  return self::filter_stored_account_alerts( $alerts );
1513
  } else {
1514
- return array();
1515
  }
1516
  }
1517
  return false;
@@ -1532,10 +1532,10 @@ class Advanced_Ads_AdSense_MAPI {
1532
  }
1533
 
1534
  // the message IDs we don’t even import from AdSense
1535
- $disabled_adsense_alerts = array(
1536
  'SELLERS_JSON_CONSENT', // AdSense message: We encourage you to publish your seller information in the Google sellers.json file. Visit the account settings page to review your current visibility status.
1537
  'REPORTING_HORIZON_LEGACY_DATA_NOTICE', // AdSense message: Data older than three years is no longer available in Reporting. This data can be downloaded for a limited time.
1538
- );
1539
 
1540
  // additional messages to disable. Useful if the function is used in different situations
1541
  if ( ! empty( $disabled_alerts ) && is_array( $disabled_alerts ) ) {
@@ -1567,7 +1567,7 @@ class Advanced_Ads_AdSense_MAPI {
1567
  return $alerts;
1568
  }
1569
 
1570
- $disabled_alerts = array();
1571
 
1572
  /**
1573
  * Asside from the basic filter, we also filter out some messages only from showing up while we still import them
@@ -1575,7 +1575,7 @@ class Advanced_Ads_AdSense_MAPI {
1575
  */
1576
  // Remove `ads.txt` related alerts if the file is displayed to visitors.
1577
  if ( Advanced_Ads_Ads_Txt_Admin::is_displayed() ) {
1578
- $disabled_alerts = array( 'ALERT_TYPE_ADS_TXT_UNAUTHORIZED', 'ADS_TXT_MISSING', 'ADS_TXT_ISSUES' );
1579
  }
1580
 
1581
  // filter alerts
@@ -1596,13 +1596,13 @@ class Advanced_Ads_AdSense_MAPI {
1596
  $adsense_id = $data->get_adsense_id();
1597
  $alerts = self::get_stored_account_alerts( $adsense_id );
1598
  if ( !is_array( $messages ) ) {
1599
- $messages = array();
1600
  }
1601
  if ( !empty( $alerts ) && !empty( $alerts['items'] ) ) {
1602
  $messages[] = sprintf(
1603
  wp_kses(
1604
  __( 'There are one or more warnings about the currently linked AdSense account. You can view them <a href="%s">here</a>', 'advanced-ads' ),
1605
- array( 'a' => array( 'href' => true ) )
1606
  ),
1607
  esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) )
1608
  );
@@ -1614,9 +1614,9 @@ class Advanced_Ads_AdSense_MAPI {
1614
  * Get the class's option
1615
  */
1616
  public static function get_option() {
1617
- $options = get_option( self::OPTNAME, array() );
1618
  if ( ! is_array( $options ) ) {
1619
- $options = array();
1620
  }
1621
  return $options + self::$default_options;
1622
  }
@@ -1646,7 +1646,7 @@ class Advanced_Ads_AdSense_MAPI {
1646
  */
1647
  public static function get_connect_error_messages() {
1648
  $health_class = Advanced_Ads_Ad_Health_Notices::get_instance();
1649
- $messages = array();
1650
  foreach( $health_class->default_notices as $key => $value ) {
1651
  if ( 0 === strpos( $key, 'adsense_connect_' ) ) {
1652
  $messages[ substr( $key, strlen( 'adsense_connect_' ) ) ] = $value['text'];
@@ -1660,7 +1660,7 @@ class Advanced_Ads_AdSense_MAPI {
1660
  */
1661
  public static function get_adsense_alert_messages() {
1662
  $health_class = Advanced_Ads_Ad_Health_Notices::get_instance();
1663
- $messages = array();
1664
  foreach( $health_class->default_notices as $key => $value ) {
1665
  if ( 0 === strpos( $key, 'adsense_alert_' ) ) {
1666
  $messages[ substr( $key, strlen( 'adsense_alert_' ) ) ] = $value['text'];
19
 
20
  private static $instance = null;
21
 
22
+ private static $default_options = [];
23
 
24
+ private static $empty_account_data = [
25
+ 'default_app' => [
26
  'access_token' => '',
27
  'refresh_token' => '',
28
  'expires' => 0,
29
  'token_type' => '',
30
+ ],
31
+ 'user_app' => [
32
  'access_token' => '',
33
  'refresh_token' => '',
34
  'expires' => 0,
35
  'token_type' => '',
36
+ ],
37
+ 'ad_units' => [],
38
+ 'details' => [],
39
+ 'alerts' => [],
40
+ ];
41
 
42
  /**
43
  * Instance constructor
44
  */
45
  private function __construct() {
46
 
47
+ add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
48
 
49
+ add_action( 'wp_ajax_advads_gadsense_mapi_confirm_code', [ $this, 'ajax_confirm_code' ] );
50
  //add_action( 'wp_ajax_advads_gadsense_mapi_get_adUnits', array( $this, 'ajax_get_adUnits' ) );
51
+ add_action( 'wp_ajax_advads_gadsense_mapi_get_details', [ $this, 'ajax_get_account_details' ] );
52
+ add_action( 'wp_ajax_advads_gadsense_mapi_select_account', [ $this, 'ajax_account_selected' ] );
53
+ add_action( 'wp_ajax_advads_mapi_get_adCode', [ $this, 'ajax_get_adCode' ] );
54
+ add_action( 'wp_ajax_advads-mapi-reconstructed-code', [ $this, 'ajax_save_reconstructed_code' ] );
55
+ add_action( 'wp_ajax_advads-mapi-save-manual-code', [ $this, 'ajax_save_manual_code' ] );
56
+ add_action( 'wp_ajax_advads-mapi-revoke-token', [ $this, 'ajax_revoke_tokken' ] );
57
+ add_action( 'wp_ajax_advads-mapi-get-alerts', [ $this, 'ajax_get_account_alerts' ] );
58
+ add_action( 'wp_ajax_advads-mapi-dismiss-alert', [ $this, 'ajax_dismiss_alert' ] );
59
+ add_action( 'wp_ajax_advads_adsense_report_refresh', [ 'Advanced_Ads_Overview_Widgets_Callbacks', 'ajax_gadsense_dashboard' ] );
60
+
61
+ add_action( 'admin_footer', [ $this, 'admin_footer' ] );
62
+
63
+ self::$default_options = [
64
+ 'accounts' => [],
65
+ 'ad_codes' => [],
66
+ 'unsupported_units' => [],
67
+ 'quota' => [
68
  'count' => self::CALL_PER_24H,
69
  'ts' => 0,
70
+ ],
71
+ 'connect_error' => [],
72
+ ];
73
 
74
+ add_filter( 'advanced-ads-support-messages', [ 'Advanced_Ads_AdSense_MAPI', 'adsense_warnings_check' ] );
75
 
76
+ add_action( 'wp_loaded', [ $this, 'update_ad_health_notices' ] );
77
 
78
  }
79
 
93
  if ( isset( $connection_error_messages[ $mapi_options['connect_error']['reason'] ] ) ) {
94
  $health_class->add( 'adsense_connect_' . $mapi_options['connect_error']['reason'] );
95
  } else {
96
+ $health_class->add( 'adsense_connect_' . $mapi_options['connect_error']['reason'], [
97
  'text' => esc_html__( 'Last AdSense account connection attempt failed.', 'advanced-ads' ) . ' ' . $mapi_options['connect_error']['message'],
98
  'type' => 'problem',
99
+ ] );
100
  }
101
 
102
  foreach( $health_class->notices as $key => $value ) {
126
  if ( is_array( $alerts ) && isset( $alerts['items'] ) && is_array( $alerts['items'] ) && $alerts['items'] ) {
127
 
128
  $alerts_advads_messages = Advanced_Ads_Adsense_MAPI::get_adsense_alert_messages();
129
+ $item_ids = [];
130
 
131
  foreach ( $alerts['items'] as $internal_id => $item ) {
132
  $item_id = isset( $item['id'] ) ? $item['id'] : str_replace( '-', '_', strtoupper( $item['type'] ) );
136
  } else {
137
  $health_class->add(
138
  'adsense_alert_' . $item_id,
139
+ [
140
  'text' => $item['message'] . ' ' . self::get_adsense_error_link( $item_id ),
141
  'type' => 'problem',
142
+ ]
143
  );
144
  }
145
 
146
  }
147
 
148
  // Remove notices that no more exist in the AdSense account (or have been dismissed).
149
+ $_remove_ids = [];
150
  foreach( $health_class->notices as $key => $value ) {
151
  if ( false !== stripos( $key, 'adsense_alert_' ) ) {
152
  $alert_id = substr( $key, strlen( 'adsense_alert_' ) );
177
  $options = $this->get_option();
178
  $now = time();
179
  if ( self::use_user_app() ) {
180
+ return [ 'count' => PHP_INT_MAX ];
181
  } else {
182
  if ( $now > $options['quota']['ts'] + ( 24 * 3600 ) ) {
183
+ return [
184
  'count' => self::CALL_PER_24H,
185
+ ];
186
  } else {
187
  $msg = $this->get_quota_msg();
188
+ return [
189
  'count' => $options['quota']['count'],
190
  'msg' => $msg,
191
+ ];
192
  }
193
  }
194
  }
325
  foreach ( Advanced_Ads_Network_Adsense::get_instance()->get_external_ad_units() as $unit ) {
326
  if (
327
  isset( $unit->raw )
328
+ && in_array( $unit->raw['contentAdsSettings']['type'], [ 'ARTICLE', 'FEED', 'MATCHED_CONTENT' ], true )
329
  && $ad_unit === $unit->id
330
  && ! array_key_exists( $ad_unit, $options['ad_codes'] )
331
  ) {
332
  $options['unsupported_units'][ $ad_unit ] = 1;
333
  update_option( self::OPTNAME, $options );
334
 
335
+ return [
336
  'status' => false,
337
  'msg' => 'doesNotSupportAdUnitType',
338
+ ];
339
  }
340
  }
341
 
342
  if ( ! isset( $access_token['msg'] ) ) {
343
+ $headers = [
344
  'Authorization' => 'Bearer ' . $access_token,
345
+ ];
346
+ $response = wp_remote_get( $url, [ 'headers' => $headers ] );
347
  self::log( 'Get ad code for ad Unit [' . $ad_unit . ']' );
348
 
349
  if ( is_wp_error( $response ) ) {
350
+ return [
351
  'status' => false,
352
  // translators: %s: ad unit ID.
353
  'msg' => sprintf( esc_html__( 'Error while retrieving ad code for "%s".', 'advanced-ads' ), $ad_unit ),
354
  'raw' => $response->get_error_message(),
355
+ ];
356
  }
357
  $ad_code = json_decode( $response['body'], true );
358
  if ( $ad_code === null || ! isset( $ad_code['adCode'] ) ) {
368
  }
369
  update_option( self::OPTNAME, $options );
370
 
371
+ return [
372
  'status' => false,
373
  'msg' => 'doesNotSupportAdUnitType',
374
+ ];
375
  }
376
 
377
+ return [
378
  'status' => false,
379
  // translators: %s: ad unit ID.
380
  'msg' => sprintf( esc_html__( 'Invalid response while retrieving ad code for "%s".', 'advanced-ads' ), $ad_unit ),
381
  'raw' => $response['body'],
382
+ ];
383
  }
384
  $options['ad_codes'][ $ad_unit ] = $ad_code['adCode'];
385
  if ( isset( $options['unsupported_units'][ $ad_unit ] ) ) {
404
  public static function convert_ad_unit_format( $ad_unit ) {
405
  $chunks = explode( '/', $ad_unit['name'] );
406
 
407
+ return [
408
  'name' => $ad_unit['displayName'],
409
  'nameV2' => $ad_unit['name'],
410
  'id' => $ad_unit['reportingDimensionId'],
412
  'status' => $ad_unit['state'],
413
  'contentAdsSettings' => $ad_unit['contentAdsSettings'],
414
  'reportingDimensionId' => $ad_unit['reportingDimensionId'],
415
+ ];
416
  }
417
 
418
  /**
431
  return $access_token;
432
  }
433
 
434
+ $response = wp_remote_get( $url, [ 'headers' => [ 'Authorization' => 'Bearer ' . $access_token ] ] );
435
  self::log( 'Get ad units list for ca-' . $account );
436
 
437
  if ( is_wp_error( $response ) ) {
438
+ return [
439
  'status' => false,
440
  // translators: %s is the publisher ID.
441
  'msg' => sprintf( esc_html__( 'Error while retrieving ad unit list for "%s".', 'advanced-ads' ), $account ),
442
  'raw' => $response->get_error_message(),
443
+ ];
444
  }
445
 
446
  if ( trim( $response['body'] ) === '{}' ) {
447
  // Empty account.
448
+ return [
449
  'status' => false,
450
  'msg' => sprintf(
451
  // translators: %1$s is the AdSense publisher ID; %2$s a starting a tag to the AdSense ad unit list and %3$s the closing link.
455
  '</a>'
456
  ),
457
  'raw' => $response['body'],
458
+ ];
459
  }
460
 
461
  $response_body = json_decode( trim( $response['body'] ), true );
480
  }
481
  }
482
 
483
+ return [
484
  'status' => false,
485
  'msg' => $error_message,
486
  'raw' => trim( $response['body'] ),
487
+ ];
488
  }
489
 
490
  $options = self::get_option();
491
 
492
  if ( ! isset( $response_body['nextPageToken'] ) ) {
493
  // Results fit into a single page (of 350 items).
494
+ $new_ad_units = [];
495
 
496
  foreach ( $response_body['adUnits'] as $item ) {
497
  $item = self::convert_ad_unit_format( $item );
501
  $options['accounts'][ $account ]['ad_units'] = $new_ad_units;
502
  update_option( self::OPTNAME, $options );
503
 
504
+ return [ 'done' => true ];
505
  }
506
 
507
  // There are more than 350 items in the account.
508
  $page_token = $response_body['nextPageToken'];
509
+ $new_ad_units = [];
510
 
511
  foreach ( $response_body['adUnits'] as $item ) {
512
  $item = self::convert_ad_unit_format( $item );
524
  }
525
 
526
  $next_url = $url . '&pageToken=' . urlencode( $page_token );
527
+ $headers = [
528
  'Authorization' => 'Bearer ' . $access_token,
529
+ ];
530
+ $response = wp_remote_get( $next_url, [ 'headers' => $headers ] );
531
  self::log( 'Get ad unit list for ca-' . $account . ' page ' . $page );
532
  $page++;
533
 
534
  if ( is_wp_error( $response ) ) {
535
+ return [
536
  'status' => false,
537
  // translators: the publisher ID.
538
  'msg' => sprintf( esc_html__( 'Error while retrieving ad unit list for "%s".', 'advanced-ads' ), $account ),
539
  'raw' => $response->get_error_message(),
540
+ ];
541
  }
542
 
543
  $response_body = json_decode( $response['body'], true );
553
  $options['accounts'][ $account ]['ad_units'] = $new_ad_units;
554
  update_option( self::OPTNAME, $options );
555
 
556
+ return [ 'done' => true ];
557
  }
558
 
559
  /**
595
  // Account does not exist.
596
  if ( ! empty( $options['accounts'] ) ) {
597
  // There is another account connected.
598
+ return [
599
  'status' => false,
600
  'msg' => esc_html__( 'It seems that some changes have been made in the Advanced Ads settings. Please refresh this page.', 'advanced-ads' ),
601
  'reload' => true,
602
+ ];
603
  } else {
604
  // No account at all.
605
+ return [
606
  'status' => false,
607
+ 'msg' => wp_kses( sprintf( __( 'Advanced Ads does not have access to your account (<code>%s</code>) anymore.', 'advanced-ads' ), $account ), [ 'code' => true ] ),
608
  'reload' => true,
609
+ ];
610
  }
611
  }
612
  }
633
  }
634
 
635
  $url = 'https://www.googleapis.com/oauth2/v4/token';
636
+ $args = [
637
+ 'body' => [
638
  'refresh_token' => $refresh_token,
639
  'client_id' => $cid,
640
  'client_secret' => $cs,
641
  'grant_type' => 'refresh_token',
642
+ ],
643
+ ];
644
 
645
  $response = wp_remote_post( $url, $args );
646
  self::log( 'Refresh access token' );
647
 
648
  if ( is_wp_error( $response ) ) {
649
+ return [
650
  'status' => false,
651
  'msg' => sprintf( esc_html__( 'error while renewing access token for "%s"', 'advanced-ads' ), $account ),
652
  'raw' => $response->get_error_message(),
653
+ ];
654
  } else {
655
  $tokens = json_decode( $response['body'], true );
656
  // checking for the $tokens is not enough. it can be empty.
666
  $options['accounts'][ $account ]['default_app']['expires'] = $expires;
667
  }
668
  update_option( self::OPTNAME, $options );
669
+ return [
670
  'status' => true,
671
  'access_token' => $tokens['access_token'],
672
+ ];
673
  } else {
674
+ return [
675
  'status' => false,
676
  'msg' => sprintf(
677
  // translators: %s AdSense account ID
679
  $account
680
  ) . ' ' . __( 'You could try to connect again under Advanced Ads > Settings > AdSense.', 'advanced-ads' ),
681
  'raw' => $response['body'],
682
+ ];
683
  }
684
  }
685
  }
703
  $token = $options['accounts'][ $adsense_id ]['default_app']['refresh_token'];
704
  }
705
  $url = 'https://accounts.google.com/o/oauth2/revoke?token=' . $token;
706
+ $args = [
707
  'timeout' => 5,
708
+ 'header' => [ 'Content-type' => 'application/x-www-form-urlencoded' ],
709
+ ];
710
 
711
  $response = wp_remote_post( $url, $args );
712
 
713
  self::log( 'Revoke API access for ca-' . $adsense_id );
714
 
715
  if ( is_wp_error( $response ) ) {
716
+ echo json_encode( [ 'status' => false ] );
717
  } else {
718
  // remove all the adsense stats
719
  global $wpdb;
723
  header( 'Content-Type: application/json' );
724
  unset( $options['accounts'][ $adsense_id ] );
725
  update_option( self::OPTNAME, $options );
726
+ echo json_encode( [ 'status' => true ] );
727
  }
728
  }
729
  die;
745
  $publisher_id = sanitize_text_field( wp_unslash( isset( $_POST['parsed_code']['pubId'] ) ? $_POST['parsed_code']['pubId'] : '' ) );
746
  if ( ! $this->check_valid_publisher( $publisher_id ) ) {
747
  wp_send_json_error(
748
+ [
749
  'message' => __( 'This ad code is from a different AdSense Account', 'advanced-ads' ),
750
+ ],
751
  400
752
  );
753
  }
771
  unset( $options['unsupported_units'][ $slot_id ] );
772
  }
773
 
774
+ wp_send_json_success( [ 'updated' => update_option( self::OPTNAME, $options ) ] );
775
  }
776
 
777
  /**
802
  $options['ad_codes'][ 'ca-' . $adsense_id . ':' . $slot ] = $code;
803
  update_option( self::OPTNAME, $options );
804
  header( 'Content-Type: application/json' );
805
+ echo json_encode( [ 'status' => true ] );
806
  }
807
  die;
808
  }
828
  header( 'Content-Type: application/json' );
829
  $quota_msg = $this->get_quota_msg();
830
  echo wp_json_encode(
831
+ [
832
  'quota' => 0,
833
  'quotaMsg' => $quota_msg,
834
+ ]
835
  );
836
  die;
837
  }
850
  }
851
  );
852
  $ad_unit = reset( $ad_units );
853
+ $response = [
854
  'code' => $code,
855
  'type' => self::format_ad_data( $ad_unit, 'type' ),
856
+ ];
857
 
858
  /**
859
  * Add quota info for default API creds
892
  $id = stripslashes( $_POST['id'] );
893
  $options = self::get_option();
894
 
895
+ $items = [];
896
 
897
  // the account exists.
898
  if ( isset( $options['accounts'][ $account ] ) ) {
905
  }
906
  }
907
  header( 'Content-Type: application/json' );
908
+ echo json_encode( [
909
  'status' => true,
910
  'alerts' => $items,
911
  'length' => count( $items ),
912
+ ] );
913
  }
914
  die;
915
  }
934
 
935
  if ( isset( $_POST['inlineAttempt'] ) ) {
936
  if ( ! is_array( $options['accounts'][ $account ]['alerts'] ) ) {
937
+ $options['accounts'][ $account ]['alerts'] = [];
938
  }
939
  $options['accounts'][ $account ]['alerts']['inlineAttempt'] = time();
940
  update_option( self::OPTNAME, $options );
942
 
943
  // the token is valid.
944
  if ( ! isset( $access_token['msg'] ) ) {
945
+ $headers = [
946
  'Authorization' => 'Bearer ' . $access_token,
947
+ ];
948
+ $response = wp_remote_get( $url, [ 'headers' => $headers ] );
949
 
950
  $this->log( 'Get AdSense alerts for ' . $account );
951
 
955
 
956
  // the response body is valid.
957
  if ( is_array( $alerts ) && isset( $alerts['alerts'] ) ) {
958
+ $items = [];
959
  foreach ( $alerts['alerts'] as $item ) {
960
  // Do not store alerts of type "INFO".
961
  if ( strcasecmp( $item['severity'], 'INFO' ) !== 0 ) {
966
  // filter alerts that are not relevant to the user
967
  $items = self::filter_account_alerts( $items );
968
 
969
+ $alerts_array = [
970
  'items' => $items ,
971
  'lastCheck' => time(),
972
+ ];
973
 
974
  $options['accounts'][ $account ]['alerts'] = $alerts_array;
975
  update_option( self::OPTNAME, $options );
976
+ $results = [
977
  'status' => true,
978
  'alerts' => $items,
979
  'length' => count( $items ),
980
+ ];
981
  header( 'Content-Type:application/json' );
982
  echo wp_json_encode( $results );
983
  } else {
984
+ $results = [
985
  'status' => false,
986
  'msg' => esc_html__( 'Invalid response body while retrieving account alerts', 'advanced-ads' ),
987
+ ];
988
  header( 'Content-Type:application/json' );
989
  echo wp_json_encode( $results );
990
  }
991
 
992
  } else {
993
+ $results = [
994
  'status' => false,
995
  'msg' => esc_html__( 'error while retrieving account alerts', 'advanced-ads' ),
996
  'raw' => $response->get_error_message(),
997
+ ];
998
  header( 'Content-Type:application/json' );
999
  echo wp_json_encode( $results );
1000
  }
1005
 
1006
  } else {
1007
  header( 'Content-Type:application/json' );
1008
+ echo wp_json_encode( [ 'status' => false ] );
1009
  }
1010
 
1011
  }
1030
  Advanced_Ads_AdSense_Admin::get_mapi_ad_selector();
1031
  $ad_selector = ob_get_clean();
1032
 
1033
+ $response = [
1034
  'status' => true,
1035
  'html' => $ad_selector,
1036
+ ];
1037
 
1038
  /**
1039
  * Add quota info for default API creds
1072
 
1073
  if ( $token_data && $account ) {
1074
  self::save_token_from_data( $token_data, $account );
1075
+ wp_send_json( [ 'status' => true ] );
1076
  }
1077
  $error = 'Token data missing';
1078
  if ( $token_data ) {
1079
  $error = 'No account provided';
1080
  }
1081
+ wp_send_json( [
1082
  'status' => false,
1083
  'error_msg' => $error,
1084
+ ] );
1085
 
1086
  }
1087
 
1105
 
1106
  if ( ! is_array( $token_data ) ) {
1107
  wp_send_json(
1108
+ [
1109
  'status' => false,
1110
  'error_msg' => esc_html__( 'No token provided. Token data needed to get account details.', 'advanced-ads' ),
1111
+ ]
1112
  );
1113
  }
1114
 
1115
+ $headers = [ 'Authorization' => 'Bearer ' . $token_data['access_token'] ];
1116
+ $response = wp_remote_get( $url, [ 'headers' => $headers ] );
1117
 
1118
  self::log( 'Get account details from new access token' );
1119
 
1120
  if ( is_wp_error( $response ) ) {
1121
+ wp_send_json( [
1122
  'status' => false,
1123
  'error_msg' => $response->get_error_message(),
1124
+ ] );
1125
  }
1126
  if ( trim( $response['body'] ) === '{}' ) {
1127
  // Empty, disapproved or other reason.
1128
  $options = self::get_option();
1129
+ $options['connect_error'] = [
1130
  'message' => esc_html__( 'No AdSense account data found.', 'advanced-ads' ),
1131
  'reason' => 'noAdsenseData',
1132
+ ];
1133
  update_option( self::OPTNAME, $options );
1134
+ wp_send_json_error( [ 'error' => esc_html__( 'No AdSense account data found.', 'advanced-ads' ) ], 404 );
1135
  }
1136
 
1137
  $accounts = json_decode( trim( $response['body'] ), true );
1138
 
1139
  if ( isset( $accounts['accounts'] ) ) {
1140
  $pub_id = explode( '/', $accounts['accounts'][0]['name'] )[1];
1141
+ $child_accounts = wp_remote_get( str_replace( '%pubid%', $pub_id, $list_child_url ), [ 'headers' => $headers ] );
1142
 
1143
  if ( is_wp_error( $child_accounts ) ) {
1144
  wp_send_json_error( $child_accounts, 500 );
1147
  if ( trim( $child_accounts['body'] ) === '{}' ) {
1148
  // Standard AdSense account.
1149
  self::save_token_from_data( $token_data, $accounts['accounts'][0] );
1150
+ wp_send_json_success( [
1151
  'reload' => true,
1152
+ ] );
1153
  }
1154
  if ( $accounts_list !== null ) {
1155
  // Network account.
1156
+ $details = [];
1157
  $html = '';
1158
+ $details[ $pub_id ] = [
1159
  'id' => $pub_id,
1160
  'name' => $accounts['accounts'][0]['displayName'],
1161
+ ];
1162
  $html .= sprintf( '<option value="%1$s">%2$s [%3$s]</option>', esc_attr( $pub_id ), esc_html( $accounts['accounts'][0]['displayName'] ), esc_html( $pub_id ) );
1163
 
1164
  foreach ( $accounts_list['accounts'] as $item ) {
1165
  $account_id = explode( '/', $item['name'] )[1];
1166
+ $details[ $account_id ] = [
1167
  'id' => $account_id,
1168
  'name' => $item['displayName'],
1169
+ ];
1170
  $html .= sprintf( '<option value="%1$s">%2$s [%3$s]</option>', esc_attr( $account_id ), esc_html( $item['displayName'] ), esc_html( $account_id ) );
1171
  }
1172
+ wp_send_json_success( [
1173
  'details' => $details,
1174
  'html' => $html,
1175
  'token_data' => $token_data,
1176
+ ] );
1177
  }
1178
+ wp_send_json_error( [ 'message' => 'unexpected response - get child accounts' ], 400 );
1179
  }
1180
  }
1181
 
1203
  $redirect_uri = self::REDIRECT_URI;
1204
  $grant_type = 'authorization_code';
1205
 
1206
+ $args = [
1207
  'timeout' => 10,
1208
+ 'body' => [
1209
  'code' => $code,
1210
  'client_id' => $cid,
1211
  'client_secret' => $cs,
1212
  'redirect_uri' => $redirect_uri,
1213
  'grant_type' => $grant_type,
1214
+ ],
1215
+ ];
1216
 
1217
  $response = wp_remote_post( $code_url, $args );
1218
 
1220
 
1221
  if ( is_wp_error( $response ) ) {
1222
  return json_encode(
1223
+ [
1224
  'status' => false,
1225
  'msg' => 'error while submitting code',
1226
  'raw' => $response->get_error_message(),
1227
+ ]
1228
  );
1229
  } else {
1230
  $token = json_decode( $response['body'], true );
1234
  $token['expires'] = $expires;
1235
  header( 'Content-Type: application/json' );
1236
  echo json_encode(
1237
+ [
1238
  'status' => true,
1239
  'token_data' => $token,
1240
+ ]
1241
  );
1242
 
1243
  } else {
1244
  header( 'Content-Type: application/json' );
1245
  echo json_encode(
1246
+ [
1247
  'status' => false,
1248
  'response_body' => $response['body'],
1249
+ ]
1250
  );
1251
  }
1252
  }
1261
  */
1262
  public function admin_scripts( $hook ) {
1263
  if ( 'advanced-ads_page_advanced-ads-settings' == $hook ) {
1264
+ wp_enqueue_script( 'gasense/mapi/settings', GADSENSE_BASE_URL . 'admin/assets/js/mapi-settings.js', [ 'jquery', 'wp-util' ], ADVADS_VERSION );
1265
  }
1266
  }
1267
 
1276
  $refresh_alerts = false;
1277
 
1278
  // default value, never checked for alerts.
1279
+ if ( [] === $alerts && $has_token ) {
1280
  $refresh_alerts = true;
1281
  }
1282
  if ( $has_token && is_array( $alerts ) ) {
1338
  * Sort ad units list alphabetically
1339
  */
1340
  public static function get_sorted_adunits( $adunits ) {
1341
+ $units_sorted_by_name = [];
1342
+ $units_by_id = [];
1343
  foreach ( $adunits as $unit ) {
1344
  $units_sorted_by_name[ $unit['name'] ] = $unit['id'];
1345
  $units_by_id[ $unit['id'] ] = $unit;
1346
  }
1347
  ksort( $units_sorted_by_name );
1348
  $units_sorted_by_name = array_flip( $units_sorted_by_name );
1349
+ $results = [];
1350
  foreach ( $units_sorted_by_name as $id => $name ) {
1351
  $results[ $name ] = $units_by_id[ $id ];
1352
  }
1467
  $options['accounts'][ $adsense_id ] = self::$empty_account_data;
1468
  }
1469
  if ( self::use_user_app() ) {
1470
+ $options['accounts'][ $adsense_id ]['user_app'] = [
1471
  'access_token' => $token['access_token'],
1472
  'refresh_token' => $token['refresh_token'],
1473
  'expires' => $token['expires'],
1474
  'token_type' => $token['token_type'],
1475
+ ];
1476
  } else {
1477
+ $options['accounts'][ $adsense_id ]['default_app'] = [
1478
  'access_token' => $token['access_token'],
1479
  'refresh_token' => $token['refresh_token'],
1480
  'expires' => $token['expires'],
1481
  'token_type' => $token['token_type'],
1482
+ ];
1483
  }
1484
+ $options['accounts'][ $adsense_id ]['details'] = [
1485
  'id' => $adsense_id,
1486
  'name' => isset( $details['displayName'] ) ? $details['displayName'] : $details['name'],
1487
+ ];
1488
+ $options['connect_error'] = [];
1489
  update_option( self::OPTNAME, $options );
1490
 
1491
  $gadsense_data = Advanced_Ads_AdSense_Data::get_instance();
1511
  $alerts = $options['accounts'][ $pub_id ]['alerts'];
1512
  return self::filter_stored_account_alerts( $alerts );
1513
  } else {
1514
+ return [];
1515
  }
1516
  }
1517
  return false;
1532
  }
1533
 
1534
  // the message IDs we don’t even import from AdSense
1535
+ $disabled_adsense_alerts = [
1536
  'SELLERS_JSON_CONSENT', // AdSense message: We encourage you to publish your seller information in the Google sellers.json file. Visit the account settings page to review your current visibility status.
1537
  'REPORTING_HORIZON_LEGACY_DATA_NOTICE', // AdSense message: Data older than three years is no longer available in Reporting. This data can be downloaded for a limited time.
1538
+ ];
1539
 
1540
  // additional messages to disable. Useful if the function is used in different situations
1541
  if ( ! empty( $disabled_alerts ) && is_array( $disabled_alerts ) ) {
1567
  return $alerts;
1568
  }
1569
 
1570
+ $disabled_alerts = [];
1571
 
1572
  /**
1573
  * Asside from the basic filter, we also filter out some messages only from showing up while we still import them
1575
  */
1576
  // Remove `ads.txt` related alerts if the file is displayed to visitors.
1577
  if ( Advanced_Ads_Ads_Txt_Admin::is_displayed() ) {
1578
+ $disabled_alerts = [ 'ALERT_TYPE_ADS_TXT_UNAUTHORIZED', 'ADS_TXT_MISSING', 'ADS_TXT_ISSUES' ];
1579
  }
1580
 
1581
  // filter alerts
1596
  $adsense_id = $data->get_adsense_id();
1597
  $alerts = self::get_stored_account_alerts( $adsense_id );
1598
  if ( !is_array( $messages ) ) {
1599
+ $messages = [];
1600
  }
1601
  if ( !empty( $alerts ) && !empty( $alerts['items'] ) ) {
1602
  $messages[] = sprintf(
1603
  wp_kses(
1604
  __( 'There are one or more warnings about the currently linked AdSense account. You can view them <a href="%s">here</a>', 'advanced-ads' ),
1605
+ [ 'a' => [ 'href' => true ] ]
1606
  ),
1607
  esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#adsense' ) )
1608
  );
1614
  * Get the class's option
1615
  */
1616
  public static function get_option() {
1617
+ $options = get_option( self::OPTNAME, [] );
1618
  if ( ! is_array( $options ) ) {
1619
+ $options = [];
1620
  }
1621
  return $options + self::$default_options;
1622
  }
1646
  */
1647
  public static function get_connect_error_messages() {
1648
  $health_class = Advanced_Ads_Ad_Health_Notices::get_instance();
1649
+ $messages = [];
1650
  foreach( $health_class->default_notices as $key => $value ) {
1651
  if ( 0 === strpos( $key, 'adsense_connect_' ) ) {
1652
  $messages[ substr( $key, strlen( 'adsense_connect_' ) ) ] = $value['text'];
1660
  */
1661
  public static function get_adsense_alert_messages() {
1662
  $health_class = Advanced_Ads_Ad_Health_Notices::get_instance();
1663
+ $messages = [];
1664
  foreach( $health_class->default_notices as $key => $value ) {
1665
  if ( 0 === strpos( $key, 'adsense_alert_' ) ) {
1666
  $messages[ substr( $key, strlen( 'adsense_alert_' ) ) ] = $value['text'];
modules/gadsense/includes/class-network-adsense.php CHANGED
@@ -9,7 +9,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
9
  *
10
  * @var array
11
  */
12
- private static $status_codes_active = array( 'ACTIVE', 'NEW' );
13
 
14
  /**
15
  * A globally usable instance, that will be created when calling {$link Advanced_Ads_Ad_Network#get_instance) for the first time
@@ -52,7 +52,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
52
  add_settings_field(
53
  'adsense-id',
54
  __( 'AdSense account', 'advanced-ads' ),
55
- array( $this, 'render_settings_adsense_id' ),
56
  $hook,
57
  $section_id
58
  );
@@ -61,7 +61,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
61
  add_settings_field(
62
  'adsense-page-level',
63
  __( 'Auto ads', 'advanced-ads' ),
64
- array( $this, 'render_settings_adsense_page_level' ),
65
  $hook,
66
  $section_id
67
  );
@@ -72,7 +72,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
72
  add_settings_field(
73
  'top_anchor_ad',
74
  __( 'Auto ads', 'advanced-ads' ) . ':&nbsp;' . __( 'Disable top anchor ad', 'advanced-ads' ),
75
- array( $this, 'render_settings_adsense_top_anchor_ad' ),
76
  $hook,
77
  $section_id
78
  );
@@ -82,7 +82,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
82
  add_settings_field(
83
  'hide_stats',
84
  __( 'Disable stats', 'advanced-ads' ),
85
- array( $this, 'render_settings_adsense_hide_stats' ),
86
  $hook,
87
  $section_id
88
  );
@@ -94,7 +94,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
94
  add_settings_field(
95
  'adsense-limit',
96
  __( 'Limit to 3 ads', 'advanced-ads' ),
97
- array( $this, 'render_settings_adsense_limit' ),
98
  $hook,
99
  $section_id
100
  );
@@ -104,7 +104,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
104
  add_settings_field(
105
  'adsense-warnings-disable',
106
  __( 'Disable violation warnings', 'advanced-ads' ),
107
- array( $this, 'render_settings_adsense_warnings_disable' ),
108
  $hook,
109
  $section_id
110
  );
@@ -112,7 +112,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
112
  add_settings_field(
113
  'adsense-background',
114
  __( 'Transparent background', 'advanced-ads' ),
115
- array( $this, 'render_settings_adsense_background' ),
116
  $hook,
117
  $section_id
118
  );
@@ -120,7 +120,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
120
  add_settings_field(
121
  'adsense-full-width',
122
  __( 'Full width responsive ads on mobile', 'advanced-ads' ),
123
- array( $this, 'render_settings_adsense_fullwidth' ),
124
  $hook,
125
  'advanced_ads_adsense_setting_section'
126
  );
@@ -281,12 +281,12 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
281
  wp_kses(
282
  /* translators: %s is a URL. */
283
  __( 'Our <a href="%s" target="_blank">Ad Health</a> feature monitors if AdSense is implemented correctly on your site. It also considers ads not managed with Advanced Ads. Enable this option to remove these checks', 'advanced-ads' ),
284
- array(
285
- 'a' => array(
286
  'href' => true,
287
  'target' => true,
288
- ),
289
- )
290
  ),
291
  esc_url( ADVADS_URL ) . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=backend-autoads-ads'
292
  );
@@ -330,12 +330,12 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
330
  __( "Whether your responsive ad unit may expand to <a href='%s' target='blank'>use the full width</a> of your visitor's mobile device screen", 'advanced-ads' ),
331
  esc_url( 'https://support.google.com/adsense/answer/7445870' )
332
  ),
333
- array(
334
- 'a' => array(
335
  'href' => true,
336
  'target' => true,
337
- ),
338
- )
339
  );
340
  ?>
341
  </p>
@@ -377,7 +377,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
377
  // Save AdSense publisher ID if there is no one stored yet.
378
  if ( ! empty( $ad_settings_post['output']['adsense-pub-id'] ) ) {
379
  // Get options.
380
- $adsense_options = get_option( 'advanced-ads-adsense', array() );
381
 
382
  if ( empty( $adsense_options['adsense-id'] ) ) {
383
  $adsense_options['adsense-id'] = $ad_settings_post['output']['adsense-pub-id'];
@@ -406,7 +406,7 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
406
  $db = Advanced_Ads_AdSense_Data::get_instance();
407
  $adsense_id = trim( $db->get_adsense_id() );
408
 
409
- $units = array();
410
  $mapi_options = Advanced_Ads_AdSense_MAPI::get_option();
411
 
412
  if (
@@ -510,13 +510,13 @@ class Advanced_Ads_Network_Adsense extends Advanced_Ads_Ad_Network {
510
  $pub_id = Advanced_Ads_AdSense_Data::get_instance()->get_adsense_id();
511
  $data['pubId'] = $pub_id;
512
  $data['connected'] = $this->is_account_connected();
513
- $data['ad_types'] = array(
514
  'matched_content' => _x( 'Multiplex', 'AdSense ad type', 'advanced-ads' ),
515
  'in_article' => _x( 'In-article', 'AdSense ad type', 'advanced-ads' ),
516
  'in_feed' => _x( 'In-feed', 'AdSense ad type', 'advanced-ads' ),
517
  'display' => _x( 'Display', 'AdSense ad type', 'advanced-ads' ),
518
  'link' => _x( 'Link', 'AdSense ad type', 'advanced-ads' ),
519
- );
520
 
521
  return $data;
522
  }
9
  *
10
  * @var array
11
  */
12
+ private static $status_codes_active = [ 'ACTIVE', 'NEW' ];
13
 
14
  /**
15
  * A globally usable instance, that will be created when calling {$link Advanced_Ads_Ad_Network#get_instance) for the first time
52
  add_settings_field(
53
  'adsense-id',
54
  __( 'AdSense account', 'advanced-ads' ),
55
+ [ $this, 'render_settings_adsense_id' ],
56
  $hook,
57
  $section_id
58
  );
61
  add_settings_field(
62
  'adsense-page-level',
63
  __( 'Auto ads', 'advanced-ads' ),
64
+ [ $this, 'render_settings_adsense_page_level' ],
65
  $hook,
66
  $section_id
67
  );
72
  add_settings_field(
73
  'top_anchor_ad',
74
  __( 'Auto ads', 'advanced-ads' ) . ':&nbsp;' . __( 'Disable top anchor ad', 'advanced-ads' ),
75
+ [ $this, 'render_settings_adsense_top_anchor_ad' ],
76
  $hook,
77
  $section_id
78
  );
82
  add_settings_field(
83
  'hide_stats',
84
  __( 'Disable stats', 'advanced-ads' ),
85
+ [ $this, 'render_settings_adsense_hide_stats' ],
86
  $hook,
87
  $section_id
88
  );
94
  add_settings_field(
95
  'adsense-limit',
96
  __( 'Limit to 3 ads', 'advanced-ads' ),
97
+ [ $this, 'render_settings_adsense_limit' ],
98
  $hook,
99
  $section_id
100
  );
104
  add_settings_field(
105
  'adsense-warnings-disable',
106
  __( 'Disable violation warnings', 'advanced-ads' ),
107
+ [ $this, 'render_settings_adsense_warnings_disable' ],
108
  $hook,
109
  $section_id
110
  );
112
  add_settings_field(
113
  'adsense-background',
114
  __( 'Transparent background', 'advanced-ads' ),
115
+ [ $this, 'render_settings_adsense_background' ],
116
  $hook,
117
  $section_id
118
  );
120
  add_settings_field(
121
  'adsense-full-width',
122
  __( 'Full width responsive ads on mobile', 'advanced-ads' ),
123
+ [ $this, 'render_settings_adsense_fullwidth' ],
124
  $hook,
125
  'advanced_ads_adsense_setting_section'
126
  );
281
  wp_kses(
282
  /* translators: %s is a URL. */
283
  __( 'Our <a href="%s" target="_blank">Ad Health</a> feature monitors if AdSense is implemented correctly on your site. It also considers ads not managed with Advanced Ads. Enable this option to remove these checks', 'advanced-ads' ),
284
+ [
285
+ 'a' => [
286
  'href' => true,
287
  'target' => true,
288
+ ],
289
+ ]
290
  ),
291
  esc_url( ADVADS_URL ) . 'manual/ad-health/?utm_source=advanced-ads&utm_medium=link&utm_campaign=backend-autoads-ads'
292
  );
330
  __( "Whether your responsive ad unit may expand to <a href='%s' target='blank'>use the full width</a> of your visitor's mobile device screen", 'advanced-ads' ),
331
  esc_url( 'https://support.google.com/adsense/answer/7445870' )
332
  ),
333
+ [
334
+ 'a' => [
335
  'href' => true,
336
  'target' => true,
337
+ ],
338
+ ]
339
  );
340
  ?>
341
  </p>
377
  // Save AdSense publisher ID if there is no one stored yet.
378
  if ( ! empty( $ad_settings_post['output']['adsense-pub-id'] ) ) {
379
  // Get options.
380
+ $adsense_options = get_option( 'advanced-ads-adsense', [] );
381
 
382
  if ( empty( $adsense_options['adsense-id'] ) ) {
383
  $adsense_options['adsense-id'] = $ad_settings_post['output']['adsense-pub-id'];
406
  $db = Advanced_Ads_AdSense_Data::get_instance();
407
  $adsense_id = trim( $db->get_adsense_id() );
408
 
409
+ $units = [];
410
  $mapi_options = Advanced_Ads_AdSense_MAPI::get_option();
411
 
412
  if (
510
  $pub_id = Advanced_Ads_AdSense_Data::get_instance()->get_adsense_id();
511
  $data['pubId'] = $pub_id;
512
  $data['connected'] = $this->is_account_connected();
513
+ $data['ad_types'] = [
514
  'matched_content' => _x( 'Multiplex', 'AdSense ad type', 'advanced-ads' ),
515
  'in_article' => _x( 'In-article', 'AdSense ad type', 'advanced-ads' ),
516
  'in_feed' => _x( 'In-feed', 'AdSense ad type', 'advanced-ads' ),
517
  'display' => _x( 'Display', 'AdSense ad type', 'advanced-ads' ),
518
  'link' => _x( 'Link', 'AdSense ad type', 'advanced-ads' ),
519
+ ];
520
 
521
  return $data;
522
  }
modules/gadsense/public/public.php CHANGED
@@ -24,9 +24,9 @@ class Advanced_Ads_AdSense_Public {
24
  */
25
  private function __construct() {
26
  $this->data = Advanced_Ads_AdSense_Data::get_instance();
27
- add_action( 'wp_head', array( $this, 'inject_header' ), 20 );
28
  // Fires before cache-busting frontend is initialized and tracking method is set
29
- add_action( 'wp', array( $this, 'inject_amp_code' ), 20 );
30
  }
31
 
32
  /**
@@ -103,9 +103,9 @@ class Advanced_Ads_AdSense_Public {
103
  * @param boolean
104
  */
105
  $add_publisher_id = apply_filters( 'advanced-ads-adsense-publisher-id', true );
106
- $script_src = add_query_arg( array(
107
  'client' => $add_publisher_id ? esc_attr( $client_id ) : false,
108
- ), 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js' );
109
 
110
  /**
111
  * Allows to override the page-level code.
@@ -125,7 +125,7 @@ class Advanced_Ads_AdSense_Public {
125
  $custom_code = apply_filters(
126
  'advanced-ads-gadsense-page-level-code',
127
  '',
128
- compact( array( 'client_id', 'top_anchor', 'top_anchor_code', 'script_src' ) )
129
  );
130
 
131
  if ( $custom_code ) {
@@ -166,10 +166,10 @@ class Advanced_Ads_AdSense_Public {
166
  }
167
 
168
  // Adds the AdSense Auto ads AMP code to the page (head) in "Reader" mode.
169
- add_action( 'amp_post_template_data', array( $this, 'add_auto_ads_amp_head_script' ) );
170
 
171
  // SmartMag theme (http://theme-sphere.com/smart-mag/documentation/).
172
- add_action( 'bunyad_amp_pre_main', array( $this, 'add_auto_ads_amp_body_script' ) );
173
 
174
  /**
175
  * Add AMP Auto ads body code to footer for `AMP` plugin ( https://wordpress.org/plugins/amp/ )
@@ -180,13 +180,13 @@ class Advanced_Ads_AdSense_Public {
180
  * use `wp_footer` in Transition and Standard mode
181
  * use `amp_post_template_footer` in Reader mode
182
  */
183
- add_action( 'wp_footer', array( $this, 'add_auto_ads_amp_body_script' ) );
184
- add_action( 'amp_post_template_footer', array( $this, 'add_auto_ads_amp_body_script' ) );
185
 
186
  // Other AMP plugins.
187
  } elseif ( function_exists( 'is_wp_amp' ) ) {
188
  // WP AMP — Accelerated Mobile Pages for WordPress and WooCommerce (https://codecanyon.net/item/wp-amp-accelerated-mobile-pages-for-wordpress-and-woocommerce/16278608).
189
- add_action( 'amphtml_after_footer', array( $this, 'add_adsense_auto_ads' ) );
190
  }
191
  }
192
 
24
  */
25
  private function __construct() {
26
  $this->data = Advanced_Ads_AdSense_Data::get_instance();
27
+ add_action( 'wp_head', [ $this, 'inject_header' ], 20 );
28
  // Fires before cache-busting frontend is initialized and tracking method is set
29
+ add_action( 'wp', [ $this, 'inject_amp_code' ], 20 );
30
  }
31
 
32
  /**
103
  * @param boolean
104
  */
105
  $add_publisher_id = apply_filters( 'advanced-ads-adsense-publisher-id', true );
106
+ $script_src = add_query_arg( [
107
  'client' => $add_publisher_id ? esc_attr( $client_id ) : false,
108
+ ], 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js' );
109
 
110
  /**
111
  * Allows to override the page-level code.
125
  $custom_code = apply_filters(
126
  'advanced-ads-gadsense-page-level-code',
127
  '',
128
+ compact( [ 'client_id', 'top_anchor', 'top_anchor_code', 'script_src' ] )
129
  );
130
 
131
  if ( $custom_code ) {
166
  }
167
 
168
  // Adds the AdSense Auto ads AMP code to the page (head) in "Reader" mode.
169
+ add_action( 'amp_post_template_data', [ $this, 'add_auto_ads_amp_head_script' ] );
170
 
171
  // SmartMag theme (http://theme-sphere.com/smart-mag/documentation/).
172
+ add_action( 'bunyad_amp_pre_main', [ $this, 'add_auto_ads_amp_body_script' ] );
173
 
174
  /**
175
  * Add AMP Auto ads body code to footer for `AMP` plugin ( https://wordpress.org/plugins/amp/ )
180
  * use `wp_footer` in Transition and Standard mode
181
  * use `amp_post_template_footer` in Reader mode
182
  */
183
+ add_action( 'wp_footer', [ $this, 'add_auto_ads_amp_body_script' ] );
184
+ add_action( 'amp_post_template_footer', [ $this, 'add_auto_ads_amp_body_script' ] );
185
 
186
  // Other AMP plugins.
187
  } elseif ( function_exists( 'is_wp_amp' ) ) {
188
  // WP AMP — Accelerated Mobile Pages for WordPress and WooCommerce (https://codecanyon.net/item/wp-amp-accelerated-mobile-pages-for-wordpress-and-woocommerce/16278608).
189
+ add_action( 'amphtml_after_footer', [ $this, 'add_adsense_auto_ads' ] );
190
  }
191
  }
192
 
modules/gutenberg/config.php CHANGED
@@ -4,9 +4,9 @@
4
 
5
  $path = dirname( __FILE__ );
6
 
7
- return array(
8
- 'classmap' => array(
9
  'Advanced_Ads_Gutenberg' => $path . '/includes/class-gutenberg.php',
10
- ),
11
  'textdomain' => null,
12
- );
4
 
5
  $path = dirname( __FILE__ );
6
 
7
+ return [
8
+ 'classmap' => [
9
  'Advanced_Ads_Gutenberg' => $path . '/includes/class-gutenberg.php',
10
+ ],
11
  'textdomain' => null,
12
+ ];
modules/gutenberg/includes/class-gutenberg.php CHANGED
@@ -10,8 +10,8 @@ class Advanced_Ads_Gutenberg {
10
  private static $css_class;
11
 
12
  private function __construct() {
13
- add_action( 'init', array( $this, 'init' ) );
14
- add_action( 'enqueue_block_editor_assets', array( $this, 'register_scripts' ) );
15
  }
16
 
17
  /**
@@ -23,10 +23,10 @@ class Advanced_Ads_Gutenberg {
23
  return;
24
  }
25
 
26
- register_block_type( 'advads/gblock', array(
27
  'editor_script' => ADVADS_BASE . '/gutenberg-ad',
28
- 'render_callback' => array( $this, 'render_ad_selector' ),
29
- ) );
30
 
31
  /**
32
  * Removes legacy widget from legacy widget block.
@@ -53,29 +53,29 @@ class Advanced_Ads_Gutenberg {
53
  wp_register_script(
54
  ADVADS_BASE . '/gutenberg-ad',
55
  ADVADS_BASE_URL . 'modules/gutenberg/js/advanced-ads.block.js',
56
- array( 'wp-dom-ready', 'wp-blocks', 'wp-element' )
57
  );
58
 
59
  $model = Advanced_Ads::get_instance()->get_model();
60
 
61
- $all_ads = Advanced_Ads::get_ads( array( 'post_status' => array( 'publish' ), 'orderby' => 'title', 'order' => 'ASC' ) );
62
  $all_groups = $model->get_ad_groups();
63
 
64
- $ads = array();
65
- $groups = array();
66
- $placements = array();
67
 
68
  foreach ( $all_ads as $ad ) {
69
- $ads[] = array( 'id' => $ad->ID, 'title' => $ad->post_title );
70
  }
71
 
72
  foreach ( $all_groups as $gr ) {
73
- $groups[] = array( 'id' => $gr->term_id, 'name' => $gr->name );
74
  }
75
 
76
  foreach ( Advanced_Ads::get_instance()->get_model()->get_ad_placements_array() as $key => $value ) {
77
- if ( in_array( $value['type'], array( 'sidebar_widget', 'default' ), true ) ) {
78
- $placements[] = array( 'id' => $key, 'name' => $value['name'] );
79
  }
80
  }
81
 
@@ -85,26 +85,26 @@ class Advanced_Ads_Gutenberg {
85
  $placements = false;
86
  }
87
 
88
- $i18n = array(
89
  '--empty--' => __( '--empty--', 'advanced-ads' ),
90
  'advads' => __( 'Advanced Ads', 'advanced-ads' ),
91
  'ads' => __( 'Ads', 'advanced-ads' ),
92
  'adGroups' => __( 'Ad Groups', 'advanced-ads' ),
93
  'placements' => __( 'Placements', 'advanced-ads' ),
94
- );
95
 
96
  $inline_script = wp_json_encode(
97
- array(
98
  'ads' => $ads,
99
  'groups' => $groups,
100
  'placements' => $placements,
101
- 'editLinks' => array(
102
  'group' => admin_url( 'admin.php?page=advanced-ads-groups' ),
103
  'placement' => admin_url( 'admin.php?page=advanced-ads-placements' ),
104
  'ad' => admin_url( 'post.php?post=%ID%&action=edit' ),
105
- ),
106
  'i18n' => $i18n
107
- )
108
  );
109
 
110
  // put the inline code with the global variable right before the block's JS file
@@ -125,11 +125,11 @@ class Advanced_Ads_Gutenberg {
125
  return '';
126
  }
127
 
128
- $output = array(
129
- 'output' => array(
130
- 'class' => ! empty( $attr['className'] ) ? array_filter( explode( ' ', $attr['className'] ) ) : array(),
131
- ),
132
- );
133
 
134
  if ( isset( $attr['fixed_widget'] ) ) {
135
  $output['wrapper_attrs']['data-fixed_widget'] = $attr['fixed_widget'];
10
  private static $css_class;
11
 
12
  private function __construct() {
13
+ add_action( 'init', [ $this, 'init' ] );
14
+ add_action( 'enqueue_block_editor_assets', [ $this, 'register_scripts' ] );
15
  }
16
 
17
  /**
23
  return;
24
  }
25
 
26
+ register_block_type( 'advads/gblock', [
27
  'editor_script' => ADVADS_BASE . '/gutenberg-ad',
28
+ 'render_callback' => [ $this, 'render_ad_selector' ],
29
+ ] );
30
 
31
  /**
32
  * Removes legacy widget from legacy widget block.
53
  wp_register_script(
54
  ADVADS_BASE . '/gutenberg-ad',
55
  ADVADS_BASE_URL . 'modules/gutenberg/js/advanced-ads.block.js',
56
+ [ 'wp-dom-ready', 'wp-blocks', 'wp-element' ]
57
  );
58
 
59
  $model = Advanced_Ads::get_instance()->get_model();
60
 
61
+ $all_ads = Advanced_Ads::get_ads( [ 'post_status' => [ 'publish' ], 'orderby' => 'title', 'order' => 'ASC' ] );
62
  $all_groups = $model->get_ad_groups();
63
 
64
+ $ads = [];
65
+ $groups = [];
66
+ $placements = [];
67
 
68
  foreach ( $all_ads as $ad ) {
69
+ $ads[] = [ 'id' => $ad->ID, 'title' => $ad->post_title ];
70
  }
71
 
72
  foreach ( $all_groups as $gr ) {
73
+ $groups[] = [ 'id' => $gr->term_id, 'name' => $gr->name ];
74
  }
75
 
76
  foreach ( Advanced_Ads::get_instance()->get_model()->get_ad_placements_array() as $key => $value ) {
77
+ if ( in_array( $value['type'], [ 'sidebar_widget', 'default' ], true ) ) {
78
+ $placements[] = [ 'id' => $key, 'name' => $value['name'] ];
79
  }
80
  }
81
 
85
  $placements = false;
86
  }
87
 
88
+ $i18n = [
89
  '--empty--' => __( '--empty--', 'advanced-ads' ),
90
  'advads' => __( 'Advanced Ads', 'advanced-ads' ),
91
  'ads' => __( 'Ads', 'advanced-ads' ),
92
  'adGroups' => __( 'Ad Groups', 'advanced-ads' ),
93
  'placements' => __( 'Placements', 'advanced-ads' ),
94
+ ];
95
 
96
  $inline_script = wp_json_encode(
97
+ [
98
  'ads' => $ads,
99
  'groups' => $groups,
100
  'placements' => $placements,
101
+ 'editLinks' => [
102
  'group' => admin_url( 'admin.php?page=advanced-ads-groups' ),
103
  'placement' => admin_url( 'admin.php?page=advanced-ads-placements' ),
104
  'ad' => admin_url( 'post.php?post=%ID%&action=edit' ),
105
+ ],
106
  'i18n' => $i18n
107
+ ]
108
  );
109
 
110
  // put the inline code with the global variable right before the block's JS file
125
  return '';
126
  }
127
 
128
+ $output = [
129
+ 'output' => [
130
+ 'class' => ! empty( $attr['className'] ) ? array_filter( explode( ' ', $attr['className'] ) ) : [],
131
+ ],
132
+ ];
133
 
134
  if ( isset( $attr['fixed_widget'] ) ) {
135
  $output['wrapper_attrs']['data-fixed_widget'] = $attr['fixed_widget'];
modules/import-export/classes/XmlEncoder.php CHANGED
@@ -56,7 +56,7 @@ class Advanced_Ads_XmlEncoder
56
  }
57
 
58
 
59
- public function encode( $data, $options = array()) {
60
  if ( ! extension_loaded( 'simplexml' ) ) {
61
  throw new Exception( sprintf( __( 'The %s extension(s) is not loaded', 'advanced-ads' ), 'simplexml' ) );
62
  }
@@ -262,7 +262,7 @@ class Advanced_Ads_XmlEncoder
262
  */
263
  private function parseXml(DOMNode $node) {
264
  // Parse the input DOMNode value (content and children) into an array or a string
265
- $data = array();
266
  if ( $node->hasAttributes() ) {
267
  foreach ($node->attributes as $attr) {
268
  if (ctype_digit($attr->nodeValue)) {
@@ -279,12 +279,12 @@ class Advanced_Ads_XmlEncoder
279
  // Parse the input DOMNode value (content and children) into an array or a string.
280
  if (!$node->hasChildNodes()) {
281
  $value = $node->nodeValue;
282
- } elseif (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, array(XML_TEXT_NODE, XML_CDATA_SECTION_NODE))) {
283
  $value = $node->firstChild->nodeValue;
284
  } else {
285
 
286
 
287
- $value = array();
288
 
289
  foreach ($node->childNodes as $subnode) {
290
  $val = $this->parseXml($subnode);
@@ -338,7 +338,7 @@ class Advanced_Ads_XmlEncoder
338
  if ( $type === 'string' ) return (string) $text;
339
  if ( $type === 'numeric' ) return 0 + $text;
340
  if ( $type === 'boolean' ) return (boolean) $text;
341
- if ( $type === 'array' && $text=== '' ) return array();
342
  if ( $type === 'null' ) return 'null';
343
  return $text;
344
  }
56
  }
57
 
58
 
59
+ public function encode( $data, $options = []) {
60
  if ( ! extension_loaded( 'simplexml' ) ) {
61
  throw new Exception( sprintf( __( 'The %s extension(s) is not loaded', 'advanced-ads' ), 'simplexml' ) );
62
  }
262
  */
263
  private function parseXml(DOMNode $node) {
264
  // Parse the input DOMNode value (content and children) into an array or a string
265
+ $data = [];
266
  if ( $node->hasAttributes() ) {
267
  foreach ($node->attributes as $attr) {
268
  if (ctype_digit($attr->nodeValue)) {
279
  // Parse the input DOMNode value (content and children) into an array or a string.
280
  if (!$node->hasChildNodes()) {
281
  $value = $node->nodeValue;
282
+ } elseif (1 === $node->childNodes->length && in_array($node->firstChild->nodeType, [XML_TEXT_NODE, XML_CDATA_SECTION_NODE])) {
283
  $value = $node->firstChild->nodeValue;
284
  } else {
285
 
286
 
287
+ $value = [];
288
 
289
  foreach ($node->childNodes as $subnode) {
290
  $val = $this->parseXml($subnode);
338
  if ( $type === 'string' ) return (string) $text;
339
  if ( $type === 'numeric' ) return 0 + $text;
340
  if ( $type === 'boolean' ) return (boolean) $text;
341
+ if ( $type === 'array' && $text=== '' ) return [];
342
  if ( $type === 'null' ) return 'null';
343
  return $text;
344
  }
modules/import-export/classes/export.php CHANGED
@@ -11,13 +11,13 @@ class Advanced_Ads_Export {
11
  /**
12
  * Status messages
13
  */
14
- private $messages = array();
15
 
16
  private function __construct() {
17
 
18
  $page_hook = 'admin_page_advanced-ads-import-export';
19
  // execute before headers are sent
20
- add_action( 'load-' . $page_hook, array( $this, 'download_export_file' ) );
21
  }
22
 
23
  /**
@@ -60,14 +60,14 @@ class Advanced_Ads_Export {
60
  @set_time_limit( 0 );
61
  @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
62
 
63
- $export = array();
64
- $advads_ad_groups = get_option( 'advads-ad-groups', array() );
65
 
66
  if ( in_array( 'ads', $content ) ) {
67
- $advads_ad_weights = get_option( 'advads-ad-weights', array() );
68
 
69
- $ads = array();
70
- $export_fields = implode( ', ', array(
71
  'ID',
72
  'post_date',
73
  'post_date_gmt',
@@ -79,7 +79,7 @@ class Advanced_Ads_Export {
79
  'post_modified',
80
  'post_modified_gmt',
81
  'guid'
82
- ) );
83
 
84
  $posts = $wpdb->get_results( $wpdb->prepare( "SELECT $export_fields FROM {$wpdb->posts} where post_type = '%s' and post_status not in ('trash', 'auto-draft')", Advanced_Ads::POST_TYPE_SLUG ), ARRAY_A );
85
 
@@ -99,11 +99,11 @@ class Advanced_Ads_Export {
99
  $terms = wp_get_object_terms( $post['ID'], 'advanced_ads_groups' );
100
 
101
  foreach ( (array) $terms as $term ) {
102
- $group_info = array(
103
  'term_id' => $term->term_id,
104
  'slug' => $term->slug,
105
  'name' => $term->name,
106
- );
107
 
108
  if ( isset( $advads_ad_groups[ $term->term_id ] ) ) {
109
  $group_info += $advads_ad_groups[ $term->term_id ];
@@ -146,11 +146,11 @@ class Advanced_Ads_Export {
146
  if ( in_array( 'groups', $content ) ) {
147
  $terms = Advanced_Ads::get_instance()->get_model()->get_ad_groups();
148
  foreach ( $terms as $term ) {
149
- $group_info = array(
150
  'term_id' => $term->term_id,
151
  'slug' => $term->slug,
152
  'name' => $term->name,
153
- );
154
 
155
  if ( isset( $advads_ad_groups[ $term->term_id ] ) ) {
156
  $group_info += $advads_ad_groups[ $term->term_id ];
@@ -177,15 +177,15 @@ class Advanced_Ads_Export {
177
  *
178
  * @param $options An array of options
179
  */
180
- $export['options'] = array_filter( apply_filters( 'advanced-ads-export-options', array(
181
  ADVADS_SLUG => get_option( ADVADS_SLUG ),
182
  GADSENSE_OPT_NAME => get_option( GADSENSE_OPT_NAME ),
183
  Advanced_Ads_Privacy::OPTION_KEY => get_option( Advanced_Ads_Privacy::OPTION_KEY ),
184
  Advanced_Ads_Ads_Txt_Strategy::OPTION => get_option( Advanced_Ads_Ads_Txt_Strategy::OPTION ),
185
- ) ) );
186
  }
187
 
188
- do_action_ref_array( 'advanced-ads-export', array( $content, &$export ) );
189
 
190
  if ( $export ) {
191
  if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
@@ -196,7 +196,7 @@ class Advanced_Ads_Export {
196
  $filename = 'advanced-ads-' . date( 'Y-m-d' ) . '.xml';
197
 
198
  try {
199
- $encoded = Advanced_Ads_XmlEncoder::get_instance()->encode( $export, array( 'encoding' => get_option( 'blog_charset' ) ) );
200
 
201
  header( 'Content-Description: File Transfer' );
202
  header( 'Content-Disposition: attachment; filename=' . $filename );
@@ -212,7 +212,7 @@ class Advanced_Ads_Export {
212
  exit();
213
 
214
  } catch ( Exception $e ) {
215
- $this->messages[] = array( 'error', $e->getMessage() );
216
  }
217
  }
218
  }
11
  /**
12
  * Status messages
13
  */
14
+ private $messages = [];
15
 
16
  private function __construct() {
17
 
18
  $page_hook = 'admin_page_advanced-ads-import-export';
19
  // execute before headers are sent
20
+ add_action( 'load-' . $page_hook, [ $this, 'download_export_file' ] );
21
  }
22
 
23
  /**
60
  @set_time_limit( 0 );
61
  @ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
62
 
63
+ $export = [];
64
+ $advads_ad_groups = get_option( 'advads-ad-groups', [] );
65
 
66
  if ( in_array( 'ads', $content ) ) {
67
+ $advads_ad_weights = get_option( 'advads-ad-weights', [] );
68
 
69
+ $ads = [];
70
+ $export_fields = implode( ', ', [
71
  'ID',
72
  'post_date',
73
  'post_date_gmt',
79
  'post_modified',
80
  'post_modified_gmt',
81
  'guid'
82
+ ] );
83
 
84
  $posts = $wpdb->get_results( $wpdb->prepare( "SELECT $export_fields FROM {$wpdb->posts} where post_type = '%s' and post_status not in ('trash', 'auto-draft')", Advanced_Ads::POST_TYPE_SLUG ), ARRAY_A );
85
 
99
  $terms = wp_get_object_terms( $post['ID'], 'advanced_ads_groups' );
100
 
101
  foreach ( (array) $terms as $term ) {
102
+ $group_info = [
103
  'term_id' => $term->term_id,
104
  'slug' => $term->slug,
105
  'name' => $term->name,
106
+ ];
107
 
108
  if ( isset( $advads_ad_groups[ $term->term_id ] ) ) {
109
  $group_info += $advads_ad_groups[ $term->term_id ];
146
  if ( in_array( 'groups', $content ) ) {
147
  $terms = Advanced_Ads::get_instance()->get_model()->get_ad_groups();
148
  foreach ( $terms as $term ) {
149
+ $group_info = [
150
  'term_id' => $term->term_id,
151
  'slug' => $term->slug,
152
  'name' => $term->name,
153
+ ];
154
 
155
  if ( isset( $advads_ad_groups[ $term->term_id ] ) ) {
156
  $group_info += $advads_ad_groups[ $term->term_id ];
177
  *
178
  * @param $options An array of options
179
  */
180
+ $export['options'] = array_filter( apply_filters( 'advanced-ads-export-options', [
181
  ADVADS_SLUG => get_option( ADVADS_SLUG ),
182
  GADSENSE_OPT_NAME => get_option( GADSENSE_OPT_NAME ),
183
  Advanced_Ads_Privacy::OPTION_KEY => get_option( Advanced_Ads_Privacy::OPTION_KEY ),
184
  Advanced_Ads_Ads_Txt_Strategy::OPTION => get_option( Advanced_Ads_Ads_Txt_Strategy::OPTION ),
185
+ ] ) );
186
  }
187
 
188
+ do_action_ref_array( 'advanced-ads-export', [ $content, &$export ] );
189
 
190
  if ( $export ) {
191
  if ( defined( 'IMPORT_DEBUG' ) && IMPORT_DEBUG ) {
196
  $filename = 'advanced-ads-' . date( 'Y-m-d' ) . '.xml';
197
 
198
  try {
199
+ $encoded = Advanced_Ads_XmlEncoder::get_instance()->encode( $export, [ 'encoding' => get_option( 'blog_charset' ) ] );
200
 
201
  header( 'Content-Description: File Transfer' );
202
  header( 'Content-Disposition: attachment; filename=' . $filename );
212
  exit();
213
 
214
  } catch ( Exception $e ) {
215
+ $this->messages[] = [ 'error', $e->getMessage() ];
216
  }
217
  }
218
  }
modules/import-export/classes/import.php CHANGED
@@ -17,26 +17,26 @@ class Advanced_Ads_Import {
17
  /**
18
  * Status messages
19
  */
20
- private $messages = array();
21
 
22
  /**
23
  * Imported data mapped with previous data, e.g. ['ads'][ new_ad_id => old_ad_id (or null if does not exist) ]
24
  */
25
- public $imported_data = array(
26
- 'ads' => array(),
27
- 'groups' => array(),
28
- 'placements' => array()
29
- );
30
 
31
  /**
32
  * Created groups during this import session ['slug' => 'id']
33
  */
34
- private $created_groups = array();
35
 
36
  /**
37
  * Attachments, created for Image Ads and images in ad content
38
  */
39
- private $created_attachments = array();
40
 
41
  private function __construct() {}
42
 
@@ -67,7 +67,7 @@ class Advanced_Ads_Import {
67
  switch ( $_POST['import_type'] ) {
68
  case 'xml_content':
69
  if ( empty( $_POST['xml_textarea'] ) ) {
70
- $this->messages[] = array( 'error', __( 'Please enter XML content', 'advanced-ads' ) );
71
  return;
72
  }
73
  // see wp_magic_quotes()
@@ -104,7 +104,7 @@ class Advanced_Ads_Import {
104
  $decoded = Advanced_Ads_XmlEncoder::get_instance()->decode( $xml_content );
105
  } catch ( Exception $e ) {
106
  error_log( $e->getMessage() );
107
- $this->messages[] = array ( 'error', $e->getMessage() );
108
  return;
109
  }
110
 
@@ -118,7 +118,7 @@ class Advanced_Ads_Import {
118
  $this->import_placements( $decoded );
119
  $this->import_options( $decoded );
120
 
121
- do_action_ref_array( 'advanced-ads-import', array( &$decoded, &$this->imported_data, &$this->messages ) );
122
 
123
  wp_cache_flush();
124
  }
@@ -151,7 +151,7 @@ class Advanced_Ads_Import {
151
  $attachment_id = $this->created_attachments[ $attached_img_url ]['post_id'];
152
  } else if ( $attachment = $this->upload_image_from_url( $attached_img_url ) ) {
153
  $link = ( $link = get_attachment_link( $attachment['post_id'] ) ) ? sprintf( '<a href="%s">%s</a>', esc_url( $link ), __( 'Edit', 'advanced-ads' ) ) : '';
154
- $this->messages[] = array( 'update', sprintf( __( 'New attachment created <em>%s</em> %s', 'advanced-ads' ), $attachment['post_id'], $link ) );
155
  $this->created_attachments[ $attached_img_url ] = $attachment;
156
  $attachment_id = $attachment['post_id'];
157
  }
@@ -161,7 +161,7 @@ class Advanced_Ads_Import {
161
  }
162
  }
163
 
164
- $insert_ad = array(
165
  'post_title' => $ad_title,
166
  'post_date' => $ad_date,
167
  'post_date_gmt' => isset( $ad['post_date_gmt'] ) ? $ad['post_date_gmt'] : '',
@@ -177,21 +177,21 @@ class Advanced_Ads_Import {
177
  'comment_status' => 'closed',
178
  'ping_status' => 'closed',
179
  'meta_input' => isset( $ad['meta_input'] ) ? $ad['meta_input'] : '',
180
- );
181
 
182
 
183
  $post_id = wp_insert_post( $insert_ad, true );
184
 
185
  if ( is_wp_error( $post_id ) ) {
186
- $this->messages[] = array( 'error', sprintf( __( 'Failed to import <em>%s</em>', 'advanced-ads' ), esc_html($ad['post_title'] ) ) );
187
  if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
188
- $this->messages[] = array( 'error', ' > ' . $post_id->get_error_message() );
189
  }
190
 
191
  continue;
192
  } else {
193
  $link = ( $link = get_edit_post_link( $post_id ) ) ? sprintf( '<a href="%s">%s</a>', esc_url( $link ), __( 'Edit', 'advanced-ads' ) ) : '';
194
- $this->messages[] = array( 'update', sprintf( __( 'New ad created: <em>%s</em> %s', 'advanced-ads' ), $post_id, $link ) );
195
  }
196
 
197
  // new ad id => old ad id, if exists
@@ -199,9 +199,9 @@ class Advanced_Ads_Import {
199
 
200
  // import ad groups
201
  if ( ! empty( $ad['groups'] ) && is_array( $ad['groups'] ) ) {
202
- $groups_to_set = array();
203
- $advads_ad_groups = get_option( 'advads-ad-groups', array() );
204
- $advads_ad_weights = get_option( 'advads-ad-weights', array() );
205
 
206
  foreach ( $ad['groups'] as $_group ) {
207
  if ( ! $group_id = $this->create_group_term( $_group ) ) {
@@ -219,11 +219,11 @@ class Advanced_Ads_Import {
219
  }
220
 
221
  if ( ! isset( $advads_ad_groups[ $group_id ] ) ) {
222
- $advads_ad_groups[ $group_id ] = array (
223
  'type' => isset( $_group['type']) ? $_group['type'] : 'default',
224
  'ad_count' => isset($_group['ad_count']) ? $_group['ad_count'] : 1,
225
- 'options' => isset($_group['options']) ? $_group['options'] : array()
226
- );
227
 
228
  update_option( 'advads-ad-groups', $advads_ad_groups );
229
  }
@@ -234,7 +234,7 @@ class Advanced_Ads_Import {
234
 
235
  update_option( 'advads-ad-weights', $advads_ad_weights );
236
 
237
- $this->messages[] = array( 'update', sprintf( __( 'Assigned terms: <em>%s</em>, to post: <em>%s</em>', 'advanced-ads' ), implode(',',$groups_to_set), $post_id ) );
238
 
239
  $tt_ids = wp_set_post_terms( $post_id, $groups_to_set, Advanced_Ads::AD_GROUP_TAXONOMY );
240
  }
@@ -249,16 +249,16 @@ class Advanced_Ads_Import {
249
  */
250
  private function import_empty_groups( &$decoded ) {
251
  if ( isset( $decoded['groups'] ) && is_array( $decoded['groups'] ) ) {
252
- $advads_ad_groups = get_option( 'advads-ad-groups', array() );
253
 
254
  foreach ( $decoded['groups'] as $_group ) {
255
  if ( $group_id = $this->create_group_term( $_group ) ) {
256
  if ( ! isset( $advads_ad_groups[ $group_id ] ) ) {
257
- $advads_ad_groups[ $group_id ] = array (
258
  'type' => isset( $_group['type']) ? $_group['type'] : 'default',
259
  'ad_count' => isset( $_group['ad_count'] ) ? $_group['ad_count'] : 1,
260
- 'options' => isset( $_group['options'] ) ? $_group['options'] : array()
261
- );
262
  }
263
  }
264
  }
@@ -291,16 +291,16 @@ class Advanced_Ads_Import {
291
  $slug = $slug . '_' . $count;
292
  }
293
 
294
- $t = wp_insert_term( $_group['name'], Advanced_Ads::AD_GROUP_TAXONOMY, array( 'slug' => $slug) );
295
 
296
  if ( ! is_wp_error( $t ) ) {
297
  $this->created_groups[ $original_slug ] = $t['term_id'];
298
  $group_id = $t['term_id'];
299
- $this->messages[] = array( 'update', sprintf( __( 'New group created, id: <em>%s</em>, name: <em>%s</em>', 'advanced-ads' ), $group_id, esc_html( $_group['name'] ) ) );
300
  } else {
301
- $this->messages[] = array( 'error', sprintf( __( 'Failed to import taxonomy: <em>%s</em>, term: <em>%s</em>', 'advanced-ads' ), esc_html(Advanced_Ads::AD_GROUP_TAXONOMY), esc_html($_group['name'] ) ) );
302
  if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
303
- $this->messages[] = array( 'error', ' > ' . $t->get_error_message() );
304
  }
305
 
306
  return false;
@@ -363,7 +363,7 @@ class Advanced_Ads_Import {
363
  $placement_key_uniq .= '_' . $count;
364
  }
365
 
366
- $this->messages[] = array( 'update', sprintf( __( 'Placement <em>%s</em> created', 'advanced-ads' ), esc_html( $placement['name'] ) ) );
367
 
368
  // new placement key => old placement key
369
  $this->imported_data['placements'][ $placement_key_uniq ] = $placement['key'];
@@ -391,7 +391,7 @@ class Advanced_Ads_Import {
391
  $_item_existing = explode( '_', $placement['item'] );
392
 
393
  if ( ! empty( $_item_existing[1] ) && $_item_existing[0] === Advanced_Ads_Select::GROUP ) {
394
- $advads_ad_weights = get_option( 'advads-ad-weights', array() );
395
 
396
  if ( term_exists( absint( $_item_existing[1] ), Advanced_Ads::AD_GROUP_TAXONOMY ) ) {
397
  wp_set_post_terms( $found, $_item_existing[1], Advanced_Ads::AD_GROUP_TAXONOMY, true );
@@ -495,19 +495,19 @@ class Advanced_Ads_Import {
495
  continue;
496
  }
497
 
498
- $existing_option = get_option( $option_name, array() );
499
 
500
  if ( ! is_array( $imported_option ) ) {
501
- $imported_option = array();
502
  }
503
  if ( ! is_array( $existing_option ) ) {
504
- $existing_option = array();
505
  }
506
 
507
  $option_to_import = array_merge( $existing_option, $imported_option );
508
 
509
  /* translators: %s: Option name. */
510
- $this->messages[] = array( 'update', sprintf( __( 'Option was updated: <em>%s</em>', 'advanced-ads' ), $option_name ) );
511
  update_option( $option_name, maybe_unserialize( $option_to_import ) );
512
  }
513
  }
@@ -521,7 +521,7 @@ class Advanced_Ads_Import {
521
  private function handle_upload() {
522
  $uploads_dir = wp_upload_dir();
523
  if ( ! empty( $uploads_dir['error'] ) ) {
524
- $this->messages[] = array( 'error', $uploads_dir['error'] );
525
  return;
526
  }
527
 
@@ -529,12 +529,12 @@ class Advanced_Ads_Import {
529
  $this->import_id = $import_dir . '/' . md5( time() . NONCE_SALT );
530
 
531
  if ( ! is_dir( $import_dir) && ! wp_mkdir_p( $import_dir ) ) {
532
- $this->messages[] = array( 'error', sprintf( __( 'Failed to create import directory <em>%s</em>', 'advanced-ads' ), $import_dir ) );
533
  return;
534
  }
535
 
536
  if ( ! is_writable( $import_dir ) ) {
537
- $this->messages[] = array( 'error', sprintf( __( 'Import directory is not writable: <em>%s</em>', 'advanced-ads' ), $import_dir ) );
538
  return;
539
  }
540
 
@@ -542,7 +542,7 @@ class Advanced_Ads_Import {
542
 
543
 
544
  if ( ! isset( $_FILES['import'] ) ) {
545
- $this->messages[] = array( 'error', __( 'File is empty, uploads are disabled or post_max_size is smaller than upload_max_filesize in php.ini', 'advanced-ads' ) );
546
  return;
547
  }
548
 
@@ -552,17 +552,17 @@ class Advanced_Ads_Import {
552
  $file = apply_filters( "wp_handle_upload_prefilter", $file );
553
 
554
  if ( ! empty( $file['error'] ) ) {
555
- $this->messages[] = array( 'error', sprintf( __( 'Failed to upload file, error: <em>%s</em>', 'advanced-ads' ), $file['error'] ) );
556
  return;
557
  }
558
 
559
  if ( ! ( $file['size'] > 0 ) ) {
560
- $this->messages[] = array( 'error', __( 'File is empty.', 'advanced-ads' ), $file['error'] );
561
  return;
562
  }
563
 
564
  if ( ! is_uploaded_file( $file['tmp_name'] ) || ! @ move_uploaded_file( $file['tmp_name'], $this->import_id ) || ! is_readable( $this->import_id ) ) {
565
- $this->messages[] = array( 'error', sprintf( __( 'The file could not be created: <em>%s</em>. This is probably a permissions problem', 'advanced-ads' ), $this->import_id ) );
566
  return;
567
  }
568
 
@@ -572,7 +572,7 @@ class Advanced_Ads_Import {
572
  @ chmod( $this->import_id, $perms );
573
 
574
  // cleanup in case of failed import
575
- wp_schedule_single_event( time() + 10 * MINUTE_IN_SECONDS, 'advanced-ads-cleanup-import-file', array( $this->import_id ) );
576
 
577
  return true;
578
  }
@@ -585,7 +585,7 @@ class Advanced_Ads_Import {
585
  */
586
  private function process_ad_content( $content ) {
587
  // download images, replace old image urls with urls of these new images
588
- $replacement_map = array();
589
 
590
  if ( preg_match_all( '/\<advads_import_img\>(\S+?)\<\/advads_import_img\>/i', $content, $matches ) ) {
591
  foreach ( $matches[1] as $k => $url ) {
@@ -593,14 +593,14 @@ class Advanced_Ads_Import {
593
  $replacement_map[ $url ] = $this->created_attachments[ $url ]['attachment_url'];
594
  } else if ( $attachment = $this->upload_image_from_url( $url ) ) {
595
  $link = ( $link = get_attachment_link( $attachment['post_id'] ) ) ? sprintf( '<a href="%s">%s</a>', esc_url( $link ), __( 'Edit', 'advanced-ads' ) ) : '';
596
- $this->messages[] = array( 'update', sprintf( __( 'New attachment created <em>%s</em> %s', 'advanced-ads' ), $attachment['post_id'], $link ) );
597
  $this->created_attachments[ $url ] = $attachment;
598
  $replacement_map[ $url ] = $attachment['attachment_url'];
599
  }
600
  }
601
  }
602
 
603
- $content = str_replace( array( '<advads_import_img>', '</advads_import_img>' ), '', $content );
604
 
605
  if ( count( $replacement_map ) ) {
606
  $content = str_replace( array_keys( $replacement_map ), array_values( $replacement_map ), $content );
@@ -635,19 +635,19 @@ class Advanced_Ads_Import {
635
 
636
 
637
  if ( ! $wp_filetype['type'] ) {
638
- $this->messages[] = array( 'error', sprintf( __( 'Invalid filetype <em>%s</em>', 'advanced-ads' ), $image_url ) );
639
  return false;
640
  }
641
 
642
  if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
643
- $this->messages[] = array( 'error', sprintf( __( 'Error getting remote image <em>%s</em>', 'advanced-ads' ), $image_url ) );
644
  return false;
645
  }
646
 
647
- $response = wp_safe_remote_get( $image_url, array( 'timeout' => 20 ) );
648
 
649
  if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
650
- $this->messages[] = array( 'error', sprintf( __( 'Error getting remote image <em>%s</em>', 'advanced-ads' ), $image_url ) );
651
  return false;
652
  }
653
 
@@ -655,7 +655,7 @@ class Advanced_Ads_Import {
655
  $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
656
 
657
  if ( $upload['error'] ) {
658
- $this->messages[] = array( 'error', sprintf( __( 'Error getting remote image <em>%s</em>', 'advanced-ads' ), $image_url ) );
659
  return false;
660
  }
661
 
@@ -664,7 +664,7 @@ class Advanced_Ads_Import {
664
 
665
  if ( 0 == $filesize ) {
666
  @unlink( $upload['file'] );
667
- $this->messages[] = array( 'error', sprintf( __( 'Zero size file downloaded <em>%s</em>', 'advanced-ads' ), $image_url ) );
668
  return false;
669
  }
670
 
@@ -681,17 +681,17 @@ class Advanced_Ads_Import {
681
  if ( ! $fileinfo || ! in_array( $fileinfo['mime'], $mime_types, true ) ) {
682
  @unlink( $upload['file'] );
683
  /* translators: 1: image url */
684
- $this->messages[] = array( 'error', sprintf( __( 'Error getting remote image <em>%s</em>', 'advanced-ads' ), $image_url ) );
685
 
686
  return false;
687
  }
688
 
689
  // create new post
690
- $new_post = array(
691
  'post_title' => $file_name,
692
  'post_mime_type' => $wp_filetype['type'],
693
  'guid' => $upload['url'],
694
- );
695
 
696
  if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
697
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
@@ -700,7 +700,7 @@ class Advanced_Ads_Import {
700
  $post_id = wp_insert_attachment( $new_post, $upload['file'] );
701
  wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) );
702
 
703
- return array( 'post_id' => $post_id, 'attachment_url' => wp_get_attachment_url( $post_id ) );
704
  }
705
 
706
  public function get_messages(){
17
  /**
18
  * Status messages
19
  */
20
+ private $messages = [];
21
 
22
  /**
23
  * Imported data mapped with previous data, e.g. ['ads'][ new_ad_id => old_ad_id (or null if does not exist) ]
24
  */
25
+ public $imported_data = [
26
+ 'ads' => [],
27
+ 'groups' => [],
28
+ 'placements' => []
29
+ ];
30
 
31
  /**
32
  * Created groups during this import session ['slug' => 'id']
33
  */
34
+ private $created_groups = [];
35
 
36
  /**
37
  * Attachments, created for Image Ads and images in ad content
38
  */
39
+ private $created_attachments = [];
40
 
41
  private function __construct() {}
42
 
67
  switch ( $_POST['import_type'] ) {
68
  case 'xml_content':
69
  if ( empty( $_POST['xml_textarea'] ) ) {
70
+ $this->messages[] = [ 'error', __( 'Please enter XML content', 'advanced-ads' ) ];
71
  return;
72
  }
73
  // see wp_magic_quotes()
104
  $decoded = Advanced_Ads_XmlEncoder::get_instance()->decode( $xml_content );
105
  } catch ( Exception $e ) {
106
  error_log( $e->getMessage() );
107
+ $this->messages[] = [ 'error', $e->getMessage() ];
108
  return;
109
  }
110
 
118
  $this->import_placements( $decoded );
119
  $this->import_options( $decoded );
120
 
121
+ do_action_ref_array( 'advanced-ads-import', [ &$decoded, &$this->imported_data, &$this->messages ] );
122
 
123
  wp_cache_flush();
124
  }
151
  $attachment_id = $this->created_attachments[ $attached_img_url ]['post_id'];
152
  } else if ( $attachment = $this->upload_image_from_url( $attached_img_url ) ) {
153
  $link = ( $link = get_attachment_link( $attachment['post_id'] ) ) ? sprintf( '<a href="%s">%s</a>', esc_url( $link ), __( 'Edit', 'advanced-ads' ) ) : '';
154
+ $this->messages[] = [ 'update', sprintf( __( 'New attachment created <em>%s</em> %s', 'advanced-ads' ), $attachment['post_id'], $link ) ];
155
  $this->created_attachments[ $attached_img_url ] = $attachment;
156
  $attachment_id = $attachment['post_id'];
157
  }
161
  }
162
  }
163
 
164
+ $insert_ad = [
165
  'post_title' => $ad_title,
166
  'post_date' => $ad_date,
167
  'post_date_gmt' => isset( $ad['post_date_gmt'] ) ? $ad['post_date_gmt'] : '',
177
  'comment_status' => 'closed',
178
  'ping_status' => 'closed',
179
  'meta_input' => isset( $ad['meta_input'] ) ? $ad['meta_input'] : '',
180
+ ];
181
 
182
 
183
  $post_id = wp_insert_post( $insert_ad, true );
184
 
185
  if ( is_wp_error( $post_id ) ) {
186
+ $this->messages[] = [ 'error', sprintf( __( 'Failed to import <em>%s</em>', 'advanced-ads' ), esc_html($ad['post_title'] ) ) ];
187
  if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
188
+ $this->messages[] = [ 'error', ' > ' . $post_id->get_error_message() ];
189
  }
190
 
191
  continue;
192
  } else {
193
  $link = ( $link = get_edit_post_link( $post_id ) ) ? sprintf( '<a href="%s">%s</a>', esc_url( $link ), __( 'Edit', 'advanced-ads' ) ) : '';
194
+ $this->messages[] = [ 'update', sprintf( __( 'New ad created: <em>%s</em> %s', 'advanced-ads' ), $post_id, $link ) ];
195
  }
196
 
197
  // new ad id => old ad id, if exists
199
 
200
  // import ad groups
201
  if ( ! empty( $ad['groups'] ) && is_array( $ad['groups'] ) ) {
202
+ $groups_to_set = [];
203
+ $advads_ad_groups = get_option( 'advads-ad-groups', [] );
204
+ $advads_ad_weights = get_option( 'advads-ad-weights', [] );
205
 
206
  foreach ( $ad['groups'] as $_group ) {
207
  if ( ! $group_id = $this->create_group_term( $_group ) ) {
219
  }
220
 
221
  if ( ! isset( $advads_ad_groups[ $group_id ] ) ) {
222
+ $advads_ad_groups[ $group_id ] = [
223
  'type' => isset( $_group['type']) ? $_group['type'] : 'default',
224
  'ad_count' => isset($_group['ad_count']) ? $_group['ad_count'] : 1,
225
+ 'options' => isset($_group['options']) ? $_group['options'] : []
226
+ ];
227
 
228
  update_option( 'advads-ad-groups', $advads_ad_groups );
229
  }
234
 
235
  update_option( 'advads-ad-weights', $advads_ad_weights );
236
 
237
+ $this->messages[] = [ 'update', sprintf( __( 'Assigned terms: <em>%s</em>, to post: <em>%s</em>', 'advanced-ads' ), implode(',',$groups_to_set), $post_id ) ];
238
 
239
  $tt_ids = wp_set_post_terms( $post_id, $groups_to_set, Advanced_Ads::AD_GROUP_TAXONOMY );
240
  }
249
  */
250
  private function import_empty_groups( &$decoded ) {
251
  if ( isset( $decoded['groups'] ) && is_array( $decoded['groups'] ) ) {
252
+ $advads_ad_groups = get_option( 'advads-ad-groups', [] );
253
 
254
  foreach ( $decoded['groups'] as $_group ) {
255
  if ( $group_id = $this->create_group_term( $_group ) ) {
256
  if ( ! isset( $advads_ad_groups[ $group_id ] ) ) {
257
+ $advads_ad_groups[ $group_id ] = [
258
  'type' => isset( $_group['type']) ? $_group['type'] : 'default',
259
  'ad_count' => isset( $_group['ad_count'] ) ? $_group['ad_count'] : 1,
260
+ 'options' => isset( $_group['options'] ) ? $_group['options'] : []
261
+ ];
262
  }
263
  }
264
  }
291
  $slug = $slug . '_' . $count;
292
  }
293
 
294
+ $t = wp_insert_term( $_group['name'], Advanced_Ads::AD_GROUP_TAXONOMY, [ 'slug' => $slug] );
295
 
296
  if ( ! is_wp_error( $t ) ) {
297
  $this->created_groups[ $original_slug ] = $t['term_id'];
298
  $group_id = $t['term_id'];
299
+ $this->messages[] = [ 'update', sprintf( __( 'New group created, id: <em>%s</em>, name: <em>%s</em>', 'advanced-ads' ), $group_id, esc_html( $_group['name'] ) ) ];
300
  } else {
301
+ $this->messages[] = [ 'error', sprintf( __( 'Failed to import taxonomy: <em>%s</em>, term: <em>%s</em>', 'advanced-ads' ), esc_html(Advanced_Ads::AD_GROUP_TAXONOMY), esc_html($_group['name'] ) ) ];
302
  if ( defined('IMPORT_DEBUG') && IMPORT_DEBUG ) {
303
+ $this->messages[] = [ 'error', ' > ' . $t->get_error_message() ];
304
  }
305
 
306
  return false;
363
  $placement_key_uniq .= '_' . $count;
364
  }
365
 
366
+ $this->messages[] = [ 'update', sprintf( __( 'Placement <em>%s</em> created', 'advanced-ads' ), esc_html( $placement['name'] ) ) ];
367
 
368
  // new placement key => old placement key
369
  $this->imported_data['placements'][ $placement_key_uniq ] = $placement['key'];
391
  $_item_existing = explode( '_', $placement['item'] );
392
 
393
  if ( ! empty( $_item_existing[1] ) && $_item_existing[0] === Advanced_Ads_Select::GROUP ) {
394
+ $advads_ad_weights = get_option( 'advads-ad-weights', [] );
395
 
396
  if ( term_exists( absint( $_item_existing[1] ), Advanced_Ads::AD_GROUP_TAXONOMY ) ) {
397
  wp_set_post_terms( $found, $_item_existing[1], Advanced_Ads::AD_GROUP_TAXONOMY, true );
495
  continue;
496
  }
497
 
498
+ $existing_option = get_option( $option_name, [] );
499
 
500
  if ( ! is_array( $imported_option ) ) {
501
+ $imported_option = [];
502
  }
503
  if ( ! is_array( $existing_option ) ) {
504
+ $existing_option = [];
505
  }
506
 
507
  $option_to_import = array_merge( $existing_option, $imported_option );
508
 
509
  /* translators: %s: Option name. */
510
+ $this->messages[] = [ 'update', sprintf( __( 'Option was updated: <em>%s</em>', 'advanced-ads' ), $option_name ) ];
511
  update_option( $option_name, maybe_unserialize( $option_to_import ) );
512
  }
513
  }
521
  private function handle_upload() {
522
  $uploads_dir = wp_upload_dir();
523
  if ( ! empty( $uploads_dir['error'] ) ) {
524
+ $this->messages[] = [ 'error', $uploads_dir['error'] ];
525
  return;
526
  }
527
 
529
  $this->import_id = $import_dir . '/' . md5( time() . NONCE_SALT );
530
 
531
  if ( ! is_dir( $import_dir) && ! wp_mkdir_p( $import_dir ) ) {
532
+ $this->messages[] = [ 'error', sprintf( __( 'Failed to create import directory <em>%s</em>', 'advanced-ads' ), $import_dir ) ];
533
  return;
534
  }
535
 
536
  if ( ! is_writable( $import_dir ) ) {
537
+ $this->messages[] = [ 'error', sprintf( __( 'Import directory is not writable: <em>%s</em>', 'advanced-ads' ), $import_dir ) ];
538
  return;
539
  }
540
 
542
 
543
 
544
  if ( ! isset( $_FILES['import'] ) ) {
545
+ $this->messages[] = [ 'error', __( 'File is empty, uploads are disabled or post_max_size is smaller than upload_max_filesize in php.ini', 'advanced-ads' ) ];
546
  return;
547
  }
548
 
552
  $file = apply_filters( "wp_handle_upload_prefilter", $file );
553
 
554
  if ( ! empty( $file['error'] ) ) {
555
+ $this->messages[] = [ 'error', sprintf( __( 'Failed to upload file, error: <em>%s</em>', 'advanced-ads' ), $file['error'] ) ];
556
  return;
557
  }
558
 
559
  if ( ! ( $file['size'] > 0 ) ) {
560
+ $this->messages[] = [ 'error', __( 'File is empty.', 'advanced-ads' ), $file['error'] ];
561
  return;
562
  }
563
 
564
  if ( ! is_uploaded_file( $file['tmp_name'] ) || ! @ move_uploaded_file( $file['tmp_name'], $this->import_id ) || ! is_readable( $this->import_id ) ) {
565
+ $this->messages[] = [ 'error', sprintf( __( 'The file could not be created: <em>%s</em>. This is probably a permissions problem', 'advanced-ads' ), $this->import_id ) ];
566
  return;
567
  }
568
 
572
  @ chmod( $this->import_id, $perms );
573
 
574
  // cleanup in case of failed import
575
+ wp_schedule_single_event( time() + 10 * MINUTE_IN_SECONDS, 'advanced-ads-cleanup-import-file', [ $this->import_id ] );
576
 
577
  return true;
578
  }
585
  */
586
  private function process_ad_content( $content ) {
587
  // download images, replace old image urls with urls of these new images
588
+ $replacement_map = [];
589
 
590
  if ( preg_match_all( '/\<advads_import_img\>(\S+?)\<\/advads_import_img\>/i', $content, $matches ) ) {
591
  foreach ( $matches[1] as $k => $url ) {
593
  $replacement_map[ $url ] = $this->created_attachments[ $url ]['attachment_url'];
594
  } else if ( $attachment = $this->upload_image_from_url( $url ) ) {
595
  $link = ( $link = get_attachment_link( $attachment['post_id'] ) ) ? sprintf( '<a href="%s">%s</a>', esc_url( $link ), __( 'Edit', 'advanced-ads' ) ) : '';
596
+ $this->messages[] = [ 'update', sprintf( __( 'New attachment created <em>%s</em> %s', 'advanced-ads' ), $attachment['post_id'], $link ) ];
597
  $this->created_attachments[ $url ] = $attachment;
598
  $replacement_map[ $url ] = $attachment['attachment_url'];
599
  }
600
  }
601
  }
602
 
603
+ $content = str_replace( [ '<advads_import_img>', '</advads_import_img>' ], '', $content );
604
 
605
  if ( count( $replacement_map ) ) {
606
  $content = str_replace( array_keys( $replacement_map ), array_values( $replacement_map ), $content );
635
 
636
 
637
  if ( ! $wp_filetype['type'] ) {
638
+ $this->messages[] = [ 'error', sprintf( __( 'Invalid filetype <em>%s</em>', 'advanced-ads' ), $image_url ) ];
639
  return false;
640
  }
641
 
642
  if ( ! $parsed_url || ! is_array( $parsed_url ) ) {
643
+ $this->messages[] = [ 'error', sprintf( __( 'Error getting remote image <em>%s</em>', 'advanced-ads' ), $image_url ) ];
644
  return false;
645
  }
646
 
647
+ $response = wp_safe_remote_get( $image_url, [ 'timeout' => 20 ] );
648
 
649
  if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
650
+ $this->messages[] = [ 'error', sprintf( __( 'Error getting remote image <em>%s</em>', 'advanced-ads' ), $image_url ) ];
651
  return false;
652
  }
653
 
655
  $upload = wp_upload_bits( $file_name, '', wp_remote_retrieve_body( $response ) );
656
 
657
  if ( $upload['error'] ) {
658
+ $this->messages[] = [ 'error', sprintf( __( 'Error getting remote image <em>%s</em>', 'advanced-ads' ), $image_url ) ];
659
  return false;
660
  }
661
 
664
 
665
  if ( 0 == $filesize ) {
666
  @unlink( $upload['file'] );
667
+ $this->messages[] = [ 'error', sprintf( __( 'Zero size file downloaded <em>%s</em>', 'advanced-ads' ), $image_url ) ];
668
  return false;
669
  }
670
 
681
  if ( ! $fileinfo || ! in_array( $fileinfo['mime'], $mime_types, true ) ) {
682
  @unlink( $upload['file'] );
683
  /* translators: 1: image url */
684
+ $this->messages[] = [ 'error', sprintf( __( 'Error getting remote image <em>%s</em>', 'advanced-ads' ), $image_url ) ];
685
 
686
  return false;
687
  }
688
 
689
  // create new post
690
+ $new_post = [
691
  'post_title' => $file_name,
692
  'post_mime_type' => $wp_filetype['type'],
693
  'guid' => $upload['url'],
694
+ ];
695
 
696
  if ( ! function_exists( 'wp_generate_attachment_metadata' ) ) {
697
  require_once( ABSPATH . 'wp-admin/includes/image.php' );
700
  $post_id = wp_insert_attachment( $new_post, $upload['file'] );
701
  wp_update_attachment_metadata( $post_id, wp_generate_attachment_metadata( $post_id, $upload['file'] ) );
702
 
703
+ return [ 'post_id' => $post_id, 'attachment_url' => wp_get_attachment_url( $post_id ) ];
704
  }
705
 
706
  public function get_messages(){
modules/import-export/config.php CHANGED
@@ -4,11 +4,11 @@
4
 
5
  $path = dirname( __FILE__ );
6
 
7
- return array(
8
- 'classmap' => array(
9
  'Advanced_Ads_XmlEncoder' => $path . '/classes/XmlEncoder.php',
10
  'Advanced_Ads_Export' => $path . '/classes/export.php',
11
  'Advanced_Ads_Import' => $path . '/classes/import.php',
12
- ),
13
  'textdomain' => null,
14
- );
4
 
5
  $path = dirname( __FILE__ );
6
 
7
+ return [
8
+ 'classmap' => [
9
  'Advanced_Ads_XmlEncoder' => $path . '/classes/XmlEncoder.php',
10
  'Advanced_Ads_Export' => $path . '/classes/export.php',
11
  'Advanced_Ads_Import' => $path . '/classes/import.php',
12
+ ],
13
  'textdomain' => null,
14
+ ];
modules/privacy/admin/admin.php CHANGED
@@ -16,12 +16,12 @@ class Advanced_Ads_Privacy_Admin {
16
  */
17
  private function __construct() {
18
  // add module settings to Advanced Ads settings page
19
- add_action( 'advanced-ads-settings-init', array( $this, 'settings_init' ), 20 );
20
- add_filter( 'advanced-ads-setting-tabs', array( $this, 'setting_tabs' ), 20 );
21
 
22
  // additional ad options
23
- add_action( 'advanced-ads-ad-params-after', array( $this, 'render_ad_options' ), 20 );
24
- add_filter( 'advanced-ads-save-options', array( $this, 'save_ad_options' ), 10, 2 );
25
  }
26
 
27
  /**
@@ -47,12 +47,12 @@ class Advanced_Ads_Privacy_Admin {
47
  * @since 1.8.30
48
  */
49
  public function setting_tabs( array $tabs ) {
50
- $tabs['privacy'] = array(
51
  'page' => ADVADS_PRIVACY_SLUG . '-settings',
52
  'group' => ADVADS_PRIVACY_SLUG,
53
  'tabid' => 'privacy',
54
  'title' => __( 'Privacy', 'advanced-ads' ),
55
- );
56
 
57
  return $tabs;
58
  }
@@ -61,7 +61,7 @@ class Advanced_Ads_Privacy_Admin {
61
  * Add settings to settings page
62
  */
63
  public function settings_init() {
64
- register_setting( ADVADS_PRIVACY_SLUG, Advanced_Ads_Privacy::OPTION_KEY, array( $this, 'sanitize_settings' ) );
65
 
66
  /**
67
  * Allow Ad Admin to save privacy options.
@@ -86,10 +86,10 @@ class Advanced_Ads_Privacy_Admin {
86
  add_settings_field(
87
  'enable-privacy-module',
88
  __( 'Enable Privacy module', 'advanced-ads' ),
89
- array( $this, 'render_settings_enable_module' ),
90
  ADVADS_PRIVACY_SLUG . '-settings',
91
  ADVADS_PRIVACY_SLUG . '_settings_section',
92
- array( 'label_for' => Advanced_Ads_Privacy::OPTION_KEY . '_enabled' )
93
  );
94
  }
95
 
@@ -113,31 +113,31 @@ class Advanced_Ads_Privacy_Admin {
113
  public function render_settings_enable_module() {
114
  $options = Advanced_Ads_Privacy::get_instance()->options();
115
  $module_enabled = isset( $options['enabled'] );
116
- $methods = array(
117
- '' => array(
118
  'label' => __( 'Show all ads even without consent', 'advanced-ads' ),
119
- ),
120
- 'custom' => array(
121
  'label' => __( 'Cookie', 'advanced-ads' ),
122
  'manual_url' => ADVADS_URL . 'manual/ad-cookie-consent/?utm_source=advanced-ads&utm_medium=link&utm_campaign=privacy-tab',
123
- ),
124
- 'iab_tcf_20' => array(
125
  'label' => sprintf(
126
  // translators: %s is a string with various CMPs (companies) that support the TCF standard
127
  __( 'TCF v2.0 integration (e.g., %s)', 'advanced-ads' ),
128
  'Quantcast Choices'
129
  ),
130
  'manual_url' => ADVADS_URL . 'manual/tcf-consent-wordpress/?utm_source=advanced-ads&utm_medium=link&utm_campaign=privacy-tab',
131
- ),
132
- );
133
  $current_method = isset( $options['consent-method'] ) ? $options['consent-method'] : '';
134
  $custom_cookie_name = isset( $options['custom-cookie-name'] ) ? $options['custom-cookie-name'] : '';
135
  $custom_cookie_value = isset( $options['custom-cookie-value'] ) ? $options['custom-cookie-value'] : '';
136
  $show_non_personalized_adsense = isset( $options['show-non-personalized-adsense'] );
137
- $link_default_attrs = array(
138
  'href' => esc_url( ADVADS_URL . 'add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=privacy-cache' ),
139
  'target' => '_blank',
140
- );
141
  $pro_link_attrs = apply_filters( 'advanced-ads-privacy-custom-link-attributes', $link_default_attrs );
142
  if ( ! array_key_exists( 'href', $pro_link_attrs ) ) {
143
  $pro_link_attrs = wp_parse_args( $pro_link_attrs, $link_default_attrs );
@@ -157,8 +157,8 @@ class Advanced_Ads_Privacy_Admin {
157
  )
158
  );
159
 
160
- wp_enqueue_script( Advanced_Ads_Privacy::OPTION_KEY, ADVADS_PRIVACY_BASE_URL . 'admin/assets/js/privacy.js', array( 'jquery' ), '1.19.1', true );
161
- wp_localize_script( Advanced_Ads_Privacy::OPTION_KEY, 'advads_privacy', array( 'option_key' => Advanced_Ads_Privacy::OPTION_KEY ) );
162
 
163
  require ADVADS_PRIVACY_BASE_PATH . 'admin/views/setting-general.php';
164
  }
@@ -199,7 +199,7 @@ class Advanced_Ads_Privacy_Admin {
199
  *
200
  * @return array
201
  */
202
- public function save_ad_options( $options = array() ) {
203
  // phpcs:disable WordPress.Security.NonceVerification.Missing
204
  if ( isset( $_POST['advanced_ad']['privacy'] ) ) {
205
  $options['privacy'] = $_POST['advanced_ad']['privacy'];
16
  */
17
  private function __construct() {
18
  // add module settings to Advanced Ads settings page
19
+ add_action( 'advanced-ads-settings-init', [ $this, 'settings_init' ], 20 );
20
+ add_filter( 'advanced-ads-setting-tabs', [ $this, 'setting_tabs' ], 20 );
21
 
22
  // additional ad options
23
+ add_action( 'advanced-ads-ad-params-after', [ $this, 'render_ad_options' ], 20 );
24
+ add_filter( 'advanced-ads-save-options', [ $this, 'save_ad_options' ], 10, 2 );
25
  }
26
 
27
  /**
47
  * @since 1.8.30
48
  */
49
  public function setting_tabs( array $tabs ) {
50
+ $tabs['privacy'] = [
51
  'page' => ADVADS_PRIVACY_SLUG . '-settings',
52
  'group' => ADVADS_PRIVACY_SLUG,
53
  'tabid' => 'privacy',
54
  'title' => __( 'Privacy', 'advanced-ads' ),
55
+ ];
56
 
57
  return $tabs;
58
  }
61
  * Add settings to settings page
62
  */
63
  public function settings_init() {
64
+ register_setting( ADVADS_PRIVACY_SLUG, Advanced_Ads_Privacy::OPTION_KEY, [ $this, 'sanitize_settings' ] );
65
 
66
  /**
67
  * Allow Ad Admin to save privacy options.
86
  add_settings_field(
87
  'enable-privacy-module',
88
  __( 'Enable Privacy module', 'advanced-ads' ),
89
+ [ $this, 'render_settings_enable_module' ],
90
  ADVADS_PRIVACY_SLUG . '-settings',
91
  ADVADS_PRIVACY_SLUG . '_settings_section',
92
+ [ 'label_for' => Advanced_Ads_Privacy::OPTION_KEY . '_enabled' ]
93
  );
94
  }
95
 
113
  public function render_settings_enable_module() {
114
  $options = Advanced_Ads_Privacy::get_instance()->options();
115
  $module_enabled = isset( $options['enabled'] );
116
+ $methods = [
117
+ '' => [
118
  'label' => __( 'Show all ads even without consent', 'advanced-ads' ),
119
+ ],
120
+ 'custom' => [
121
  'label' => __( 'Cookie', 'advanced-ads' ),
122
  'manual_url' => ADVADS_URL . 'manual/ad-cookie-consent/?utm_source=advanced-ads&utm_medium=link&utm_campaign=privacy-tab',
123
+ ],
124
+ 'iab_tcf_20' => [
125
  'label' => sprintf(
126
  // translators: %s is a string with various CMPs (companies) that support the TCF standard
127
  __( 'TCF v2.0 integration (e.g., %s)', 'advanced-ads' ),
128
  'Quantcast Choices'
129
  ),
130
  'manual_url' => ADVADS_URL . 'manual/tcf-consent-wordpress/?utm_source=advanced-ads&utm_medium=link&utm_campaign=privacy-tab',
131
+ ],
132
+ ];
133
  $current_method = isset( $options['consent-method'] ) ? $options['consent-method'] : '';
134
  $custom_cookie_name = isset( $options['custom-cookie-name'] ) ? $options['custom-cookie-name'] : '';
135
  $custom_cookie_value = isset( $options['custom-cookie-value'] ) ? $options['custom-cookie-value'] : '';
136
  $show_non_personalized_adsense = isset( $options['show-non-personalized-adsense'] );
137
+ $link_default_attrs = [
138
  'href' => esc_url( ADVADS_URL . 'add-ons/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=privacy-cache' ),
139
  'target' => '_blank',
140
+ ];
141
  $pro_link_attrs = apply_filters( 'advanced-ads-privacy-custom-link-attributes', $link_default_attrs );
142
  if ( ! array_key_exists( 'href', $pro_link_attrs ) ) {
143
  $pro_link_attrs = wp_parse_args( $pro_link_attrs, $link_default_attrs );
157
  )
158
  );
159
 
160
+ wp_enqueue_script( Advanced_Ads_Privacy::OPTION_KEY, ADVADS_PRIVACY_BASE_URL . 'admin/assets/js/privacy.js', [ 'jquery' ], '1.19.1', true );
161
+ wp_localize_script( Advanced_Ads_Privacy::OPTION_KEY, 'advads_privacy', [ 'option_key' => Advanced_Ads_Privacy::OPTION_KEY ] );
162
 
163
  require ADVADS_PRIVACY_BASE_PATH . 'admin/views/setting-general.php';
164
  }
199
  *
200
  * @return array
201
  */
202
+ public function save_ad_options( $options = [] ) {
203
  // phpcs:disable WordPress.Security.NonceVerification.Missing
204
  if ( isset( $_POST['advanced_ad']['privacy'] ) ) {
205
  $options['privacy'] = $_POST['advanced_ad']['privacy'];
modules/privacy/classes/class-privacy.php CHANGED
@@ -29,7 +29,7 @@ class Advanced_Ads_Privacy {
29
  * Initialize the module
30
  */
31
  private function __construct() {
32
- add_filter( 'advanced-ads-can-display', array( $this, 'can_display_by_consent' ), 10, 3 );
33
 
34
  $this->options();
35
 
@@ -37,7 +37,7 @@ class Advanced_Ads_Privacy {
37
  add_filter( 'advanced-ads-activate-advanced-js', '__return_true' );
38
 
39
  if ( $this->options['consent-method'] === 'iab_tcf_20' ) {
40
- add_filter( 'advanced-ads-output-final', array( $this, 'final_ad_output' ), 10, 2 );
41
  }
42
  }
43
  }
@@ -73,10 +73,10 @@ class Advanced_Ads_Privacy {
73
  * @return string
74
  */
75
  public function encode_ad( $output, Advanced_Ads_Ad $ad ) {
76
- $data_attributes = array(
77
  'id' => $ad->id,
78
  'bid' => get_current_blog_id(),
79
- );
80
  if ( ! empty( $ad->output['placement_id'] ) ) {
81
  $data_attributes['placement'] = $ad->output['placement_id'];
82
  }
@@ -136,7 +136,7 @@ class Advanced_Ads_Privacy {
136
  */
137
  public function options() {
138
  if ( ! isset( $this->options ) ) {
139
- $this->options = get_option( self::OPTION_KEY, array() );
140
  if ( isset( $this->options['enabled'] ) && empty( $this->options['consent-method'] ) ) {
141
  $this->options['enabled'] = false;
142
  }
@@ -203,7 +203,7 @@ class Advanced_Ads_Privacy {
203
  * @return bool
204
  */
205
  public function ad_type_needs_consent( $type ) {
206
- return ! in_array( $type, array( 'image', 'dummy', 'group' ), true );
207
  }
208
 
209
  /**
29
  * Initialize the module
30
  */
31
  private function __construct() {
32
+ add_filter( 'advanced-ads-can-display', [ $this, 'can_display_by_consent' ], 10, 3 );
33
 
34
  $this->options();
35
 
37
  add_filter( 'advanced-ads-activate-advanced-js', '__return_true' );
38
 
39
  if ( $this->options['consent-method'] === 'iab_tcf_20' ) {
40
+ add_filter( 'advanced-ads-output-final', [ $this, 'final_ad_output' ], 10, 2 );
41
  }
42
  }
43
  }
73
  * @return string
74
  */
75
  public function encode_ad( $output, Advanced_Ads_Ad $ad ) {
76
+ $data_attributes = [
77
  'id' => $ad->id,
78
  'bid' => get_current_blog_id(),
79
+ ];
80
  if ( ! empty( $ad->output['placement_id'] ) ) {
81
  $data_attributes['placement'] = $ad->output['placement_id'];
82
  }
136
  */
137
  public function options() {
138
  if ( ! isset( $this->options ) ) {
139
+ $this->options = get_option( self::OPTION_KEY, [] );
140
  if ( isset( $this->options['enabled'] ) && empty( $this->options['consent-method'] ) ) {
141
  $this->options['enabled'] = false;
142
  }
203
  * @return bool
204
  */
205
  public function ad_type_needs_consent( $type ) {
206
+ return ! in_array( $type, [ 'image', 'dummy', 'group' ], true );
207
  }
208
 
209
  /**
modules/privacy/config.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
 
3
  // module configuration
4
- return array(
5
- 'classmap' => array(
6
  'Advanced_Ads_Privacy' => __DIR__ . '/classes/class-privacy.php',
7
  'Advanced_Ads_Privacy_Admin' => __DIR__ . '/admin/admin.php',
8
- ),
9
  'textdomain' => null,
10
- );
1
  <?php
2
 
3
  // module configuration
4
+ return [
5
+ 'classmap' => [
6
  'Advanced_Ads_Privacy' => __DIR__ . '/classes/class-privacy.php',
7
  'Advanced_Ads_Privacy_Admin' => __DIR__ . '/admin/admin.php',
8
+ ],
9
  'textdomain' => null,
10
+ ];
public/assets/js/advanced.js CHANGED
@@ -155,16 +155,17 @@ advads = {
155
  /**
156
  * get a cookie value
157
  *
158
- * @param {str} name of the cookie
 
159
  */
160
  get_cookie: function ( name ) {
161
- var i, x, y, ADVcookies = document.cookie.split( ";" );
162
  for ( i = 0; i < ADVcookies.length; i ++ ) {
163
- x = ADVcookies[i].substr( 0, ADVcookies[i].indexOf( "=" ) );
164
- y = ADVcookies[i].substr( ADVcookies[i].indexOf( "=" ) + 1 );
165
- x = x.replace( /^\s+|\s+$/g, "" );
166
  if ( x === name ) {
167
- return unescape( y );
168
  }
169
  }
170
  },
@@ -196,7 +197,7 @@ advads = {
196
  set_cookie_sec: function ( name, value, expiry, path, domain, secure ) {
197
  var exdate = new Date();
198
  exdate.setSeconds( exdate.getSeconds() + parseInt( expiry ) );
199
- document.cookie = name + "=" + escape( value ) +
200
  (
201
  (
202
  expiry == null
@@ -670,4 +671,3 @@ document.addEventListener( 'advanced_ads_privacy', function ( event ) {
670
  // Find all scripts waiting for consent and decode them.
671
  document.querySelectorAll( 'script[type="text/plain"][data-tcf="waiting-for-consent"]' ).forEach( advads.privacy.decode_ad );
672
  } );
673
-
155
  /**
156
  * get a cookie value
157
  *
158
+ * @param {string} name of the cookie
159
+ * @return {string} decoded cookie value
160
  */
161
  get_cookie: function ( name ) {
162
+ var i, x, y, ADVcookies = document.cookie.split( ';' );
163
  for ( i = 0; i < ADVcookies.length; i ++ ) {
164
+ x = ADVcookies[i].substr( 0, ADVcookies[i].indexOf( '=' ) );
165
+ y = ADVcookies[i].substr( ADVcookies[i].indexOf( '=' ) + 1 );
166
+ x = x.replace( /^\s+|\s+$/g, '' );
167
  if ( x === name ) {
168
+ return decodeURIComponent( y );
169
  }
170
  }
171
  },
197
  set_cookie_sec: function ( name, value, expiry, path, domain, secure ) {
198
  var exdate = new Date();
199
  exdate.setSeconds( exdate.getSeconds() + parseInt( expiry ) );
200
+ document.cookie = name + "=" + encodeURIComponent( value ) +
201
  (
202
  (
203
  expiry == null
671
  // Find all scripts waiting for consent and decode them.
672
  document.querySelectorAll( 'script[type="text/plain"][data-tcf="waiting-for-consent"]' ).forEach( advads.privacy.decode_ad );
673
  } );
 
public/assets/js/advanced.min.js CHANGED
@@ -1 +1 @@
1
- !function(){if("function"!=typeof window.CustomEvent){window.CustomEvent=function(e,t){t=t||{bubbles:!1,cancelable:!1,detail:null};var a=document.createEvent("CustomEvent");return a.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),a}}function e(){var e,t=this.parentNode,a=arguments.length;if(t)for(a||t.removeChild(this);a--;)"object"!=typeof(e=arguments[a])?e=this.ownerDocument.createTextNode(e):e.parentNode&&e.parentNode.removeChild(e),a?t.insertBefore(e,this.nextSibling):t.replaceChild(e,this)}Element.prototype.replaceWith||(Element.prototype.replaceWith=e),CharacterData.prototype.replaceWith||(CharacterData.prototype.replaceWith=e),DocumentType.prototype.replaceWith||(DocumentType.prototype.replaceWith=e),window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=function(e,t){var a,o=this.length;for(t=t||window,a=0;a<o;a++)e.call(t,this[a],a,this)})}(),advads={supports_localstorage:function(){"use strict";try{return!(!window||void 0===window.localStorage)&&(window.localStorage.setItem("x","x"),window.localStorage.removeItem("x"),!0)}catch(e){return!1}},max_per_session:function(e,t){var a=1;if(void 0!==t&&0!==parseInt(t)||(t=1),this.cookie_exists(e)){if(this.get_cookie(e)>=t)return!0;a+=parseInt(this.get_cookie(e))}return this.set_cookie(e,a),!1},count_up:function(e,t){var a=1;this.cookie_exists(e)&&(a+=parseInt(this.get_cookie(e))),this.set_cookie(e,a)},set_cookie_exists:function(e){return!!get_cookie(e)||(set_cookie(e,"",0),!1)},get_cookie:function(e){var t,a,o,i=document.cookie.split(";");for(t=0;t<i.length;t++)if(a=i[t].substr(0,i[t].indexOf("=")),o=i[t].substr(i[t].indexOf("=")+1),(a=a.replace(/^\s+|\s+$/g,""))===e)return unescape(o)},set_cookie:function(e,t,a,o,i,n){var s=null==a?null:24*a*60*60;this.set_cookie_sec(e,t,s,o,i,n)},set_cookie_sec:function(e,t,a,o,i,n){var s=new Date;s.setSeconds(s.getSeconds()+parseInt(a)),document.cookie=e+"="+escape(t)+(null==a?"":"; expires="+s.toUTCString())+(null==o?"; path=/":"; path="+o)+(null==i?"":"; domain="+i)+(null==n?"":"; secure")},cookie_exists:function(e){var t=this.get_cookie(e);return null!==t&&""!==t&&void 0!==t},move:function(e,t,a){var o=jQuery(e);if(void 0===a&&(a={}),void 0===a.css&&(a.css={}),void 0===a.method&&(a.method="prependTo"),""===t&&void 0!==a.target)switch(a.target){case"wrapper":var i="left";void 0!==a.offset&&(i=a.offset),t=this.find_wrapper(e,i)}switch((t=void 0===a.moveintohidden?jQuery(t).filter(":visible"):jQuery(t)).length>1&&t.length,a.method){case"insertBefore":o.insertBefore(t);break;case"insertAfter":o.insertAfter(t);break;case"appendTo":o.appendTo(t);break;case"prependTo":o.prependTo(t);break;default:o.prependTo(t)}},set_parent_relative:function(e,t){t=void 0!==t?t:{};var a=jQuery(e).parent();t.use_grandparent&&(a=a.parent()),"static"!==a.css("position")&&""!==a.css("position")||a.css("position","relative")},fix_element:function(e,t){t=void 0!==t?t:{};var a=jQuery(e);t.use_grandparent?this.set_parent_relative(a.parent()):this.set_parent_relative(a),t.is_invisible&&a.show();var o=parseInt(a.offset().top),i=parseInt(a.offset().left);if(t.is_invisible&&a.hide(),"left"===t.offset){var n=jQuery(window).width()-i-a.outerWidth();a.css("position","fixed").css("top",o+"px").css("right",n+"px").css("left","")}else a.css("position","fixed").css("top",o+"px").css("left",i+"px").css("right","")},find_wrapper:function(e,t){var a;return jQuery("body").children().each((function(o,i){if(i.id!==e.substring(1)){var n=jQuery(i);if("right"===t&&n.offset().left+jQuery(n).width()<jQuery(window).width()||"left"===t&&n.offset().left>0)return"static"!==n.css("position")&&""!==n.css("position")||n.css("position","relative"),a=i,!1}})),a},center_fixed_element:function(e){var t=jQuery(e),a=jQuery(window).width()/2-parseInt(t.css("width"))/2;t.css("left",a+"px")},center_vertically:function(e){var t=jQuery(e),a=jQuery(window).height()/2-parseInt(t.css("height"))/2;"fixed"!==t.css("position")&&(a-=topoffset=parseInt(t.offset().top)),t.css("top",a+"px")},close:function(e){jQuery(e).remove()},wait_for_images:function(e,t){var a=0,o=[];e.find('img[src][src!=""]').each((function(){o.push(this.src)})),0===o.length&&t.call(e),jQuery.each(o,(function(i,n){var s=new Image;s.src=n;var r="load error";jQuery(s).one(r,(function i(n){if(jQuery(this).off(r,i),++a==o.length)return t.call(e[0]),!1}))}))},privacy:{state:"unknown",state_executed:!1,get_state:function(){if("unknown"!==window.advads_options.privacy.state)return advads.privacy.state_executed||(advads.privacy.state_executed=!0,advads.privacy.dispatch_event(window.advads_options.privacy.state,!1)),advads.privacy.state;if("custom"===window.advads_options.privacy["consent-method"]){var e=new RegExp(window.advads_options.privacy["custom-cookie-name"]+"=.*?"+window.advads_options.privacy["custom-cookie-value"]+"[^;]*");advads.privacy.state_executed||(advads.privacy.state_executed=!0,advads.privacy.dispatch_event(null!==document.cookie.match(e)?"accepted":"unknown",!0))}advads.privacy.state_executed=!0;var t=0,a=setInterval((function(){switch(600==++t&&clearInterval(a),window.advads_options.privacy["consent-method"]){case"custom":null!==document.cookie.match(e)&&(clearInterval(a),"accepted"!==advads.privacy.state&&advads.privacy.dispatch_event("accepted",!0));break;case"iab_tcf_20":if(void 0===window.__tcfapi)return;clearInterval(a),window.__tcfapi("addEventListener",2,(function(e,t){if(t&&("tcloaded"===e.eventStatus||"useractioncomplete"===e.eventStatus||null===e.eventStatus&&void 0!==window.googlefc&&(void 0!==e.purpose||!e.gdprApplies))){var a="useractioncomplete"===e.eventStatus;if(!e.gdprApplies)return void("not_needed"!==advads.privacy.state&&advads.privacy.dispatch_event("not_needed",a));if(e.purpose.consents[1])return void("accepted"!==advads.privacy.state&&advads.privacy.dispatch_event("accepted",a));"rejected"!==advads.privacy.state&&advads.privacy.dispatch_event("rejected",a)}}))}}),100);return advads.privacy.state},is_adsense_npa_enabled:function(){return!window.advads_options||!window.advads_options.privacy||!(!window.advads_options.privacy["show-non-personalized-adsense"]||"custom"!==window.advads_options.privacy["consent-method"])},dispatch_event:function(e,t){var a=advads.privacy.state;advads.privacy.state=e,window.advanced_ads_ready_queue.push((function(){document.dispatchEvent(new CustomEvent("advanced_ads_privacy",{detail:{state:e,previousState:a,userAction:t}}))}))},is_ad_decoded:function(e){return null===document.querySelector('script[data-tcf="waiting-for-consent"][data-id="'+e+'"]')},decode_ad:function(e,t){t="boolean"!=typeof t||t;var a=decodeURIComponent(Array.prototype.map.call(atob(e.textContent),(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""));if(!t)return a;e.replaceWith(document.createRange().createContextualFragment(a))}}},window.advanced_ads_ready_queue.push(advads.privacy.get_state),document.addEventListener("advanced_ads_privacy",(function(e){"accepted"!==e.detail.state&&"not_needed"!==e.detail.state||e.detail.userAction||"loading"===document.readyState||document.querySelectorAll('script[type="text/plain"][data-tcf="waiting-for-consent"]').forEach(advads.privacy.decode_ad)}));
1
+ !function(){if("function"!=typeof window.CustomEvent){window.CustomEvent=function(e,t){t=t||{bubbles:!1,cancelable:!1,detail:null};var a=document.createEvent("CustomEvent");return a.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),a}}function e(){var e,t=this.parentNode,a=arguments.length;if(t)for(a||t.removeChild(this);a--;)"object"!=typeof(e=arguments[a])?e=this.ownerDocument.createTextNode(e):e.parentNode&&e.parentNode.removeChild(e),a?t.insertBefore(e,this.nextSibling):t.replaceChild(e,this)}Element.prototype.replaceWith||(Element.prototype.replaceWith=e),CharacterData.prototype.replaceWith||(CharacterData.prototype.replaceWith=e),DocumentType.prototype.replaceWith||(DocumentType.prototype.replaceWith=e),window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=function(e,t){var a,o=this.length;for(t=t||window,a=0;a<o;a++)e.call(t,this[a],a,this)})}(),advads={supports_localstorage:function(){"use strict";try{return!(!window||void 0===window.localStorage)&&(window.localStorage.setItem("x","x"),window.localStorage.removeItem("x"),!0)}catch(e){return!1}},max_per_session:function(e,t){var a=1;if(void 0!==t&&0!==parseInt(t)||(t=1),this.cookie_exists(e)){if(this.get_cookie(e)>=t)return!0;a+=parseInt(this.get_cookie(e))}return this.set_cookie(e,a),!1},count_up:function(e,t){var a=1;this.cookie_exists(e)&&(a+=parseInt(this.get_cookie(e))),this.set_cookie(e,a)},set_cookie_exists:function(e){return!!get_cookie(e)||(set_cookie(e,"",0),!1)},get_cookie:function(e){var t,a,o,i=document.cookie.split(";");for(t=0;t<i.length;t++)if(a=i[t].substr(0,i[t].indexOf("=")),o=i[t].substr(i[t].indexOf("=")+1),(a=a.replace(/^\s+|\s+$/g,""))===e)return decodeURIComponent(o)},set_cookie:function(e,t,a,o,i,n){var s=null==a?null:24*a*60*60;this.set_cookie_sec(e,t,s,o,i,n)},set_cookie_sec:function(e,t,a,o,i,n){var s=new Date;s.setSeconds(s.getSeconds()+parseInt(a)),document.cookie=e+"="+encodeURIComponent(t)+(null==a?"":"; expires="+s.toUTCString())+(null==o?"; path=/":"; path="+o)+(null==i?"":"; domain="+i)+(null==n?"":"; secure")},cookie_exists:function(e){var t=this.get_cookie(e);return null!==t&&""!==t&&void 0!==t},move:function(e,t,a){var o=jQuery(e);if(void 0===a&&(a={}),void 0===a.css&&(a.css={}),void 0===a.method&&(a.method="prependTo"),""===t&&void 0!==a.target)switch(a.target){case"wrapper":var i="left";void 0!==a.offset&&(i=a.offset),t=this.find_wrapper(e,i)}switch((t=void 0===a.moveintohidden?jQuery(t).filter(":visible"):jQuery(t)).length>1&&t.length,a.method){case"insertBefore":o.insertBefore(t);break;case"insertAfter":o.insertAfter(t);break;case"appendTo":o.appendTo(t);break;case"prependTo":o.prependTo(t);break;default:o.prependTo(t)}},set_parent_relative:function(e,t){t=void 0!==t?t:{};var a=jQuery(e).parent();t.use_grandparent&&(a=a.parent()),"static"!==a.css("position")&&""!==a.css("position")||a.css("position","relative")},fix_element:function(e,t){t=void 0!==t?t:{};var a=jQuery(e);t.use_grandparent?this.set_parent_relative(a.parent()):this.set_parent_relative(a),t.is_invisible&&a.show();var o=parseInt(a.offset().top),i=parseInt(a.offset().left);if(t.is_invisible&&a.hide(),"left"===t.offset){var n=jQuery(window).width()-i-a.outerWidth();a.css("position","fixed").css("top",o+"px").css("right",n+"px").css("left","")}else a.css("position","fixed").css("top",o+"px").css("left",i+"px").css("right","")},find_wrapper:function(e,t){var a;return jQuery("body").children().each((function(o,i){if(i.id!==e.substring(1)){var n=jQuery(i);if("right"===t&&n.offset().left+jQuery(n).width()<jQuery(window).width()||"left"===t&&n.offset().left>0)return"static"!==n.css("position")&&""!==n.css("position")||n.css("position","relative"),a=i,!1}})),a},center_fixed_element:function(e){var t=jQuery(e),a=jQuery(window).width()/2-parseInt(t.css("width"))/2;t.css("left",a+"px")},center_vertically:function(e){var t=jQuery(e),a=jQuery(window).height()/2-parseInt(t.css("height"))/2;"fixed"!==t.css("position")&&(a-=topoffset=parseInt(t.offset().top)),t.css("top",a+"px")},close:function(e){jQuery(e).remove()},wait_for_images:function(e,t){var a=0,o=[];e.find('img[src][src!=""]').each((function(){o.push(this.src)})),0===o.length&&t.call(e),jQuery.each(o,(function(i,n){var s=new Image;s.src=n;var r="load error";jQuery(s).one(r,(function i(n){if(jQuery(this).off(r,i),++a==o.length)return t.call(e[0]),!1}))}))},privacy:{state:"unknown",state_executed:!1,get_state:function(){if("unknown"!==window.advads_options.privacy.state)return advads.privacy.state_executed||(advads.privacy.state_executed=!0,advads.privacy.dispatch_event(window.advads_options.privacy.state,!1)),advads.privacy.state;if("custom"===window.advads_options.privacy["consent-method"]){var e=new RegExp(window.advads_options.privacy["custom-cookie-name"]+"=.*?"+window.advads_options.privacy["custom-cookie-value"]+"[^;]*");advads.privacy.state_executed||(advads.privacy.state_executed=!0,advads.privacy.dispatch_event(null!==document.cookie.match(e)?"accepted":"unknown",!0))}advads.privacy.state_executed=!0;var t=0,a=setInterval((function(){switch(600==++t&&clearInterval(a),window.advads_options.privacy["consent-method"]){case"custom":null!==document.cookie.match(e)&&(clearInterval(a),"accepted"!==advads.privacy.state&&advads.privacy.dispatch_event("accepted",!0));break;case"iab_tcf_20":if(void 0===window.__tcfapi)return;clearInterval(a),window.__tcfapi("addEventListener",2,(function(e,t){if(t&&("tcloaded"===e.eventStatus||"useractioncomplete"===e.eventStatus||null===e.eventStatus&&void 0!==window.googlefc&&(void 0!==e.purpose||!e.gdprApplies))){var a="useractioncomplete"===e.eventStatus;if(!e.gdprApplies)return void("not_needed"!==advads.privacy.state&&advads.privacy.dispatch_event("not_needed",a));if(e.purpose.consents[1])return void("accepted"!==advads.privacy.state&&advads.privacy.dispatch_event("accepted",a));"rejected"!==advads.privacy.state&&advads.privacy.dispatch_event("rejected",a)}}))}}),100);return advads.privacy.state},is_adsense_npa_enabled:function(){return!window.advads_options||!window.advads_options.privacy||!(!window.advads_options.privacy["show-non-personalized-adsense"]||"custom"!==window.advads_options.privacy["consent-method"])},dispatch_event:function(e,t){var a=advads.privacy.state;advads.privacy.state=e,window.advanced_ads_ready_queue.push((function(){document.dispatchEvent(new CustomEvent("advanced_ads_privacy",{detail:{state:e,previousState:a,userAction:t}}))}))},is_ad_decoded:function(e){return null===document.querySelector('script[data-tcf="waiting-for-consent"][data-id="'+e+'"]')},decode_ad:function(e,t){t="boolean"!=typeof t||t;var a=decodeURIComponent(Array.prototype.map.call(atob(e.textContent),(function(e){return"%"+("00"+e.charCodeAt(0).toString(16)).slice(-2)})).join(""));if(!t)return a;e.replaceWith(document.createRange().createContextualFragment(a))}}},window.advanced_ads_ready_queue.push(advads.privacy.get_state),document.addEventListener("advanced_ads_privacy",(function(e){"accepted"!==e.detail.state&&"not_needed"!==e.detail.state||e.detail.userAction||"loading"===document.readyState||document.querySelectorAll('script[type="text/plain"][data-tcf="waiting-for-consent"]').forEach(advads.privacy.decode_ad)}));
public/class-advanced-ads.php CHANGED
@@ -44,14 +44,14 @@ class Advanced_Ads {
44
  *
45
  * @var array Ads already loaded in the frontend
46
  */
47
- public $current_ads = array();
48
 
49
  /**
50
  * Ad types
51
  *
52
  * @var array Ad types
53
  */
54
- public $ad_types = array();
55
 
56
  /**
57
  * Plugin options
@@ -89,7 +89,7 @@ class Advanced_Ads {
89
  *
90
  * @var array list of bots
91
  */
92
- protected $bots = array( 'bot', 'spider', 'crawler', 'scraper', 'parser', '008', 'Accoona-AI-Agent', 'ADmantX', 'alexa', 'appie', 'Apple-PubSub', 'Arachmo', 'Ask Jeeves', 'avira\.com', 'B-l-i-t-z-B-O-T', 'boitho\.com-dc', 'BUbiNG', 'Cerberian Drtrs', 'Charlotte', 'cosmos', 'Covario IDS', 'curl', 'Datanyze', 'DataparkSearch', 'Dataprovider\.com', 'DDG-Android', 'Ecosia', 'expo9', 'facebookexternalhit', 'Feedfetcher-Google', 'FindLinks', 'Firefly', 'froogle', 'Genieo', 'heritrix', 'Holmes', 'htdig', 'https://developers\.google\.com', 'ia_archiver', 'ichiro', 'igdeSpyder', 'InfoSeek', 'inktomi', 'Kraken', 'L\.webis', 'Larbin', 'Linguee', 'LinkWalker', 'looksmart', 'lwp-trivial', 'mabontland', 'Mnogosearch', 'mogimogi', 'Morning Paper', 'MVAClient', 'NationalDirectory', 'NetResearchServer', 'NewsGator', 'NG-Search', 'Nusearch', 'NutchCVS', 'Nymesis', 'oegp', 'Orbiter', 'Peew', 'Pompos', 'PostPost', 'proximic', 'PycURL', 'Qseero', 'rabaz', 'Radian6', 'Reeder', 'savetheworldheritage', 'SBIder', 'Scooter', 'ScoutJet', 'Scrubby', 'SearchSight', 'semanticdiscovery', 'Sensis', 'ShopWiki', 'silk', 'Snappy', 'Spade', 'Sqworm', 'StackRambler', 'TechnoratiSnoop', 'TECNOSEEK', 'Teoma', 'Thumbnail\.CZ', 'TinEye', 'truwoGPS', 'updated', 'Vagabondo', 'voltron', 'Vortex', 'voyager', 'VYU2', 'WebBug', 'webcollage', 'WebIndex', 'Websquash\.com', 'WeSEE:Ads', 'wf84', 'Wget', 'WomlpeFactory', 'WordPress', 'yacy', 'Yahoo! Slurp', 'Yahoo! Slurp China', 'YahooSeeker', 'YahooSeeker-Testing', 'YandexBot', 'YandexMedia', 'YandexBlogs', 'YandexNews', 'YandexCalendar', 'YandexImages', 'Yeti', 'yoogliFetchAgent', 'Zao', 'ZyBorg', 'okhttp', 'ips-agent', 'ltx71', 'Optimizer', 'Daum', 'Qwantify' );
93
 
94
  /**
95
  * Loaded instance of Advanced_Ads_Model
@@ -124,7 +124,7 @@ class Advanced_Ads {
124
  *
125
  * @var array
126
  */
127
- private $number_of_ads = array();
128
 
129
  /**
130
  * Reason why are disabled.
@@ -149,18 +149,18 @@ class Advanced_Ads {
149
  $this->ad_selector = Advanced_Ads_Select::get_instance();
150
 
151
  // initialize plugin specific functions.
152
- add_action( 'init', array( $this, 'wp_init' ) );
153
 
154
  // only when not doing ajax.
155
  if ( wp_doing_ajax() ) {
156
  Advanced_Ads_Ajax::get_instance();
157
  }
158
- add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ) );
159
 
160
  // allow add-ons to interact.
161
- add_action( 'init', array( $this, 'advanced_ads_loaded' ), 9 );
162
 
163
- add_filter( 'the_content', array( $this, 'set_was_in_the_loop' ), ~PHP_INT_MAX );
164
  }
165
 
166
  /**
@@ -201,25 +201,25 @@ class Advanced_Ads {
201
  public function wp_plugins_loaded() {
202
  // register hook for global constants.
203
  // Wait until BuddyPress assigns `WP_Query->is_404` back to `false`.
204
- add_action( 'template_redirect', array( $this, 'set_disabled_constant' ), 11 );
205
- add_action( 'rest_api_init', array( $this, 'set_disabled_constant' ) );
206
 
207
  // setup default ad types.
208
- add_filter( 'advanced-ads-ad-types', array( $this, 'setup_default_ad_types' ), 5 );
209
 
210
  // register hooks and filters for auto ad injection.
211
  $this->init_injection();
212
 
213
  // add meta robots noindex, nofollow to images, which are part of 'Image ad' ad type.
214
- add_action( 'wp_head', array( $this, 'noindex_attachment_images' ) );
215
 
216
  // use custom CSS or other custom header code.
217
- add_action( 'wp_head', array( $this, 'custom_header_code' ) );
218
 
219
  // check if ads are disabled in secondary queries.
220
- add_action( 'the_post', array( $this, 'set_query_type' ), 10, 2 );
221
- add_action( 'loop_start', array( $this, 'set_loop_start' ), 10, 0 );
222
- add_action( 'loop_end', array( $this, 'set_loop_end' ), 10, 0 );
223
 
224
  // register debug parameter
225
  $this->debug_parameter();
@@ -255,7 +255,7 @@ class Advanced_Ads {
255
  * Load default ad type files
256
  * custom ad types can also be loaded in your own plugin or functions.php
257
  */
258
- $types = array();
259
 
260
  /**
261
  * Developers can add new ad types using this filter
@@ -269,9 +269,9 @@ class Advanced_Ads {
269
  */
270
  public function init_injection() {
271
  // -TODO abstract
272
- add_action( 'wp_head', array( $this, 'inject_header' ), 20 );
273
- add_action( 'wp_footer', array( $this, 'inject_footer' ), 20 );
274
- add_filter( 'the_content', array( $this, 'inject_content' ), $this->plugin->get_content_injection_priority() );
275
  }
276
 
277
  /**
@@ -355,7 +355,7 @@ class Advanced_Ads {
355
  if ( isset( $options['hide-for-user-role'] ) ) {
356
  $hide_for_roles = Advanced_Ads_Utils::maybe_translate_cap_to_role( $options['hide-for-user-role'] );
357
  } else {
358
- $hide_for_roles = array();
359
  }
360
  $user = wp_get_current_user();
361
 
@@ -449,11 +449,11 @@ class Advanced_Ads {
449
  * Injected ad into header
450
  */
451
  public function inject_header() {
452
- $placements = get_option( 'advads-ads-placements', array() );
453
  if ( is_array( $placements ) ) {
454
  foreach ( $placements as $_placement_id => $_placement ) {
455
  if ( isset( $_placement['type'] ) && 'header' === $_placement['type'] ) {
456
- $_options = isset( $_placement['options'] ) ? $_placement['options'] : array();
457
  // injecting ad code so we don’t run escaping here.
458
  // phpcs:ignore
459
  echo Advanced_Ads_Select::get_instance()->get_ad_by_method( $_placement_id, Advanced_Ads_Select::PLACEMENT, $_options );
@@ -468,11 +468,11 @@ class Advanced_Ads {
468
  * @since 1.1.0
469
  */
470
  public function inject_footer() {
471
- $placements = get_option( 'advads-ads-placements', array() );
472
  if ( is_array( $placements ) ) {
473
  foreach ( $placements as $_placement_id => $_placement ) {
474
  if ( isset( $_placement['type'] ) && 'footer' === $_placement['type'] ) {
475
- $_options = isset( $_placement['options'] ) ? $_placement['options'] : array();
476
  // injecting ad code so we don’t run escaping here.
477
  // phpcs:ignore
478
  echo Advanced_Ads_Select::get_instance()->get_ad_by_method( $_placement_id, Advanced_Ads_Select::PLACEMENT, $_options );
@@ -521,10 +521,10 @@ class Advanced_Ads {
521
 
522
  // run only within the loop on single pages of public post types.
523
  $public_post_types = get_post_types(
524
- array(
525
  'public' => true,
526
  'publicly_queryable' => true,
527
- ),
528
  'names',
529
  'or'
530
  );
@@ -552,7 +552,7 @@ class Advanced_Ads {
552
  }
553
  }
554
 
555
- $placements = get_option( 'advads-ads-placements', array() );
556
 
557
  if ( ! apply_filters( 'advanced-ads-can-inject-into-content', true, $content, $placements ) ) {
558
  return $content;
@@ -562,7 +562,7 @@ class Advanced_Ads {
562
  foreach ( $placements as $_placement_id => $_placement ) {
563
  if ( empty( $_placement['item'] ) || ! isset( $_placement['type'] ) ) {
564
  continue; }
565
- $_options = isset( $_placement['options'] ) ? $_placement['options'] : array();
566
 
567
  // check if injection is ok for a specific placement ID.
568
  if ( ! apply_filters( 'advanced-ads-can-inject-into-content-' . $_placement_id, true, $content, $_placement_id ) ) {
@@ -599,7 +599,7 @@ class Advanced_Ads {
599
  * @param array $args WP_Query arguments that are more specific that default.
600
  * @return array $ads array with post objects
601
  */
602
- public static function get_ads( $args = array() ) {
603
  return self::get_instance()->get_model()->get_ads( $args );
604
  }
605
 
@@ -611,7 +611,7 @@ class Advanced_Ads {
611
  * @return array $groups array with ad groups
612
  * @link http://codex.wordpress.org/Function_Reference/get_terms
613
  */
614
- public static function get_ad_groups( $args = array() ) {
615
  return self::get_instance()->get_model()->get_ad_groups( $args );
616
  }
617
 
@@ -734,7 +734,7 @@ class Advanced_Ads {
734
  // register ad group taxonomy.
735
  if ( ! taxonomy_exists( self::AD_GROUP_TAXONOMY ) ) {
736
  $post_type_params = $this->get_group_taxonomy_params();
737
- register_taxonomy( self::AD_GROUP_TAXONOMY, array( self::POST_TYPE_SLUG ), $post_type_params );
738
  }
739
 
740
  // register ad post type.
@@ -750,7 +750,7 @@ class Advanced_Ads {
750
  * @return array
751
  */
752
  protected function get_group_taxonomy_params() {
753
- $labels = array(
754
  'name' => _x( 'Ad Groups & Rotations', 'ad group general name', 'advanced-ads' ),
755
  'singular_name' => _x( 'Ad Group', 'ad group singular name', 'advanced-ads' ),
756
  'search_items' => __( 'Search Ad Groups', 'advanced-ads' ),
@@ -763,9 +763,9 @@ class Advanced_Ads {
763
  'new_item_name' => __( 'New Ad Groups Name', 'advanced-ads' ),
764
  'menu_name' => __( 'Groups', 'advanced-ads' ),
765
  'not_found' => __( 'No Ad Group found', 'advanced-ads' ),
766
- );
767
 
768
- $args = array(
769
  'public' => false,
770
  'hierarchical' => true,
771
  'labels' => $labels,
@@ -775,13 +775,13 @@ class Advanced_Ads {
775
  'show_admin_column' => true,
776
  'query_var' => false,
777
  'rewrite' => false,
778
- 'capabilities' => array(
779
  'manage_terms' => 'advanced_ads_edit_ads',
780
  'edit_terms' => 'advanced_ads_edit_ads',
781
  'delete_terms' => 'advanced_ads_edit_ads',
782
  'assign_terms' => 'advanced_ads_edit_ads',
783
- ),
784
- );
785
 
786
  return apply_filters( 'advanced-ads-group-taxonomy-params', $args );
787
  }
@@ -792,7 +792,7 @@ class Advanced_Ads {
792
  * @return array
793
  */
794
  protected function get_post_type_params() {
795
- $labels = array(
796
  'name' => __( 'Ads', 'advanced-ads' ),
797
  'singular_name' => __( 'Ad', 'advanced-ads' ),
798
  'add_new' => __( 'New Ad', 'advanced-ads' ),
@@ -806,20 +806,20 @@ class Advanced_Ads {
806
  'not_found' => __( 'No Ads found', 'advanced-ads' ),
807
  'not_found_in_trash' => __( 'No Ads found in Trash', 'advanced-ads' ),
808
  'parent' => __( 'Parent Ad', 'advanced-ads' ),
809
- );
810
 
811
- $supports = array( 'title', 'author' );
812
  if ( defined( 'ADVANCED_ADS_ENABLE_REVISIONS' ) ) {
813
  $supports[] = 'revisions';
814
  };
815
 
816
- $post_type_params = array(
817
  'labels' => $labels,
818
  'public' => false,
819
  'show_ui' => true,
820
  'show_in_menu' => false,
821
  'hierarchical' => false,
822
- 'capabilities' => array(
823
  // Meta capabilities.
824
  'edit_post' => 'advanced_ads_edit_ads',
825
  'read_post' => 'advanced_ads_edit_ads',
@@ -839,13 +839,13 @@ class Advanced_Ads {
839
  'edit_private_posts' => 'advanced_ads_edit_ads',
840
  'edit_published_posts' => 'advanced_ads_edit_ads',
841
  'create_posts' => 'advanced_ads_edit_ads',
842
- ),
843
  'has_archive' => false,
844
  'query_var' => false, // set to true and refresh your permalink settings to query ads under a public URL
845
  'rewrite' => false, // defaults to true and so needs to be set to false to prevent any public URL
846
  'supports' => $supports,
847
- 'taxonomies' => array( self::AD_GROUP_TAXONOMY ),
848
- );
849
 
850
  return apply_filters( 'advanced-ads-post-type-params', $post_type_params );
851
  }
@@ -999,7 +999,7 @@ class Advanced_Ads {
999
  $key = md5( serialize( $post_status ) );
1000
  // query number of ads only, if not retrieved, yet.
1001
  if ( ! isset( self::get_instance()->number_of_ads[ $key ] ) ) {
1002
- $args = array( 'post_status' => $post_status );
1003
  $recent_ads = self::get_instance()->get_model()->get_ads( $args );
1004
  self::get_instance()->number_of_ads[ $key ] = count( $recent_ads );
1005
  }
44
  *
45
  * @var array Ads already loaded in the frontend
46
  */
47
+ public $current_ads = [];
48
 
49
  /**
50
  * Ad types
51
  *
52
  * @var array Ad types
53
  */
54
+ public $ad_types = [];
55
 
56
  /**
57
  * Plugin options
89
  *
90
  * @var array list of bots
91
  */
92
+ protected $bots = [ 'bot', 'spider', 'crawler', 'scraper', 'parser', '008', 'Accoona-AI-Agent', 'ADmantX', 'alexa', 'appie', 'Apple-PubSub', 'Arachmo', 'Ask Jeeves', 'avira\.com', 'B-l-i-t-z-B-O-T', 'boitho\.com-dc', 'BUbiNG', 'Cerberian Drtrs', 'Charlotte', 'cosmos', 'Covario IDS', 'curl', 'Datanyze', 'DataparkSearch', 'Dataprovider\.com', 'DDG-Android', 'Ecosia', 'expo9', 'facebookexternalhit', 'Feedfetcher-Google', 'FindLinks', 'Firefly', 'froogle', 'Genieo', 'heritrix', 'Holmes', 'htdig', 'https://developers\.google\.com', 'ia_archiver', 'ichiro', 'igdeSpyder', 'InfoSeek', 'inktomi', 'Kraken', 'L\.webis', 'Larbin', 'Linguee', 'LinkWalker', 'looksmart', 'lwp-trivial', 'mabontland', 'Mnogosearch', 'mogimogi', 'Morning Paper', 'MVAClient', 'NationalDirectory', 'NetResearchServer', 'NewsGator', 'NG-Search', 'Nusearch', 'NutchCVS', 'Nymesis', 'oegp', 'Orbiter', 'Peew', 'Pompos', 'PostPost', 'proximic', 'PycURL', 'Qseero', 'rabaz', 'Radian6', 'Reeder', 'savetheworldheritage', 'SBIder', 'Scooter', 'ScoutJet', 'Scrubby', 'SearchSight', 'semanticdiscovery', 'Sensis', 'ShopWiki', 'silk', 'Snappy', 'Spade', 'Sqworm', 'StackRambler', 'TechnoratiSnoop', 'TECNOSEEK', 'Teoma', 'Thumbnail\.CZ', 'TinEye', 'truwoGPS', 'updated', 'Vagabondo', 'voltron', 'Vortex', 'voyager', 'VYU2', 'WebBug', 'webcollage', 'WebIndex', 'Websquash\.com', 'WeSEE:Ads', 'wf84', 'Wget', 'WomlpeFactory', 'WordPress', 'yacy', 'Yahoo! Slurp', 'Yahoo! Slurp China', 'YahooSeeker', 'YahooSeeker-Testing', 'YandexBot', 'YandexMedia', 'YandexBlogs', 'YandexNews', 'YandexCalendar', 'YandexImages', 'Yeti', 'yoogliFetchAgent', 'Zao', 'ZyBorg', 'okhttp', 'ips-agent', 'ltx71', 'Optimizer', 'Daum', 'Qwantify' ];
93
 
94
  /**
95
  * Loaded instance of Advanced_Ads_Model
124
  *
125
  * @var array
126
  */
127
+ private $number_of_ads = [];
128
 
129
  /**
130
  * Reason why are disabled.
149
  $this->ad_selector = Advanced_Ads_Select::get_instance();
150
 
151
  // initialize plugin specific functions.
152
+ add_action( 'init', [ $this, 'wp_init' ] );
153
 
154
  // only when not doing ajax.
155
  if ( wp_doing_ajax() ) {
156
  Advanced_Ads_Ajax::get_instance();
157
  }
158
+ add_action( 'plugins_loaded', [ $this, 'wp_plugins_loaded' ] );
159
 
160
  // allow add-ons to interact.
161
+ add_action( 'init', [ $this, 'advanced_ads_loaded' ], 9 );
162
 
163
+ add_filter( 'the_content', [ $this, 'set_was_in_the_loop' ], ~PHP_INT_MAX );
164
  }
165
 
166
  /**
201
  public function wp_plugins_loaded() {
202
  // register hook for global constants.
203
  // Wait until BuddyPress assigns `WP_Query->is_404` back to `false`.
204
+ add_action( 'template_redirect', [ $this, 'set_disabled_constant' ], 11 );
205
+ add_action( 'rest_api_init', [ $this, 'set_disabled_constant' ] );
206
 
207
  // setup default ad types.
208
+ add_filter( 'advanced-ads-ad-types', [ $this, 'setup_default_ad_types' ], 5 );
209
 
210
  // register hooks and filters for auto ad injection.
211
  $this->init_injection();
212
 
213
  // add meta robots noindex, nofollow to images, which are part of 'Image ad' ad type.
214
+ add_action( 'wp_head', [ $this, 'noindex_attachment_images' ] );
215
 
216
  // use custom CSS or other custom header code.
217
+ add_action( 'wp_head', [ $this, 'custom_header_code' ] );
218
 
219
  // check if ads are disabled in secondary queries.
220
+ add_action( 'the_post', [ $this, 'set_query_type' ], 10, 2 );
221
+ add_action( 'loop_start', [ $this, 'set_loop_start' ], 10, 0 );
222
+ add_action( 'loop_end', [ $this, 'set_loop_end' ], 10, 0 );
223
 
224
  // register debug parameter
225
  $this->debug_parameter();
255
  * Load default ad type files
256
  * custom ad types can also be loaded in your own plugin or functions.php
257
  */
258
+ $types = [];
259
 
260
  /**
261
  * Developers can add new ad types using this filter
269
  */
270
  public function init_injection() {
271
  // -TODO abstract
272
+ add_action( 'wp_head', [ $this, 'inject_header' ], 20 );
273
+ add_action( 'wp_footer', [ $this, 'inject_footer' ], 20 );
274
+ add_filter( 'the_content', [ $this, 'inject_content' ], $this->plugin->get_content_injection_priority() );
275
  }
276
 
277
  /**
355
  if ( isset( $options['hide-for-user-role'] ) ) {
356
  $hide_for_roles = Advanced_Ads_Utils::maybe_translate_cap_to_role( $options['hide-for-user-role'] );
357
  } else {
358
+ $hide_for_roles = [];
359
  }
360
  $user = wp_get_current_user();
361
 
449
  * Injected ad into header
450
  */
451
  public function inject_header() {
452
+ $placements = get_option( 'advads-ads-placements', [] );
453
  if ( is_array( $placements ) ) {
454
  foreach ( $placements as $_placement_id => $_placement ) {
455
  if ( isset( $_placement['type'] ) && 'header' === $_placement['type'] ) {
456
+ $_options = isset( $_placement['options'] ) ? $_placement['options'] : [];
457
  // injecting ad code so we don’t run escaping here.
458
  // phpcs:ignore
459
  echo Advanced_Ads_Select::get_instance()->get_ad_by_method( $_placement_id, Advanced_Ads_Select::PLACEMENT, $_options );
468
  * @since 1.1.0
469
  */
470
  public function inject_footer() {
471
+ $placements = get_option( 'advads-ads-placements', [] );
472
  if ( is_array( $placements ) ) {
473
  foreach ( $placements as $_placement_id => $_placement ) {
474
  if ( isset( $_placement['type'] ) && 'footer' === $_placement['type'] ) {
475
+ $_options = isset( $_placement['options'] ) ? $_placement['options'] : [];
476
  // injecting ad code so we don’t run escaping here.
477
  // phpcs:ignore
478
  echo Advanced_Ads_Select::get_instance()->get_ad_by_method( $_placement_id, Advanced_Ads_Select::PLACEMENT, $_options );
521
 
522
  // run only within the loop on single pages of public post types.
523
  $public_post_types = get_post_types(
524
+ [
525
  'public' => true,
526
  'publicly_queryable' => true,
527
+ ],
528
  'names',
529
  'or'
530
  );
552
  }
553
  }
554
 
555
+ $placements = get_option( 'advads-ads-placements', [] );
556
 
557
  if ( ! apply_filters( 'advanced-ads-can-inject-into-content', true, $content, $placements ) ) {
558
  return $content;
562
  foreach ( $placements as $_placement_id => $_placement ) {
563
  if ( empty( $_placement['item'] ) || ! isset( $_placement['type'] ) ) {
564
  continue; }
565
+ $_options = isset( $_placement['options'] ) ? $_placement['options'] : [];
566
 
567
  // check if injection is ok for a specific placement ID.
568
  if ( ! apply_filters( 'advanced-ads-can-inject-into-content-' . $_placement_id, true, $content, $_placement_id ) ) {
599
  * @param array $args WP_Query arguments that are more specific that default.
600
  * @return array $ads array with post objects
601
  */
602
+ public static function get_ads( $args = [] ) {
603
  return self::get_instance()->get_model()->get_ads( $args );
604
  }
605
 
611
  * @return array $groups array with ad groups
612
  * @link http://codex.wordpress.org/Function_Reference/get_terms
613
  */
614
+ public static function get_ad_groups( $args = [] ) {
615
  return self::get_instance()->get_model()->get_ad_groups( $args );
616
  }
617
 
734
  // register ad group taxonomy.
735
  if ( ! taxonomy_exists( self::AD_GROUP_TAXONOMY ) ) {
736
  $post_type_params = $this->get_group_taxonomy_params();
737
+ register_taxonomy( self::AD_GROUP_TAXONOMY, [ self::POST_TYPE_SLUG ], $post_type_params );
738
  }
739
 
740
  // register ad post type.
750
  * @return array
751
  */
752
  protected function get_group_taxonomy_params() {
753
+ $labels = [
754
  'name' => _x( 'Ad Groups & Rotations', 'ad group general name', 'advanced-ads' ),
755
  'singular_name' => _x( 'Ad Group', 'ad group singular name', 'advanced-ads' ),
756
  'search_items' => __( 'Search Ad Groups', 'advanced-ads' ),
763
  'new_item_name' => __( 'New Ad Groups Name', 'advanced-ads' ),
764
  'menu_name' => __( 'Groups', 'advanced-ads' ),
765
  'not_found' => __( 'No Ad Group found', 'advanced-ads' ),
766
+ ];
767
 
768
+ $args = [
769
  'public' => false,
770
  'hierarchical' => true,
771
  'labels' => $labels,
775
  'show_admin_column' => true,
776
  'query_var' => false,
777
  'rewrite' => false,
778
+ 'capabilities' => [
779
  'manage_terms' => 'advanced_ads_edit_ads',
780
  'edit_terms' => 'advanced_ads_edit_ads',
781
  'delete_terms' => 'advanced_ads_edit_ads',
782
  'assign_terms' => 'advanced_ads_edit_ads',
783
+ ],
784
+ ];
785
 
786
  return apply_filters( 'advanced-ads-group-taxonomy-params', $args );
787
  }
792
  * @return array
793
  */
794
  protected function get_post_type_params() {
795
+ $labels = [
796
  'name' => __( 'Ads', 'advanced-ads' ),
797
  'singular_name' => __( 'Ad', 'advanced-ads' ),
798
  'add_new' => __( 'New Ad', 'advanced-ads' ),
806
  'not_found' => __( 'No Ads found', 'advanced-ads' ),
807
  'not_found_in_trash' => __( 'No Ads found in Trash', 'advanced-ads' ),
808
  'parent' => __( 'Parent Ad', 'advanced-ads' ),
809
+ ];
810
 
811
+ $supports = [ 'title', 'author' ];
812
  if ( defined( 'ADVANCED_ADS_ENABLE_REVISIONS' ) ) {
813
  $supports[] = 'revisions';
814
  };
815
 
816
+ $post_type_params = [
817
  'labels' => $labels,
818
  'public' => false,
819
  'show_ui' => true,
820
  'show_in_menu' => false,
821
  'hierarchical' => false,
822
+ 'capabilities' => [
823
  // Meta capabilities.
824
  'edit_post' => 'advanced_ads_edit_ads',
825
  'read_post' => 'advanced_ads_edit_ads',
839
  'edit_private_posts' => 'advanced_ads_edit_ads',
840
  'edit_published_posts' => 'advanced_ads_edit_ads',
841
  'create_posts' => 'advanced_ads_edit_ads',
842
+ ],
843
  'has_archive' => false,
844
  'query_var' => false, // set to true and refresh your permalink settings to query ads under a public URL
845
  'rewrite' => false, // defaults to true and so needs to be set to false to prevent any public URL
846
  'supports' => $supports,
847
+ 'taxonomies' => [ self::AD_GROUP_TAXONOMY ],
848
+ ];
849
 
850
  return apply_filters( 'advanced-ads-post-type-params', $post_type_params );
851
  }
999
  $key = md5( serialize( $post_status ) );
1000
  // query number of ads only, if not retrieved, yet.
1001
  if ( ! isset( self::get_instance()->number_of_ads[ $key ] ) ) {
1002
+ $args = [ 'post_status' => $post_status ];
1003
  $recent_ads = self::get_instance()->get_model()->get_ads( $args );
1004
  self::get_instance()->number_of_ads[ $key ] = count( $recent_ads );
1005
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Tags: ads, adsense, amp, ads.txt, ad rotations, ad blocker, amazon, banner, clic
4
  Requires at least: 4.9
5
  Tested up to: 6.1
6
  Requires PHP: 7.2
7
- Stable tag: 1.37.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -88,9 +88,7 @@ serve ads by conditions based on the visitor. [List of all visitor conditions](h
88
 
89
  * display or hide a banner by device: mobile and tablet or desktop
90
  * display or hide a banner by role and for logged-in visitors
91
- * advanced visitor conditions: previously visited URL (referrer), user capability, browser language, browser and device included in [Pro](https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=wporg&utm_medium=link&utm_campaign=wp-features-pro-2)
92
- * display ads by geolocation with the [Geo Targeting add-on](https://wpadvancedads.com/add-ons/geo-targeting/?utm_source=wporg&utm_medium=link&utm_campaign=features
93
- )
94
  * display ads by browser width with the [Responsive add-on](https://wpadvancedads.com/add-ons/responsive-ads/?utm_source=wporg&utm_medium=link&utm_campaign=wp-features-responsive-1)
95
 
96
  > **Fantastic plugin and outstanding support**
@@ -156,7 +154,7 @@ https://vimeo.com/577170591
156
  >
157
  > * all add-ons include priority email support
158
  > * [All Access](https://wpadvancedads.com/add-ons/all-access/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – includes all available add-ons
159
- > * [Advanced Ads Pro](https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – powerful tools for ad optimizations: cache-busting, more placements, [lazy loading](https://wpadvancedads.com/lazy-load-ads/?utm_source=wporg&utm_medium=link&utm_campaign=features), ad blocker module, [click fraud protection](https://wpadvancedads.com/manual/click-fraud-protection/?utm_source=wporg&utm_medium=link&utm_campaign=features), and many more
160
  > * [Tracking](https://wpadvancedads.com/add-ons/tracking/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – track ad impressions and ad clicks with local methods or Google Analytics
161
  > * [Responsive Ads](https://wpadvancedads.com/add-ons/responsive-ads/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – target ads to specific browser sizes and create ads for AMP
162
  > * [Google Ad Manager Integration](https://wpadvancedads.com/add-ons/google-ad-manager/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – a quick and error-free way to load ad units from your Google Ad Manager (formerly Google DoubleClick for Publishers, DFP) account without touching any ad codes
@@ -336,38 +334,10 @@ Yes. You can use plenty of [hooks](https://wpadvancedads.com/codex/) to customiz
336
 
337
  == Changelog ==
338
 
339
- = 1.37.2 (November 2, 2022) =
340
-
341
- - Improvement: add manual links to display and visitor conditions
342
- - Improvement: sanitize the frontend prefix according to W3C valid class names
343
- - Improvement: update Black Friday / Cyber Monday promotion
344
- - Fix: remove the ad width and height before saving for responsive AdSense ads
345
-
346
- = 1.37.1 (October 25, 2022) =
347
-
348
- - Improvement: align the ad image preview in the Ad Parameters with other options
349
- - Improvement: order ads on the groups page by weight first and then by ad title
350
- - Fix: remove superfluous output above hints about cache-busting
351
- - Fix: ensure "Expired" and "Expiring" view stay active, when posts list is filtered or searched
352
- - Fix: allow saving an ad with an invalid user if the user was already the author of this ad
353
- - Fix: show a notice if positioning is used with responsive AdSense ads
354
-
355
- = 1.37.0 (October 11, 2022) =
356
-
357
- - Feature: bump minimum required PHP version to 7.2
358
- - Improvement: cleanup of the header items on list pages in the admin and unified layout elements
359
- - Improvement: show filters and search options on the ad, group, and placement list pages with the new Filters button in the page header
360
- - Improvement: show filters on the ad overview list permanently using the new Show Filters Permanently screen option
361
- - Improvement: unify the links and buttons in the header of admin pages related to Advanced Ads
362
- - Improvement: show the bulk options only when items in the ad list are selected
363
- - Improvement: hide the following columns on the ad list view by default: notes, size, author
364
- - Improvement: remove the background color for some ad status, like draft
365
- - Improvement: add a new "Type" column to the beginning of the ad list with a tooltip with more details
366
- - Improvement: add a new "Size" column for the ad size only
367
- - Improvement: add a "Notes" column for the ad description
368
- - Improvement: rename the "Title" Column into "Name"
369
- - Improvement: rename the Ad Details column into "Preview", showing only image ad previews
370
- - Improvement: search ad by post ID on the ad overview page
371
- - Fix: "All" view on the ad list not highlighted
372
- - Fix: show proper message for empty AdSense account
373
- - Fix: prevent undefined index notice on Ad Blocker setting in multisite
4
  Requires at least: 4.9
5
  Tested up to: 6.1
6
  Requires PHP: 7.2
7
+ Stable tag: 1.38.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
88
 
89
  * display or hide a banner by device: mobile and tablet or desktop
90
  * display or hide a banner by role and for logged-in visitors
91
+ * advanced visitor conditions: geolocation, previously visited URL (referrer), user capability, browser language, browser and device included in [Advanced Ads Pro](https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=wporg&utm_medium=link&utm_campaign=wp-features-pro-2)
 
 
92
  * display ads by browser width with the [Responsive add-on](https://wpadvancedads.com/add-ons/responsive-ads/?utm_source=wporg&utm_medium=link&utm_campaign=wp-features-responsive-1)
93
 
94
  > **Fantastic plugin and outstanding support**
154
  >
155
  > * all add-ons include priority email support
156
  > * [All Access](https://wpadvancedads.com/add-ons/all-access/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – includes all available add-ons
157
+ > * [Advanced Ads Pro](https://wpadvancedads.com/add-ons/advanced-ads-pro/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – powerful tools for ad optimizations: cache-busting, more placements, [lazy loading](https://wpadvancedads.com/lazy-load-ads/?utm_source=wporg&utm_medium=link&utm_campaign=features), ad blocker module, [click fraud protection](https://wpadvancedads.com/manual/click-fraud-protection/?utm_source=wporg&utm_medium=link&utm_campaign=features), [geo targeting](https://wpadvancedads.com/add-ons/geo-targeting/?utm_source=wporg&utm_medium=link&utm_campaign=features), and many more
158
  > * [Tracking](https://wpadvancedads.com/add-ons/tracking/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – track ad impressions and ad clicks with local methods or Google Analytics
159
  > * [Responsive Ads](https://wpadvancedads.com/add-ons/responsive-ads/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – target ads to specific browser sizes and create ads for AMP
160
  > * [Google Ad Manager Integration](https://wpadvancedads.com/add-ons/google-ad-manager/?utm_source=wporg&utm_medium=link&utm_campaign=wp-add-ons) – a quick and error-free way to load ad units from your Google Ad Manager (formerly Google DoubleClick for Publishers, DFP) account without touching any ad codes
334
 
335
  == Changelog ==
336
 
337
+ = 1.38.0 (November 22, 2022) =
338
+
339
+ - Improvement: add support for multibyte cookies in "advads.get/set_cookie" functions
340
+ - Improvement: update routine to remove all data on uninstall
341
+ - Improvement: unify the behavior and look of the group and placement lists
342
+ - Fix: serialize post meta in conditions to do string comparisons
343
+ - Fix: ensure the filters for placements work