Advanced Ads - Version 1.13.2

Version Description

  • added AdSense ad slot ID to "AdSense hidden" warning
  • improved ads.txt test for existing files and other problems
  • fixed broken link preventing the Privacy settings from working
Download this release

Release Info

Developer webzunft
Plugin Icon 128x128 Advanced Ads
Version 1.13.2
Comparing to
See all releases

Code changes from version 1.13.1 to 1.13.2

admin/assets/js/admin.js CHANGED
@@ -637,7 +637,7 @@ jQuery( document ).ready(function ($) {
637
  advads_show_adsense_auto_ads_warning();
638
  }
639
 
640
- advads_ads_txt_check_third_party();
641
  });
642
 
643
 
@@ -852,34 +852,42 @@ function advads_show_adsense_auto_ads_warning() {
852
  /**
853
  * Check if a third-party ads.txt file exists.
854
  */
855
- function advads_ads_txt_check_third_party() {
856
- jQuery( '#advads-ads-txt-check-tp button' ).click( function() {
857
- var $wrapper = jQuery( this ).parent().hide();
858
- var $spinner = jQuery( '<span class="spinner advads-spinner"></span>' ).insertAfter( $wrapper );
859
-
860
- function result( exists, msg ) {
861
- $wrapper.show().find( 'span' ).hide();
862
- $spinner.remove();
863
- if ( exists !== null ) {
864
- $wrapper.find( '#advads-ads-txt-tpe').toggle( exists );
865
- $wrapper.find( '#advads-ads-txt-tpne').toggle( ! exists );
866
- } else {
867
- $wrapper.find( '#advads-ads-txt-tp-error' ).show().html( msg );
868
- }
869
- }
 
870
  jQuery.ajax( {
871
  type: 'POST',
872
  url: ajaxurl,
 
873
  data: {
874
  action: 'advads-ads-txt',
875
  nonce: advadsglobal.ajax_nonce
876
  },
877
  } ).done(function( response ) {
878
- result( '1' === response );
879
- } ).fail(function( jqXHR, textStatus ) {
880
- result( null, textStatus );
 
 
 
 
 
881
  } );
882
- } );
 
883
  }
884
 
885
  // Change JQueryUI names to fix name collision with other libraries, eg. Bootstrap
637
  advads_show_adsense_auto_ads_warning();
638
  }
639
 
640
+ advads_ads_txt_find_issues();
641
  });
642
 
643
 
852
  /**
853
  * Check if a third-party ads.txt file exists.
854
  */
855
+ function advads_ads_txt_find_issues() {
856
+ var $wrapper = jQuery( '#advads-ads-txt-notice-wrapper' );
857
+ var $refresh = jQuery( '#advads-ads-txt-notice-refresh' );
858
+
859
+ if ( ! $wrapper.find( 'ul' ).length ) {
860
+ load();
861
+ }
862
+
863
+ $refresh.click( function() {
864
+ load();
865
+ } );
866
+
867
+ function load() {
868
+ $wrapper.empty().append( jQuery( '<span class="spinner advads-spinner"></span>' ) );
869
+ $refresh.hide();
870
+
871
  jQuery.ajax( {
872
  type: 'POST',
873
  url: ajaxurl,
874
+ dataType: 'html',
875
  data: {
876
  action: 'advads-ads-txt',
877
  nonce: advadsglobal.ajax_nonce
878
  },
879
  } ).done(function( response ) {
880
+ $wrapper.html( response );
881
+ $refresh.show();
882
+ } ).fail(function( jqXHR ) {
883
+ $wrapper.html( '<p class="advads-error-message">'
884
+ + jQuery( '#advads-ads-txt-notice-error' ).text().replace( '%s', parseInt( jqXHR.status, 10 ) ),
885
+ + '</p>'
886
+ );
887
+ $refresh.show();
888
  } );
889
+ }
890
+
891
  }
892
 
893
  // Change JQueryUI names to fix name collision with other libraries, eg. Bootstrap
