Advanced Ads - Version 1.14.3

Version Description

  • allow adding ads to newsletter emails created in MailPoet using the shortcode [custom:ad:AD_ID] in the email template
  • prevented error when Piklist plugin is used
  • fixed JS error on post edit pages that had no real consequences
  • minor fixes to licensing settings (Pro only)
Download this release

Release Info

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

Code changes from version 1.14.2 to 1.14.3

admin/assets/js/admin.js CHANGED
@@ -33,12 +33,12 @@ jQuery( document ).ready(function ($) {
33
  $( '#advanced-ad-type-adsense' ).trigger( 'click' );
34
  $( this ).closest( 'li' ).addClass( 'hidden' );
35
  } );
36
-
37
  $( document ).on('change', '#advanced-ad-type input', function () {
38
  var ad_type = $( this ).val()
39
  advads_load_ad_type_parameter_metabox( ad_type );
40
  });
41
-
42
  // trigger for ad injection after ad creation
43
  $( '#advads-ad-injection-box .advads-ad-injection-button' ).on( 'click', function(){
44
  var placement_type = this.dataset.placementType, // create new placement
@@ -90,7 +90,7 @@ jQuery( document ).ready(function ($) {
90
  // jQuery( '#advanced-ad-type input').prop( 'disabled', false );
91
  });
92
  });
93
-
94
  // activate general buttons
95
  if ( $.fn.advads_buttonset ) {
96
  $( '.advads-buttonset' ).advads_buttonset();
@@ -173,7 +173,7 @@ jQuery( document ).ready(function ($) {
173
  };
174
  };
175
  });
176
-
177
  // remove individual posts from the display conditions post list
178
  $( document ).on('click', '.advads-conditions-postid-buttons .button', function(e){
179
  $( this ).remove();
@@ -212,13 +212,13 @@ jQuery( document ).ready(function ($) {
212
  $(this).parents('.advads-conditions-table tr').prev('tr').remove();
213
  $(this).parents('.advads-conditions-table tr').remove();
214
  });
215
-
216
  // display new ad group form
217
  $( '#advads-new-ad-group-link' ).click(function(e){
218
  e.preventDefault();
219
  $( '#advads-new-group-form' ).show().find('input[type="text"]').focus();
220
  });
221
-
222
  // display ad groups form
223
  $( '#advads-ad-group-list a.edit, #advads-ad-group-list a.row-title' ).click(function(e){
224
  e.preventDefault();
@@ -270,13 +270,13 @@ jQuery( document ).ready(function ($) {
270
  usagediv.show();
271
  }
272
  });
273
- /**
274
  * automatically open all options and show usage link when this is the placement linked in the URL
275
  * also highlight the box with an effect for a short time
276
  */
277
  if( jQuery( window.location.hash ).length ){
278
  jQuery( window.location.hash ).find( '.advads-toggle-link + div, .advads-usage' ).show();
279
-
280
  }
281
 
282
  // group page: add ad to group
@@ -326,7 +326,7 @@ jQuery( document ).ready(function ($) {
326
  });
327
  }
328
  // set default group options for earch group
329
-
330
  advads_show_group_options( $( '.advads-ad-group-type input:checked' ) );
331
  // group page: hide ads if more than 4 – than only show 3
332
  $('.advads-ad-group-list-ads').each( function(){
@@ -343,15 +343,44 @@ jQuery( document ).ready(function ($) {
343
  * SETTINGS PAGE
344
  */
345
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  // activate licenses
347
  $('.advads-license-activate').click(function(){
348
 
349
- var button = $(this);
350
-
351
  if( ! this.dataset.addon ) { return }
352
-
353
- // hide button to prevent issues with activation when people click twice
354
- button.hide();
355
 
356
  var query = {
357
  action: 'advads-activate-license',
@@ -377,6 +406,7 @@ jQuery( document ).ready(function ($) {
377
  button.fadeOut();
378
  parent.find('.advads-license-activate-active').fadeIn();
379
  parent.find('input').prop('readonly', 'readonly');
 
380
  } else if( r === 'ex' ){
381
  var input = parent.find('input.advads-license-key');
382
  var link = parent.find('a.advads-renewal-link');
@@ -387,23 +417,22 @@ jQuery( document ).ready(function ($) {
387
  }
388
  parent.find('.advads-license-activate-error').remove();
389
  parent.find('.advads-license-expired-error').show();
390
- button.show();
391
  } else {
392
  parent.find('.advads-license-activate-error').show().text( r );
393
- button.show();
394
  }
395
  });
396
  });
397
-
398
  // deactivate licenses
399
  $('.advads-license-deactivate').click(function(){
400
 
401
  var button = $(this);
402
-
403
  if( ! this.dataset.addon ) { return }
404
-
405
- // hide button to prevent issues with double clicking
406
- button.hide();
407
 
408
  var query = {
409
  action: 'advads-deactivate-license',
@@ -427,24 +456,34 @@ jQuery( document ).ready(function ($) {
427
  button.siblings('.advads-license-activate').show();
428
  button.siblings('input').prop('readonly', false);
429
  button.fadeOut();
 
430
  } else if( r === 'ex' ){
431
  button.siblings('.advads-license-activate-error').hide();
432
  button.siblings('.advads-license-activate-active').hide();
433
  button.siblings('.advads-license-expired-error').show();
434
  button.siblings('input').prop('readonly', false);
435
  button.fadeOut();
 
436
  } else {
437
  console.log( r );
438
  button.siblings('.advads-license-activate-error').show().html( r );
439
  button.siblings('.advads-license-activate-active').hide();
440
- button.show();
441
  }
442
  });
443
  });
444
 
 
 
 
 
 
 
 
 
 
 
445
 
446
-
447
-
448
  /**
449
  * PLACEMENTS
450
  */
33
  $( '#advanced-ad-type-adsense' ).trigger( 'click' );
34
  $( this ).closest( 'li' ).addClass( 'hidden' );
35
  } );
36
+
37
  $( document ).on('change', '#advanced-ad-type input', function () {
38
  var ad_type = $( this ).val()
39
  advads_load_ad_type_parameter_metabox( ad_type );
40
  });
41
+
42
  // trigger for ad injection after ad creation
43
  $( '#advads-ad-injection-box .advads-ad-injection-button' ).on( 'click', function(){
44
  var placement_type = this.dataset.placementType, // create new placement
90
  // jQuery( '#advanced-ad-type input').prop( 'disabled', false );
91
  });
92
  });
93
+
94
  // activate general buttons
95
  if ( $.fn.advads_buttonset ) {
96
  $( '.advads-buttonset' ).advads_buttonset();
173
  };
174
  };
175
  });
176
+
177
  // remove individual posts from the display conditions post list
178
  $( document ).on('click', '.advads-conditions-postid-buttons .button', function(e){
179
  $( this ).remove();
212
  $(this).parents('.advads-conditions-table tr').prev('tr').remove();
213
  $(this).parents('.advads-conditions-table tr').remove();
214
  });
215
+
216
  // display new ad group form
217
  $( '#advads-new-ad-group-link' ).click(function(e){
218
  e.preventDefault();
219
  $( '#advads-new-group-form' ).show().find('input[type="text"]').focus();
220
  });
221
+
222
  // display ad groups form
223
  $( '#advads-ad-group-list a.edit, #advads-ad-group-list a.row-title' ).click(function(e){
224
  e.preventDefault();
270
  usagediv.show();
271
  }
272
  });
273
+ /**
274
  * automatically open all options and show usage link when this is the placement linked in the URL
275
  * also highlight the box with an effect for a short time
276
  */
277
  if( jQuery( window.location.hash ).length ){
278
  jQuery( window.location.hash ).find( '.advads-toggle-link + div, .advads-usage' ).show();
279
+
280
  }
281
 
282
  // group page: add ad to group
326
  });
327
  }
328
  // set default group options for earch group
329
+
330
  advads_show_group_options( $( '.advads-ad-group-type input:checked' ) );
331
  // group page: hide ads if more than 4 – than only show 3
332
  $('.advads-ad-group-list-ads').each( function(){
343
  * SETTINGS PAGE
344
  */
345
 
346
+ // automatically copy the first entered license key into all other empty fields
347
+ $('.advads-settings-tab-main-form .advads-license-key').blur( function(){
348
+ // get number of license fields
349
+
350
+ var license_key = $(this).val();
351
+
352
+ if( "" === license_key ){
353
+ return;
354
+ }
355
+
356
+ var license_fields = $('.advads-settings-tab-main-form .advads-license-key');
357
+ var license_fields_without_value = [];
358
+
359
+ // count license fields without value
360
+ license_fields.each( function( i, el ){
361
+ if( "" === $( el ).val() ){
362
+ license_fields_without_value.push( el );
363
+ }
364
+ } );
365
+
366
+ // if there is only one field filled then take its content (probably a license key) and add it into the other fields
367
+ if( license_fields.length === ( license_fields_without_value.length + 1 ) ){
368
+ $.each( license_fields_without_value, function( i, el ) {
369
+ $( el ).val( license_key );
370
+ } );
371
+ }
372
+
373
+
374
+ });
375
+
376
  // activate licenses
377
  $('.advads-license-activate').click(function(){
378
 
379
+ var button = $(this);
380
+
381
  if( ! this.dataset.addon ) { return }
382
+
383
+ advads_disable_license_buttons( true );
 
384
 
385
  var query = {
386
  action: 'advads-activate-license',
406
  button.fadeOut();
407
  parent.find('.advads-license-activate-active').fadeIn();
408
  parent.find('input').prop('readonly', 'readonly');
409
+ advads_disable_license_buttons( false );
410
  } else if( r === 'ex' ){
411
  var input = parent.find('input.advads-license-key');
412
  var link = parent.find('a.advads-renewal-link');
417
  }
418
  parent.find('.advads-license-activate-error').remove();
419
  parent.find('.advads-license-expired-error').show();
420
+ advads_disable_license_buttons( false );
421
  } else {
422
  parent.find('.advads-license-activate-error').show().text( r );
423
+ advads_disable_license_buttons( false );
424
  }
425
  });
426
  });