admin/includes/class-settings.php CHANGED
@@ -353,7 +353,7 @@ class Advanced_Ads_Admin_Settings {
353
  echo '<h3>' . esc_attr__( 'Are you missing something?', 'advanced-ads' ) . '</h3>';
354
 
355
  $link = ADVADS_URL . 'manual/how-to-install-an-add-on/#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses';
356
- echo '<p><a href="' . esc_url( $link ) . '" target="_blank">' . esc_attr__( 'How to install and activate an add-on.', 'advanced-ads' ) . '</p>';
357
 
358
  Advanced_Ads_Overview_Widgets_Callbacks::render_addons( true );
359
  }
353
  echo '<h3>' . esc_attr__( 'Are you missing something?', 'advanced-ads' ) . '</h3>';
354
 
355
  $link = ADVADS_URL . 'manual/how-to-install-an-add-on/#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses';
356
+ echo '<p><a href="' . esc_url( $link ) . '" target="_blank">' . esc_attr__( 'How to install and activate an add-on.', 'advanced-ads' ) . '</a></p>';
357
 
358
  Advanced_Ads_Overview_Widgets_Callbacks::render_addons( true );
359
  }
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.13.1
16
  * Author: Thomas Maier
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.13.1' );
43
 
44
  /*----------------------------------------------------------------------------*
45
  * Autoloading, modules and functions
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: https://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
+ * Version: 1.13.2
16
  * Author: Thomas Maier
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.13.2' );
43
 
44
  /*----------------------------------------------------------------------------*
45
  * Autoloading, modules and functions
classes/frontend_checks.php CHANGED
@@ -540,7 +540,8 @@ class Advanced_Ads_Frontend_Checks {
540
  jQuery( 'ins.adsbygoogle', context ).each( function() {
541
  // The parent container is invisible.
542
  if( ! jQuery( this ).parent().is(':visible') ){
543
- advads_ad_health_check_adsense_hidden_ids.push( this.dataset.adSlot );
 
544
  }
545
 
546
  // Zero width, perhaps because a parent container is floated
@@ -550,7 +551,6 @@ class Advanced_Ads_Frontend_Checks {
550
  });
551
  if( advads_ad_health_check_adsense_hidden_ids.length ){
552
  advanced_ads_frontend_checks.add_item_to_node( '.advanced_ads_ad_health_hidden_adsense', advads_ad_health_check_adsense_hidden_ids );
553
- advanced_ads_frontend_checks.add_item_to_notices( 'adsense_hidden' );
554
  }
555
  if ( responsive_zero_width.length ) {
556
  advanced_ads_frontend_checks.add_item_to_node( '.advanced_ads_ad_health_floated_responsive_adsense', responsive_zero_width );
540
  jQuery( 'ins.adsbygoogle', context ).each( function() {
541
  // The parent container is invisible.
542
  if( ! jQuery( this ).parent().is(':visible') ){
543
+ advads_ad_health_check_adsense_hidden_ids.push( this.dataset.adSlot );
544
+ advanced_ads_frontend_checks.add_item_to_notices( 'adsense_hidden', { mode: 'update', append_key: this.dataset.adSlot, append_text: ' ' + this.dataset.adSlot } );
545
  }
546
 
547
  // Zero width, perhaps because a parent container is floated
551
  });
552
  if( advads_ad_health_check_adsense_hidden_ids.length ){
553
  advanced_ads_frontend_checks.add_item_to_node( '.advanced_ads_ad_health_hidden_adsense', advads_ad_health_check_adsense_hidden_ids );
 
554
  }
555
  if ( responsive_zero_width.length ) {
556
  advanced_ads_frontend_checks.add_item_to_node( '.advanced_ads_ad_health_floated_responsive_adsense', responsive_zero_width );
languages/advanced-ads.pot CHANGED
@@ -3,7 +3,7 @@ msgid ""
3
  msgstr ""
4
  "Project-Id-Version: Advanved Ads\n"
5
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/plugin-name\n"
6
- "POT-Creation-Date: 2019-03-08 12:30+0000\n"
7
  "POT-Revision-Date: Wed Jul 13 2016 13:23:05 GMT+0200 (CEST)\n"
8
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
9
  "Last-Translator: Thomas Maier <post@webzunft.de>\n"
@@ -3098,30 +3098,36 @@ msgstr ""
3098
  msgid "Ad blocker counter"
3099
  msgstr ""
3100
 
3101
- #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:162
3102
  #, php-format
3103
  msgid ""
3104
  "The ads.txt file cannot be placed because the URL contains a subdirectory. "
3105
  "You need to make the file available at %s"
3106
  msgstr ""
3107
 
3108
- #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:167
3109
  #, php-format
3110
- msgid "The file is available on %s when it contains content to display."
 
 
 
 
 
 
 
 
 
 
3111
  msgstr ""
3112
 
3113
  #. %s the line that may need to be added manually
3114
- #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:173
3115
  #, php-format
3116
  msgid ""
3117
  "If your site is located on a subdomain, you need to add the following line "
3118
  "to the ads.txt file of the root domain: %s"
3119
  msgstr ""
3120
 
3121
- #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:179
3122
- msgid "File does not exist"
3123
- msgstr ""
3124
-
3125
  #: modules/gadsense/admin/admin.php:135
3126
  msgid "AdSense account"
3127
  msgstr ""
@@ -3571,17 +3577,8 @@ msgid ""
3571
  "automatically."
3572
  msgstr ""
3573
 
3574
- #: modules/ads-txt/admin/views/setting-check-third-party.php:2
3575
- msgid "Check for existing ads.txt file"
3576
- msgstr ""
3577
-
3578
- #: modules/ads-txt/admin/views/setting-check-third-party.php:4
3579
- #, php-format
3580
- msgid "Another ads.txt already exists: %s"
3581
- msgstr ""
3582
-
3583
- #: modules/ads-txt/admin/views/setting-check-third-party.php:5
3584
- msgid "No conflicting ads.txt file found"
3585
  msgstr ""
3586
 
3587
  #: modules/ads-txt/admin/views/setting-create.php:19
@@ -3591,7 +3588,7 @@ msgstr ""
3591
  #: modules/ads-txt/admin/views/setting-create.php:27
3592
  msgid ""
3593
  "Usually, this should be enabled on the main site of the network - often the "
3594
- "one without a subdomain or subdirectory)."
3595
  msgstr ""
3596
 
3597
  #: modules/gadsense/admin/views/adsense-account.php:29
3
  msgstr ""
4
  "Project-Id-Version: Advanved Ads\n"
5
  "Report-Msgid-Bugs-To: http://wordpress.org/plugins/plugin-name\n"
6
+ "POT-Creation-Date: 2019-03-12 10:03+0000\n"
7
  "POT-Revision-Date: Wed Jul 13 2016 13:23:05 GMT+0200 (CEST)\n"
8
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
9
  "Last-Translator: Thomas Maier <post@webzunft.de>\n"
3098
  msgid "Ad blocker counter"
3099
  msgstr ""
3100
 
3101
+ #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:166
3102
  #, php-format
3103
  msgid ""
3104
  "The ads.txt file cannot be placed because the URL contains a subdirectory. "
3105
  "You need to make the file available at %s"
3106
  msgstr ""
3107
 
3108
+ #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:177
3109
  #, php-format
3110
+ msgid "The file is available on %s."
3111
+ msgstr ""
3112
+
3113
+ #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:181
3114
+ msgid "The file was not created."
3115
+ msgstr ""
3116
+
3117
+ #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:192
3118
+ #: modules/ads-txt/admin/views/setting-additional-content.php:4
3119
+ #, php-format
3120
+ msgid "An error occured: %s."
3121
  msgstr ""
3122
 
3123
  #. %s the line that may need to be added manually
3124
+ #: modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php:205
3125
  #, php-format
3126
  msgid ""
3127
  "If your site is located on a subdomain, you need to add the following line "
3128
  "to the ads.txt file of the root domain: %s"
3129
  msgstr ""
3130
 
 
 
 
 
3131
  #: modules/gadsense/admin/admin.php:135
3132
  msgid "AdSense account"
3133
  msgstr ""
3577
  "automatically."
3578
  msgstr ""
3579
 
3580
+ #: modules/ads-txt/admin/views/setting-additional-content.php:5
3581
+ msgid "Check for problems"
 
 
 
 
 
 
 
 
 
3582
  msgstr ""
3583
 
3584
  #: modules/ads-txt/admin/views/setting-create.php:19
3588
  #: modules/ads-txt/admin/views/setting-create.php:27
3589
  msgid ""
3590
  "Usually, this should be enabled on the main site of the network - often the "
3591
+ "one without a subdomain or subdirectory."
3592
  msgstr ""
3593
 
3594
  #: modules/gadsense/admin/views/adsense-account.php:29
modules/ads-txt/admin/class-advanced-ads-ads-txt-admin.php CHANGED
@@ -7,6 +7,7 @@ class Advanced_Ads_Ads_Txt_Admin {
7
  * AdSense network ID.
8
  */