427
+
428
  // deactivate licenses
429
  $('.advads-license-deactivate').click(function(){
430
 
431
  var button = $(this);
432
+
433
  if( ! this.dataset.addon ) { return }
434
+
435
+ advads_disable_license_buttons( true );
 
436
 
437
  var query = {
438
  action: 'advads-deactivate-license',
456
  button.siblings('.advads-license-activate').show();
457
  button.siblings('input').prop('readonly', false);
458
  button.fadeOut();
459
+ advads_disable_license_buttons( false );
460
  } else if( r === 'ex' ){
461
  button.siblings('.advads-license-activate-error').hide();
462
  button.siblings('.advads-license-activate-active').hide();
463
  button.siblings('.advads-license-expired-error').show();
464
  button.siblings('input').prop('readonly', false);
465
  button.fadeOut();
466
+ advads_disable_license_buttons( false );
467
  } else {
468
  console.log( r );
469
  button.siblings('.advads-license-activate-error').show().html( r );
470
  button.siblings('.advads-license-activate-active').hide();
471
+ advads_disable_license_buttons( false );
472
  }
473
  });
474
  });
475
 
476
+ // toggle license buttons – disable or not
477
+ function advads_disable_license_buttons( disable = true ) {
478
+ var buttons = $('button.advads-license-activate, button.advads-license-deactivate'); // all activation buttons
479
+ // disable all buttons to prevent issues when users try to enable multiple licenses at the same time
480
+ if (disable) {
481
+ buttons.attr('disabled', 'disabled');
482
+ } else {
483
+ buttons.removeAttr( 'disabled' );
484
+ }
485
+ }
486
 
 
 
487
  /**
488
  * PLACEMENTS
489
  */