9
  const adsense = 'adsense';
 
10
  /**
11
  * Constructor
12
  *
@@ -18,9 +19,10 @@ class Advanced_Ads_Ads_Txt_Admin {
18
  add_filter( 'advanced-ads-sanitize-settings', array( $this, 'toggle' ), 10, 1 );
19
  add_action( 'update_option_advanced-ads-adsense', array( $this, 'update_adsense_option' ), 10, 2 );
20
  add_action( 'advanced-ads-settings-init', array( $this, 'add_settings' ) );
21
- add_action( 'wp_ajax_advads-ads-txt', array( $this, 'ajax_check_third_party_exists' ) );
22
  }
23
 
 
24
  /**
25
  * Toggle ads.txt and add additional content.
26
  *
@@ -146,7 +148,8 @@ class Advanced_Ads_Ads_Txt_Admin {
146
  /**
147
  * Get notices.
148
  *
149
- * @return string
 
150
  */
151
  public function get_notices() {
152
  $url = home_url( '/' );
@@ -154,6 +157,7 @@ class Advanced_Ads_Ads_Txt_Admin {
154
  if ( ! isset( $parsed_url['scheme'] ) || ! isset ( $parsed_url['host'] ) ) {
155
  return;
156
  }
 
157
  $notices = array();
158
  $link = sprintf( '<a href="%1$s" target="_blank">%1$s</a>', esc_url( $url . 'ads.txt' ) );
159
 
@@ -163,38 +167,87 @@ class Advanced_Ads_Ads_Txt_Admin {
163
  sprintf( '<a href="%1$s" target="_blank">%1$s</a>', esc_url( $parsed_url['scheme'] . '://' . $parsed_url['host'] ) )
164
  ) );
165
  } elseif ( $this->strategy->is_enabled() ) {
166
- $notices[] = array( '', sprintf(
167
- esc_html__( 'The file is available on %s when it contains content to display.', 'advanced-ads' ),
168
- $link
169
- ) );
170
- if ( Advanced_Ads_Ads_Txt_Utils::need_file_on_root_domain() ) {
171
- $notices[] = array( '', sprintf(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
172
  /* translators: %s the line that may need to be added manually */
173
  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' ),
174
  // Without http://.
175
  '<code>subdomain=' . esc_html( $parsed_url['host'] ) . '</code>'
176
  ) );
177
  }
178
- } else {
179
- $notices[] = array( '', esc_html__( 'File does not exist', 'advanced-ads' ) );
180
  }
181
 
182
-
183
- $r = '<ul>';
184
  foreach( $notices as $notice ) {
185
  $r .= sprintf( '<li class="%s">%s</li>', $notice[0], $notice[1] );
186
  }
187
  $r .= '</ul>';
188
 
189
- $tpe = Advanced_Ads_Ads_Txt_Utils::third_party_exists();
190
- ob_start();
191
- include dirname( __FILE__ ) . '/views/setting-check-third-party.php';
192
- $r .= ob_get_clean();
193
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  return $r;
195
  }
196
 
197
 
 
198
  /**
199
  * Get Adsense data.
200
  *
@@ -224,7 +277,7 @@ class Advanced_Ads_Ads_Txt_Admin {
224
  /**
225
  * Check if a third-party ads.txt file exists.
226
  */
227
- public function ajax_check_third_party_exists() {
228
 
229
  check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
230
 
@@ -232,11 +285,17 @@ class Advanced_Ads_Ads_Txt_Admin {
232
  return;
233
  }
234
 
235
- $r = Advanced_Ads_Ads_Txt_Utils::third_party_exists( null, true );
236
- echo $r;
237
  exit;
238
  }
239
 
 
 
 
 
 
 
 
240
  }
241
 
242
 
7
  * AdSense network ID.
8
  */