admin/includes/class-ad-network.php CHANGED
@@ -92,7 +92,7 @@ abstract class Advanced_Ads_Ad_Network{
92
  global $pagenow;
93
  $requires_settings = false;
94
  $requires_javascript = false;
95
-
96
  if ($pagenow == "admin.php") {
97
  $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
98
  switch ($page){
@@ -112,11 +112,14 @@ abstract class Advanced_Ads_Ad_Network{
112
  else if ($pagenow == 'post.php' || $pagenow == 'post-new.php'){
113
  $post_type = isset($_REQUEST['post_type']) ? $_REQUEST['post_type'] : '';
114
  add_filter('advanced-ads-ad-settings-pre-save', array($this, 'sanitize_ad_settings'));
115
- if (isset($_GET['action']) && 'edit' == $_GET['action']){
116
- $requires_javascript = true;
117
- }
118
- else if ($post_type == "advanced_ads"){
119
- $requires_javascript = true;
 
 
 
120
  }
121
  }
122
 
92
  global $pagenow;
93
  $requires_settings = false;
94
  $requires_javascript = false;
95
+
96
  if ($pagenow == "admin.php") {
97
  $page = isset($_REQUEST['page']) ? $_REQUEST['page'] : null;
98
  switch ($page){
112
  else if ($pagenow == 'post.php' || $pagenow == 'post-new.php'){
113
  $post_type = isset($_REQUEST['post_type']) ? $_REQUEST['post_type'] : '';
114
  add_filter('advanced-ads-ad-settings-pre-save', array($this, 'sanitize_ad_settings'));
115
+
116
+ if (Advanced_Ads_Admin::screen_belongs_to_advanced_ads()){
117
+ if (isset($_GET['action']) && 'edit' == $_GET['action']){
118
+ $requires_javascript = true;
119
+ }
120
+ else if ($post_type == "advanced_ads"){
121
+ $requires_javascript = true;
122
+ }
123
  }
124
  }
125
 
admin/includes/class-menu.php CHANGED
@@ -125,6 +125,16 @@ class Advanced_Ads_Admin_Menu {
125
  } else {
126
  $submenu['advanced-ads'][1][0] .= '&nbsp;<span class="update-plugins count-' . $notices. '"><span class="update-count">' . $notices . '</span></span>';
127
  }*/
 
 
 
 
 
 
 
 
 
 
128
  }
129
 
130
 
125
  } else {
126
  $submenu['advanced-ads'][1][0] .= '&nbsp;<span class="update-plugins count-' . $notices. '"><span class="update-count">' . $notices . '</span></span>';
127
  }*/
128
+ // link to license tab if they are invalid
129
+ if( Advanced_Ads_Checks::licenses_invalid() ){
130
+ $submenu['advanced-ads'][] = array(
131
+ __('Licenses', 'advanced-ads' ) // title.
132
+ . '&nbsp;<span class="update-plugins count-1"><span class="update-count">!</span></span>',
133
+ Advanced_Ads_Plugin::user_cap( 'advanced_ads_manage_options'), // capability
134
+ admin_url( 'admin.php?page=advanced-ads-settings#top#licenses' ),
135
+ __('Licenses', 'advanced-ads' ), // not sure what this is, but it is in the API
136
+ );
137
+ }
138
  }
139
 
140
 
admin/includes/class-notices.php CHANGED
@@ -170,20 +170,27 @@ class Advanced_Ads_Admin_Notices {
170
  $this->notices[] = 'nl_free_addons';
171
  }
172
  }
 
 
 
 
 
 
 
 
173
  // ask for a review after 2 days and when 3 ads were created and when not paused
174
  if ( ! in_array( 'review', $queue )
175
  && ! isset( $closed['review'] )
176
  && ( ! isset( $paused['review'] ) || $paused['review'] <= time() )
177
  && 172800 < ( time() - $activation)
178
- && 3 <= Advanced_Ads::get_number_of_ads()
179
  ) {
180
  $this->notices[] = 'review';
181
- } elseif ( 3 > Advanced_Ads::get_number_of_ads() ){
182
- // remove the notice in case the number of ads dropped
183
- $key = array_search( 'review', $this->notices );
184
- if ( $key !== false ) {
185
- unset( $this->notices[$key]);
186
- }
187
  }
188
  }
189
 
@@ -243,7 +250,7 @@ class Advanced_Ads_Admin_Notices {
243
  * move notice into "closed"
244
  *
245
  * @since 1.5.3
246
- * @param str $notice notice to be removed from the queue
247
  */
248
  public function remove_from_queue($notice) {
249
  if ( ! isset($notice) ) {
170
  $this->notices[] = 'nl_free_addons';
171
  }
172
  }
173
+ $number_of_ads = 0;
174
+ // needed error handling due to a weird bug in the piklist plugin
175
+ try {
176
+ $number_of_ads = Advanced_Ads::get_number_of_ads();
177
+ } catch ( Exception $e ) {
178
+
179
+ }
180
+
181
  // ask for a review after 2 days and when 3 ads were created and when not paused
182
  if ( ! in_array( 'review', $queue )
183
  && ! isset( $closed['review'] )
184
  && ( ! isset( $paused['review'] ) || $paused['review'] <= time() )
185
  && 172800 < ( time() - $activation)
186
+ && 3 <= $number_of_ads
187
  ) {
188
  $this->notices[] = 'review';
189
+ } elseif ( in_array( 'review', $queue ) && 3 > $number_of_ads ){
190
+ $review_key = array_search( 'review', $this->notices );
191
+ if ( $review_key !== false ) {
192
+ unset( $this->notices[ $review_key ] );
193
+ }
 
194
  }
195
  }
196
 
250
  * move notice into "closed"
251
  *
252
  * @since 1.5.3
253
+ * @param string $notice notice to be removed from the queue
254
  */
255
  public function remove_from_queue($notice) {
256
  if ( ! isset($notice) ) {
admin/views/setting-license.php CHANGED
@@ -1,74 +1,76 @@
1
  <?php
2
- $errortext = false;
3
- $expires = Advanced_Ads_Admin_Licenses::get_instance()->get_license_expires($options_slug);
4
- $expired = false;
5
- $expired_error = __('Your license expired.', 'advanced-ads');
6
 
7
  ob_start();
8
- ?><button type="button" class="button-secondary advads-license-activate"
9
- data-addon="<?php echo $index; ?>"
10
- data-pluginname="<?php echo $plugin_name; ?>"
11
- data-optionslug="<?php echo $options_slug; ?>"
12
- name="advads_license_activate"><?php _e('Update expiry date', 'advanced-ads'); ?></button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  <?php
14
- $update_button = ob_get_clean();
 
 
15
 
16
- $license_key_for_expired_link = $license_key ? $license_key : "%LICENSE_KEY%";
17
- $expired_error .= $expired_renew_link = ' ' . sprintf(__('Click on %2$s if you renewed it or have a subscription or <a href="%1$s" class="advads-renewal-link" target="_blank">renew your license</a>.', 'advanced-ads'), ADVADS_URL . 'checkout/?edd_license_key=' . esc_attr($license_key_for_expired_link) . '#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses', $update_button);
18
- if ('lifetime' !== $expires) {
19
- $expires_time = strtotime($expires);
20
- $days_left = ( $expires_time - time() ) / DAY_IN_SECONDS;
21
- }
22
- if ('lifetime' === $expires) {
23
- // do nothing
24
- } elseif ($days_left <= 0) {
25
- $plugin_url = isset($plugin_url) ? $plugin_url : ADVADS_URL;
26
- $errortext = $expired_error;
27
- $expired = true;
28
- } elseif (0 < $days_left && 31 > $days_left) {
29
- $errortext = sprintf(__('(%d days left)', 'advanced-ads'), $days_left);
30
  }
31
- $show_active = ( $license_status !== false && $license_status == 'valid' && !$expired ) ? true : false;
32
  ?>
33
- <input type="text" class="regular-text advads-license-key" placeholder="<?php _e('License key', 'advanced-ads'); ?>"
34
- name="<?php echo ADVADS_SLUG . '-licenses'; ?>[<?php echo $index; ?>]"
35
- value="<?php echo esc_attr($license_key); ?>"
36
- <?php
37
- if ($license_status !== false && $license_status == 'valid' && !$expired) :
38
- ?>
39
- readonly="readonly"<?php endif; ?>/>
40
 
41
- <button type="button" class="button-secondary advads-license-deactivate"
 
 
 
 
42
  <?php
43
- if ($license_status !== 'valid') {
44
- echo ' style="display: none;" ';
 
 
45
  }
46
  ?>
47
- data-addon="<?php echo $index; ?>"
48
- data-pluginname="<?php echo $plugin_name; ?>"
49
- data-optionslug="<?php echo $options_slug; ?>"
50
- name="advads_license_activate"><?php _e('Deactivate License', 'advanced-ads'); ?></button>
51
-
52
- <button type="button" class="button-primary advads-license-activate"
53
- data-addon="<?php echo $index; ?>"
54
- data-pluginname="<?php echo $plugin_name; ?>"
55
- data-optionslug="<?php echo $options_slug; ?>"
56
- name="advads_license_activate"><?php echo ( $license_status === 'valid' && !$expired ) ? __('Update License', 'advanced-ads') : __('Activate License', 'advanced-ads'); ?></button>
57
- <?php
58
- if ('' === trim($license_key)) {
59
- $errortext = __('Please enter a valid license key', 'advanced-ads');
60
- } elseif (!$expired && !$errortext) {
61
- $errortext = ( $license_status == 'invalid' ) ? __('License key invalid', 'advanced-ads') : '';
62
- }
63
- ?>
64
  &nbsp;
65
  <span class="advads-license-activate-active" <?php
66
- if (!$show_active) {
67
- echo 'style="display: none;"';
68
  }
69
- ?>><?php _e('active', 'advanced-ads'); ?></span>
70
  <span class="advads-license-activate-error" <?php
71
- if (!$errortext) {
72
- echo 'style="display: none;"';
73
  } ?>><?php echo $errortext; ?></span>
74
- <span class="advads-license-expired-error advads-error-message" style="display: none;"><?php echo $expired_error; ?></span>
 
1
  <?php
2
+ $errortext = false;
3
+ $expires = Advanced_Ads_Admin_Licenses::get_instance()->get_license_expires( $options_slug );
4
+ $expired = false;
5
+ $expired_error = __( 'Your license expired.', 'advanced-ads' );
6
 
7
  ob_start();
8
+ ?>
9
+ <button type="button" class="button-secondary advads-license-activate"
10
+ data-addon="<?php echo $index; ?>"
11
+ data-pluginname="<?php echo $plugin_name; ?>"
12
+ data-optionslug="<?php echo $options_slug; ?>"
13
+ name="advads_license_activate"><?php _e( 'Update expiry date', 'advanced-ads' ); ?></button>
14
+ <?php
15
+ $update_button = ob_get_clean();
16
+
17
+ $license_key_for_expired_link = $license_key ? $license_key : "%LICENSE_KEY%";
18
+ $expired_error .= $expired_renew_link = ' ' . sprintf( __( 'Click on %2$s if you renewed it or have a subscription or <a href="%1$s" class="advads-renewal-link" target="_blank">renew your license</a>.', 'advanced-ads' ), ADVADS_URL . 'checkout/?edd_license_key=' . esc_attr( $license_key_for_expired_link ) . '#utm_source=advanced-ads&utm_medium=link&utm_campaign=settings-licenses', $update_button );
19
+ if ( 'lifetime' !== $expires ) {
20
+ $expires_time = strtotime( $expires );
21
+ $days_left = ( $expires_time - time() ) / DAY_IN_SECONDS;
22
+ }
23
+ if ( 'lifetime' === $expires ) {
24
+ // do nothing
25
+ } elseif ( $expired && $days_left <= 0 ) {
26
+ $plugin_url = isset( $plugin_url ) ? $plugin_url : ADVADS_URL;
27
+ $errortext = $expired_error;
28
+ $expired = true;
29
+ } elseif ( 0 < $days_left && 31 > $days_left ) {
30
+ $errortext = sprintf( __( '(%d days left)', 'advanced-ads' ), $days_left );
31
+ }
32
+ $show_active = ( $license_status !== false && $license_status == 'valid' && ! $expired ) ? true : false;
33
+ ?>
34
+ <input type="text" class="regular-text advads-license-key" placeholder="<?php _e( 'License key', 'advanced-ads' ); ?>"
35
+ name="<?php echo ADVADS_SLUG . '-licenses'; ?>[<?php echo $index; ?>]"
36
+ value="<?php echo esc_attr( $license_key ); ?>"
37
  <?php
38
+ if ( $license_status !== false && $license_status == 'valid' && ! $expired ) :
39
+ ?>
40
+ readonly="readonly"<?php endif; ?>/>
41
 
42
+ <button type="button" class="button-secondary advads-license-deactivate"
43
+ <?php
44
+ if ( $license_status !== 'valid' ) {
45
+ echo ' style="display: none;" ';
 
 
 
 
 
 
 
 
 
 
46
  }
 
47
  ?>
48
+ data-addon="<?php echo $index; ?>"
49
+ data-pluginname="<?php echo $plugin_name; ?>"
50
+ data-optionslug="<?php echo $options_slug; ?>"
51
+ name="advads_license_activate"><?php _e( 'Deactivate License', 'advanced-ads' ); ?></button>
 
 
 
52
 
53
+ <button type="button" class="button-primary advads-license-activate"
54
+ data-addon="<?php echo $index; ?>"
55
+ data-pluginname="<?php echo $plugin_name; ?>"
56
+ data-optionslug="<?php echo $options_slug; ?>"
57
+ name="advads_license_activate"><?php echo ( $license_status === 'valid' && ! $expired ) ? __( 'Update License', 'advanced-ads' ) : __( 'Activate License', 'advanced-ads' ); ?></button>
58
  <?php
59
+ if ( '' === trim( $license_key ) ) {
60
+ $errortext = __( 'Please enter a valid license key', 'advanced-ads' );
61
+ } elseif ( ! $expired && ! $errortext ) {
62
+ $errortext = ( $license_status == 'invalid' ) ? __( 'License key invalid', 'advanced-ads' ) : '';
63
  }
64
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  &nbsp;
66
  <span class="advads-license-activate-active" <?php
67
+ if ( ! $show_active ) {
68
+ echo 'style="display: none;"';
69
  }
70
+ ?>><?php _e( 'active', 'advanced-ads' ); ?></span>
71
  <span class="advads-license-activate-error" <?php
72
+ if ( ! $errortext ) {
73
+ echo 'style="display: none;"';
74
  } ?>><?php echo $errortext; ?></span>
75
+ <span class="advads-license-expired-error advads-error-message"
76
+ style="display: none;"><?php echo $expired_error; ?></span>
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.14.2
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.14.2' );
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.14.3
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.14.3' );
43
 
44
  /*----------------------------------------------------------------------------*
45
  * Autoloading, modules and functions
classes/compatibility.php CHANGED
@@ -1,10 +1,15 @@
1
  <?php
2
 
3
  class Advanced_Ads_Compatibility {
 
 
 
 
4
  public function __construct() {
5
  // Elementor plugin.
6
  if ( defined( 'ELEMENTOR_VERSION' ) ) {
7
- add_filter( 'advanced-ads-placement-content-injection-xpath',
 
8
  array(
9
  $this,
10
  'content_injection_elementor',
@@ -20,6 +25,8 @@ class Advanced_Ads_Compatibility {
20
  add_filter( 'wpml_admin_language_switcher_active_languages', array( $this, 'wpml_language_switcher' ) );
21
  // Wordpress SEO by Yoast.
22
  add_filter( 'wpseo_sitemap_entry', array( $this, 'wordpress_seo_noindex_ad_attachments' ), 10, 3 );
 
 
23
  }
24
 
25
  /**
@@ -120,4 +127,61 @@ class Advanced_Ads_Compatibility {
120
 
121
  return $url;
122
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  }
1
  <?php
2
 
3
  class Advanced_Ads_Compatibility {
4
+
5
+ /**
6
+ * Advanced_Ads_Compatibility constructor.
7
+ */
8
  public function __construct() {
9
  // Elementor plugin.
10
  if ( defined( 'ELEMENTOR_VERSION' ) ) {
11
+ add_filter(
12
+ 'advanced-ads-placement-content-injection-xpath',
13
  array(
14
  $this,
15
  'content_injection_elementor',
25
  add_filter( 'wpml_admin_language_switcher_active_languages', array( $this, 'wpml_language_switcher' ) );
26
  // Wordpress SEO by Yoast.
27
  add_filter( 'wpseo_sitemap_entry', array( $this, 'wordpress_seo_noindex_ad_attachments' ), 10, 3 );
28
+ // Add shortcode for MailPoet.
29
+ add_filter( 'mailpoet_newsletter_shortcode', array( $this, 'mailpoet_ad_shortcode' ), 10, 5 );
30
  }
31
 
32
  /**
127
 
128
  return $url;
129
  }
130
+
131
+ /**
132
+ * Display an ad or ad group in a newsletter created by MailPoet.
133
+ * e.g., [custom:ad:123] to display ad with the ID 123
134
+ * [custom:ad_group:345] to display ad group with the ID 345
135
+ *
136
+ * @param string $shortcode
137
+ * @param $newsletter unused
138
+ * @param $subscriber unused
139
+ * @param $queue unused
140
+ * @param $newsletter_body unused
141
+ *
142
+ * @return string
143
+ */
144
+ function mailpoet_ad_shortcode( $shortcode, $newsletter, $subscriber, $queue, $newsletter_body ) {
145
+ // display an ad group.
146
+ if ( 0 === strpos( $shortcode, '[custom:ad_group:' ) ) {
147
+ // get ad group ID.
148
+ preg_match( '/\d+/', $shortcode, $matches );
149
+ $group_id = $matches[0];
150
+
151
+ // is returning an empty string when the ad group is not found good UI?
152
+ if ( empty( $group_id ) ) {
153
+ return '';
154
+ }
155
+
156
+ // only display if the ad group type could work, i.e. default (random) and ordered.
157
+ $ad_group = new Advanced_Ads_Group( $group_id );
158
+ if ( isset( $ad_group->type ) && in_array( $ad_group->type, array( 'default', 'ordered' ), true ) ) {
159
+ return get_ad_group( $group_id );
160
+ }
161
+
162
+ return '';
163
+
164
+ // display individual ad.
165
+ } elseif ( 0 === strpos( $shortcode, '[custom:ad:' ) ) {
166
+ // get ad ID.
167
+ preg_match( '/\d+/', $shortcode, $matches );
168
+ $ad_id = $matches[0];
169
+
170
+ // is returning an empty string when the ad is not found good UI?
171
+ if ( empty( $ad_id ) ) {
172
+ return '';
173
+ }
174
+
175
+ $ad = new Advanced_Ads_Ad( $ad_id );
176
+ // only display if the ad type could work, i.e. plain text and image ads.
177
+ if ( isset( $ad->type ) && in_array( $ad->type, array( 'plain', 'image' ), true ) ) {
178
+ return get_ad( $ad_id );
179
+ }
180
+
181
+ return '';
182
+ } else {
183
+ // always return the shortcode if it doesn't match your own!
184
+ return $shortcode;
185
+ }
186
+ }
187
  }
classes/plugin.php CHANGED
@@ -59,6 +59,7 @@ class Advanced_Ads_Plugin {
59
  register_uninstall_hook( ADVADS_BASE, array( 'Advanced_Ads_Plugin', 'uninstall' ) );
60
 
61
  add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ), 10 );
 
62
  }
63
 
64
  /**
@@ -85,15 +86,6 @@ class Advanced_Ads_Plugin {
85
  public function wp_plugins_loaded() {
86
  // Load plugin text domain
87
  $this->load_plugin_textdomain();
88
-
89
- $internal_options = $this->internal_options();
90
-
91
- /**
92
- * run upgrades, if this is a new version or version does not exist
93
- */
94
- if ( ! defined( 'DOING_AJAX' ) && ( ! isset( $internal_options['version'] ) || version_compare( $internal_options['version'], ADVADS_VERSION, '<' ) ) ) {
95
- new Advanced_Ads_Upgrades();
96
- }
97
 
98
  // activate plugin when new blog is added on multisites // -TODO this is admin-only
99
  add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
@@ -120,6 +112,24 @@ class Advanced_Ads_Plugin {
120
  Advanced_Ads_Ad_Health_Notices::get_instance(); // load to fetch notices
121
  }
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  /**
124
  * Register and enqueue public-facing style sheet.
125
  *
59
  register_uninstall_hook( ADVADS_BASE, array( 'Advanced_Ads_Plugin', 'uninstall' ) );
60
 
61
  add_action( 'plugins_loaded', array( $this, 'wp_plugins_loaded' ), 10 );
62
+ add_action( 'init', array( $this, 'run_upgrades' ), 9 );
63
  }
64
 
65
  /**
86
  public function wp_plugins_loaded() {
87
  // Load plugin text domain
88
  $this->load_plugin_textdomain();
 
 
 
 
 
 
 
 
 
89
 
90
  // activate plugin when new blog is added on multisites // -TODO this is admin-only
91
  add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );
112
  Advanced_Ads_Ad_Health_Notices::get_instance(); // load to fetch notices
113
  }
114
 
115
+ /**
116
+ * Run upgrades.
117
+ *
118
+ * Compatibility with the Piklist plugin that has a function hooked to `posts_where` that access $GLOBALS['wp_query'].
119
+ * Since `Advanced_Ads_Upgrades` applies `posts_where`: (`Advanced_Ads_Admin_Notices::get_instance()` >
120
+ * `Advanced_Ads::get_number_of_ads()` > new WP_Query > ... 'posts_where') this function is hooked to `init` so that `$GLOBALS['wp_query']` is instantiated.
121
+ */
122
+ public function run_upgrades() {
123
+ /**
124
+ * Run upgrades, if this is a new version or version does not exist.
125
+ */
126
+ $internal_options = $this->internal_options();
127
+
128
+ if ( ! defined( 'DOING_AJAX' ) && ( ! isset( $internal_options['version'] ) || version_compare( $internal_options['version'], ADVADS_VERSION, '<' ) ) ) {
129
+ new Advanced_Ads_Upgrades();
130
+ }
131
+ }
132
+
133
  /**
134
  * Register and enqueue public-facing style sheet.
135
  *
modules/gadsense/includes/class-ad-type-adsense.php CHANGED
@@ -272,7 +272,6 @@ class Advanced_Ads_Ad_Type_Adsense extends Advanced_Ads_Ad_Type_Abstract {
272
  break;
273
  case 'in-feed' :
274
  $format = 'fluid';
275
- $layout = $content->layout;
276
  $layout_key = $content->layout_key;
277
  break;
278
  case 'in-article' :
272
  break;
273
  case 'in-feed' :
274
  $format = 'fluid';
 
275
  $layout_key = $content->layout_key;
276
  break;
277
  case 'in-article' :
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.2
7
  Requires PHP: 5.6
8
- Stable tag: 1.14.2
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -290,6 +290,13 @@ Yes. Advanced Ads is based on WordPress standards and therefore easily customiza
290
 
291
  == Changelog ==
292
 
 
 
 
 
 
 
 
293
  = 1.14.2 =
294
 
295
  * preparations for [Advanced Ads Pro](https://wpadvancedads.com/add-ons/advanced-ads-pro/) 2.4.2
5
  Requires at least: 4.6
6
  Tested up to: 5.2
7
  Requires PHP: 5.6
8
+ Stable tag: 1.14.3
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
290
 
291
  == Changelog ==
292
 
293
+ = 1.14.3 =
294
+
295
+ * allow adding ads to newsletter emails created in MailPoet using the shortcode `[custom:ad:AD_ID]` in the email template
296
+ * prevented error when Piklist plugin is used
297
+ * fixed JS error on post edit pages that had no real consequences
298
+ * minor fixes to licensing settings (Pro only)
299
+
300
  = 1.14.2 =
301
 
302
  * preparations for [Advanced Ads Pro](https://wpadvancedads.com/add-ons/advanced-ads-pro/) 2.4.2