9
  const adsense = 'adsense';
10
+
11
  /**
12
  * Constructor
13
  *
19
  add_filter( 'advanced-ads-sanitize-settings', array( $this, 'toggle' ), 10, 1 );
20
  add_action( 'update_option_advanced-ads-adsense', array( $this, 'update_adsense_option' ), 10, 2 );
21
  add_action( 'advanced-ads-settings-init', array( $this, 'add_settings' ) );
22
+ add_action( 'wp_ajax_advads-ads-txt', array( $this, 'ajax_refresh_notices' ) );
23
  }
24
 
25
+
26
  /**
27
  * Toggle ads.txt and add additional content.
28
  *
148
  /**
149
  * Get notices.
150
  *
151
+ * @return string/bool Html markup on success or false if no cached data exists.
152
+ * In the latter case, an ajax request will fetch the data.
153
  */
154
  public function get_notices() {
155
  $url = home_url( '/' );
157
  if ( ! isset( $parsed_url['scheme'] ) || ! isset ( $parsed_url['host'] ) ) {
158
  return;
159
  }
160
+
161
  $notices = array();
162
  $link = sprintf( '<a href="%1$s" target="_blank">%1$s</a>', esc_url( $url . 'ads.txt' ) );
163
 
167
  sprintf( '<a href="%1$s" target="_blank">%1$s</a>', esc_url( $parsed_url['scheme'] . '://' . $parsed_url['host'] ) )
168
  ) );
169
  } elseif ( $this->strategy->is_enabled() ) {
170
+ if ( null === ( $file = $this->get_notice( 'get_file_info', $url ) ) ) {
171
+ return false;
172
+ }
173
+
174
+ if ( ! is_wp_error( $file )) {
175
+ if ( $file['exists'] ) {
176
+ $notices[] = array( '', sprintf(
177
+ esc_html__( 'The file is available on %s.', 'advanced-ads' ),
178
+ $link
179
+ ) );
180
+ } else {
181
+ $notices[] = array( '', esc_html__( 'The file was not created.', 'advanced-ads' ) );
182
+ }
183
+
184
+ if ( $file['is_third_party'] ) {
185
+ $notices[] = array( 'advads-error-message', sprintf(
186
+ esc_html__( 'A third-party file exists: %s' ),
187
+ $link
188
+ ) );
189
+ }
190
+ } else {
191
+ $notices[] = array( 'advads-error-message', sprintf(
192
+ esc_html__( 'An error occured: %s.', 'advanced-ads' ),
193
+ esc_html( $file->get_error_message() ) )
194
+ );
195
+ }
196
+
197
+
198
+ if ( null === ( $need_file_on_root_domain = $this->get_notice( 'need_file_on_root_domain', $url ) ) ) {
199
+ return false;
200
+ }
201
+
202
+ if ( $need_file_on_root_domain ) {
203
+ $notices[] = array( 'advads-ads-txt-nfor', sprintf(
204
  /* translators: %s the line that may need to be added manually */
205
  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' ),
206
  // Without http://.
207
  '<code>subdomain=' . esc_html( $parsed_url['host'] ) . '</code>'
208
  ) );
209
  }
 
 
210
  }
211
 
212
+ $r = '<ul id="advads-ads-txt-notices">';
 
213
  foreach( $notices as $notice ) {
214
  $r .= sprintf( '<li class="%s">%s</li>', $notice[0], $notice[1] );
215
  }
216
  $r .= '</ul>';
217
 
218
+ return $r;
219
+ }
 
 
220
 
221
+ /**
222
+ * Get a notice.
223
+ *
224
+ * @return null/bool Boolean on success or null if no cached data exists.
225
+ * In the latter case, this function should be called using AJAX
226
+ * to get fresh data.
227
+ */
228
+ public static function get_notice( $func, $url ) {
229
+ if ( ! method_exists( 'Advanced_Ads_Ads_Txt_Utils', $func ) ) {
230
+ return false;
231
+ }
232
+
233
+ $url = $url ? $url : home_url( '/' );
234
+ $is_ajax = defined( 'DOING_AJAX') && DOING_AJAX;
235
+ $key = self::get_transient_key();
236
+ $transient = get_transient( $key );
237
+
238
+ if ( ! $is_ajax ) {
239
+ return isset( $transient[ $func ] ) ? $transient[ $func ] : null;
240
+ }
241
+
242
+ $r = call_user_func( array( 'Advanced_Ads_Ads_Txt_Utils', $func ), $url );
243
+
244
+ $transient[ $func ] = $r;
245
+ set_transient( $key, $transient, WEEK_IN_SECONDS );
246
  return $r;
247
  }
248
 
249
 
250
+
251
  /**
252
  * Get Adsense data.
253
  *
277
  /**
278
  * Check if a third-party ads.txt file exists.
279
  */
280
+ public function ajax_refresh_notices() {
281
 
282
  check_ajax_referer( 'advanced-ads-admin-ajax-nonce', 'nonce' );
283
 
285
  return;
286
  }
287
 
288
+ echo $this->get_notices();
 
289
  exit;
290
  }
291
 
292
+ /**
293
+ * Get transient key.
294
+ */
295
+ public static function get_transient_key() {
296
+ return 'advanced_ads_ads_txt_ctp' . home_url( '/') ;
297
+ }
298
+
299
  }
300
 
301
 
modules/ads-txt/admin/views/setting-additional-content.php CHANGED
@@ -1,3 +1,5 @@
1
  <textarea cols="50" rows="5" name="advads-ads-txt-additional-content"><?php echo esc_textarea( $content ); ?></textarea>
2
  <p class="description"><?php esc_html_e( 'Additional records to add to the file, one record per line. AdSense is added automatically.', 'advanced-ads' ); ?></p>
3
- <p id="advads-ads-txt-result"><?php echo $notices; ?></p>
 
 
1
  <textarea cols="50" rows="5" name="advads-ads-txt-additional-content"><?php echo esc_textarea( $content ); ?></textarea>
2
  <p class="description"><?php esc_html_e( 'Additional records to add to the file, one record per line. AdSense is added automatically.', 'advanced-ads' ); ?></p>
3
+ <div id="advads-ads-txt-notice-wrapper"><?php echo $notices; ?></div>
4
+ <p class="advads-error-message hidden" id="advads-ads-txt-notice-error"><?php esc_html_e( 'An error occured: %s.', 'advanced-ads' ); ?></p>
5
+ <button class="button" type="button" id="advads-ads-txt-notice-refresh"><?php esc_html_e( 'Check for problems', 'advanced-ads' ); ?></button>
modules/ads-txt/admin/views/setting-check-third-party.php DELETED
@@ -1,7 +0,0 @@
1
- <div id="advads-ads-txt-check-tp">
2
- <button class="button" type="button" id="advads-check-ads-txt"><?php esc_html_e( 'Check for existing ads.txt file', 'advanced-ads' ); ?></button>
3
- <span <?php if ( ! $tpe ) { echo 'style="display: none;"'; } ?> class="advads-error-message" id="advads-ads-txt-tpe"><?php
4
- printf( esc_html__( 'Another ads.txt already exists: %s', 'advanced-ads' ), $link ); ?></span>
5
- <span <?php if ( $tpe ) { echo 'style="display: none;"'; } ?> id="advads-ads-txt-tpne"><?php esc_html_e( 'No conflicting ads.txt file found', 'advanced-ads' ); ?></span>
6
- <span id="advads-ads-txt-tp-error" class="advads-error-message"></span>
7
- </div>
 
 
 
 
 
 
 
modules/ads-txt/includes/class-advanced-ads-ads-txt-strategy.php CHANGED
@@ -138,8 +138,7 @@ class Advanced_Ads_Ads_Txt_Strategy {
138
  }
139
 
140
  $this->changed = false;
141
- delete_transient( Advanced_Ads_Ads_Txt_Utils::TRANSIENT );
142
-
143
  return true;
144
  }
145
 
138
  }
139
 
140
  $this->changed = false;
141
+ delete_transient( Advanced_Ads_Ads_Txt_Admin::get_transient_key() );
 
142
  return true;
143
  }
144
 
modules/ads-txt/includes/class-advanced-ads-ads-txt-utils.php CHANGED
@@ -3,33 +3,41 @@
3
  * User interface for managing the 'ads.txt' file.
4
  */
5
  class Advanced_Ads_Ads_Txt_Utils {
6
- const TRANSIENT = 'advanced_ads_ads_txt_ctp';
7
 
8
  /**
9
- * Check if a third-party 'ads.txt' file exists.
10
  *
11
- * @return bool
 
12
  */
13
- public static function third_party_exists( $url = null, $force = false ) {
14
  $url = $url ? $url : home_url( '/' );
15
 
16
- if ( false === ( $r = get_transient( self::TRANSIENT ) ) || $force ) {
17
- $response = wp_remote_get( trailingslashit( $url ) . 'ads.txt', array( 'timeout' => 3 ) );
18
- $code = wp_remote_retrieve_response_code( $response );
19
- $content = wp_remote_retrieve_body( $response );
20
- $content_type = wp_remote_retrieve_header( $response, 'content-type' );
21
-
22
- $r = ( ! is_wp_error( $response )
23
- && 404 !== $code
24
- && 'text/plain' === $content_type
25
- && false === strpos( $content, Advanced_Ads_Ads_Txt_Public::TOP ) ) ? 'yes' : 'no';
26
- set_transient( self::TRANSIENT, $r, WEEK_IN_SECONDS );
27
  }
28
 
29
- return 'yes' === $r;
 
 
 
 
 
 
 
 
 
 
30
  }
31
 
32
 
 
33
  /**
34
  * Check if the another 'ads.txt' file should be hosted on the root domain.
35
  *
@@ -38,6 +46,7 @@ class Advanced_Ads_Ads_Txt_Utils {
38
  public static function need_file_on_root_domain( $url = null ) {
39
  $url = $url ? $url : home_url( '/' );
40
 
 
41
  $parsed_url = wp_parse_url( $url );
42
  if ( ! isset( $parsed_url['host'] ) ) {
43
  return false;
@@ -55,14 +64,44 @@ class Advanced_Ads_Ads_Txt_Utils {
55
  return false;
56
  }
57
 
58
- // Example: `http://one.{net/org/gov/edu/co}.two`.
59
- $suffixes = array( 'net', 'org', 'gov', 'edu', 'co' );
60
- if ( 3 === $count && in_array( $host_parts[ $count - 2 ], $suffixes, true ) ) {
61
- return false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
 
63
  return true;
64
  }
65
 
 
 
 
 
 
 
 
 
 
66
  /**
67
  * Check if the site is in a subdirectory, for example 'http://one.two/three'.
68
  *
3
  * User interface for managing the 'ads.txt' file.
4
  */
5
  class Advanced_Ads_Ads_Txt_Utils {
6
+ private static $location;
7
 
8
  /**
9
+ * Get file info.
10
  *
11
+ * @return array/WP_Error An array containing 'exists', 'is_third_party'.
12
+ * A WP_Error upon error.
13
  */
14
+ public static function get_file_info( $url = null ) {
15
  $url = $url ? $url : home_url( '/' );
16
 
17
+ $response = wp_remote_get( trailingslashit( $url ) . 'ads.txt', array( 'timeout' => 3 ) );
18
+ $code = wp_remote_retrieve_response_code( $response );
19
+ $content = wp_remote_retrieve_body( $response );
20
+ $content_type = wp_remote_retrieve_header( $response, 'content-type' );
21
+
22
+ if ( is_wp_error( $response ) ) {
23
+ return $response;
 
 
 
 
24
  }
25
 
26
+ $file_exists = ! is_wp_error( $response )
27
+ && 404 !== $code
28
+ && ( false !== stripos( $content_type, 'text/plain' ) );
29
+ $header_exists = false !== strpos( $content, Advanced_Ads_Ads_Txt_Public::TOP );
30
+
31
+ $r = array(
32
+ 'exists' => $file_exists && $header_exists,
33
+ 'is_third_party' => $file_exists && ! $header_exists
34
+ );
35
+
36
+ return $r;
37
  }
38
 
39
 
40
+
41
  /**
42
  * Check if the another 'ads.txt' file should be hosted on the root domain.
43
  *
46
  public static function need_file_on_root_domain( $url = null ) {
47
  $url = $url ? $url : home_url( '/' );
48
 
49
+
50
  $parsed_url = wp_parse_url( $url );
51
  if ( ! isset( $parsed_url['host'] ) ) {
52
  return false;
64
  return false;
65
  }
66
 
67
+ if ( 3 === $count ) {
68
+ // Example: `http://one.{net/org/gov/edu/co}.two`.
69
+ $suffixes = array( 'net', 'org', 'gov', 'edu', 'co' );
70
+ if ( in_array( $host_parts[ $count - 2 ], $suffixes, true ) ) {
71
+ return false;
72
+ }
73
+
74
+ // `http://www.one.two` will only be crawled if `http://one.two` redirects to it.
75
+ // Check if such redirect exists.
76
+ if ( 'www' === $host_parts[0] ) {
77
+ /*
78
+ * Do not append `/ads.txt` because otherwise the redirect will not happen.
79
+ */
80
+ $no_www_url = $parsed_url['scheme'] . '://' . trailingslashit( $host_parts[1] . '.' . $host_parts[2] );
81
+
82
+ add_action( 'requests-requests.before_redirect', array( __CLASS__, 'collect_locations' ) );
83
+ wp_remote_get( $no_www_url, array( 'timeout' => 5, 'redirection' => 3 ) );
84
+ remove_action( 'requests-requests.before_redirect', array( __CLASS__, 'collect_locations' ) );
85
+
86
+ $no_www_url_parsed = wp_parse_url( self::$location );
87
+ if ( isset( $no_www_url_parsed['host'] ) && $no_www_url_parsed['host'] === $host ) {
88
+ return false;
89
+ }
90
+ }
91
  }
92
+
93
  return true;
94
  }
95
 
96
+ /**
97
+ * Collect last location.
98
+ *
99
+ * @return string $location An URL.
100
+ */
101
+ public static function collect_locations( $location ) {
102
+ self::$location = $location;
103
+ }
104
+
105
  /**
106
  * Check if the site is in a subdirectory, for example 'http://one.two/three'.
107
  *
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: ads, ad manager, ad rotation, adsense, banner
5
  Requires at least: 4.6
6
  Tested up to: 5.1
7
  Requires PHP: 5.4
8
- Stable tag: 1.13.1
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -286,6 +286,12 @@ Yes. Advanced Ads is based on WordPress standards and therefore easily customiza
286
 
287
  == Changelog ==
288
 
 
 
 
 
 
 
289
  = 1.13.1 =
290
 
291
  * fixed issue with PHP 7.1 and higher
5
  Requires at least: 4.6
6
  Tested up to: 5.1
7
  Requires PHP: 5.4
8
+ Stable tag: 1.13.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
286
 
287
  == Changelog ==
288
 
289
+ = 1.13.2 =
290
+
291
+ * added AdSense ad slot ID to "AdSense hidden" warning
292
+ * improved ads.txt test for existing files and other problems
293
+ * fixed broken link preventing the Privacy settings from working
294
+
295
  = 1.13.1 =
296
 
297
  * fixed issue with PHP 7.1 and higher