Advanced Ads - Version 1.6.10.2

Version Description

  • warn on support page if ads are (partially) disabled
  • inform users of Pro that AdSense limit does not work with cache-busting
  • added hooks to extend content injection
  • group slug hidden, because it currently serves no purpose
  • fixed possible issues with content injection priority being lower than wpautop
Download this release

Release Info

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

Code changes from version 1.6.10.1 to 1.6.10.2

admin/class-advanced-ads-admin.php CHANGED
@@ -1010,7 +1010,12 @@ class Advanced_Ads_Admin {
1010
  $priority = ( isset($options['content-injection-priority'])) ? intval( $options['content-injection-priority'] ) : 100;
1011
 
1012
  echo '<input id="advanced-ads-content-injection-priority" type="number" value="'.$priority.'" name="'.ADVADS_SLUG.'[content-injection-priority]" size="3"/>';
1013
- echo '<p class="description">'. __( 'Play with this value in order to change the priority of the injected ads compared to other auto injected elements in the post content.', 'advanced-ads' ) .'</p>';
 
 
 
 
 
1014
  }
1015
 
1016
  /**
1010
  $priority = ( isset($options['content-injection-priority'])) ? intval( $options['content-injection-priority'] ) : 100;
1011
 
1012
  echo '<input id="advanced-ads-content-injection-priority" type="number" value="'.$priority.'" name="'.ADVADS_SLUG.'[content-injection-priority]" size="3"/>';
1013
+ echo '<p class="description">';
1014
+ if ( $priority < 11 ) {
1015
+ echo '<span class="advads-error-message">' . __( 'Please check your post content. A priority of 10 and below might cause issues (wpautop function might run twice).', 'advanced-ads' ) . '</span><br />';
1016
+ }
1017
+ _e( 'Play with this value in order to change the priority of the injected ads compared to other auto injected elements in the post content.', 'advanced-ads' );
1018
+ echo '</p>';
1019
  }
1020
 
1021
  /**
admin/views/ad-group-list-row.php CHANGED
@@ -18,7 +18,6 @@
18
  <ul><?php $_type = isset($this->types[$group->type]['title']) ? $this->types[$group->type]['title'] : 'default'; ?>
19
  <li><strong><?php printf( __( 'Type: %s', 'advanced-ads' ), $_type ); ?></strong></li>
20
  <li><?php printf( __( 'ID: %s', 'advanced-ads' ), $group->id ); ?></li>
21
- <li><?php printf( __( 'Slug: %s', 'advanced-ads' ), $group->slug ); ?></li>
22
  </ul>
23
  </td>
24
  <td class="advads-ad-group-list-ads"><?php $this->render_ads_list( $group ); ?></td>
18
  <ul><?php $_type = isset($this->types[$group->type]['title']) ? $this->types[$group->type]['title'] : 'default'; ?>
19
  <li><strong><?php printf( __( 'Type: %s', 'advanced-ads' ), $_type ); ?></strong></li>
20
  <li><?php printf( __( 'ID: %s', 'advanced-ads' ), $group->id ); ?></li>
 
21
  </ul>
22
  </td>
23
  <td class="advads-ad-group-list-ads"><?php $this->render_ads_list( $group ); ?></td>
admin/views/support.php CHANGED
@@ -43,6 +43,10 @@
43
  if( count( Advanced_Ads_Checks::conflicting_plugins() ) ) :
44
  $messages[] = sprintf(__( 'Plugins that are known to cause (partial) problems: <strong>%1$s</strong>. <a href="%2$s" target="_blank">Learn more</a>.', 'advanced-ads' ), implode( ', ', Advanced_Ads_Checks::conflicting_plugins() ), ADVADS_URL . 'manual/known-plugin-conflicts/');
45
  endif;
 
 
 
 
46
 
47
 
48
  if( count( $messages )) :
43
  if( count( Advanced_Ads_Checks::conflicting_plugins() ) ) :
44
  $messages[] = sprintf(__( 'Plugins that are known to cause (partial) problems: <strong>%1$s</strong>. <a href="%2$s" target="_blank">Learn more</a>.', 'advanced-ads' ), implode( ', ', Advanced_Ads_Checks::conflicting_plugins() ), ADVADS_URL . 'manual/known-plugin-conflicts/');
45
  endif;
46
+ $options = Advanced_Ads::get_instance()->options();
47
+ if( isset( $options['disabled-ads']) ){
48
+ $messages[] = sprintf(__( 'Ads are disabled for all or some pages. See "disabled ads" in <a href="%s">settings</a>.', 'advanced-ads' ), admin_url('admin.php?page=advanced-ads-settings#top#general') );
49
+ }
50
 
51
 
52
  if( count( $messages )) :
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.6.10.1
16
  * Author: Thomas Maier
17
  * Author URI: http://webgilde.com
18
  * Text Domain: advanced-ads
@@ -38,7 +38,7 @@ define( 'ADVADS_BASE_DIR', dirname( plugin_basename( __FILE__ ) ) ); // director
38
  // general and global slug, e.g. to store options in WP, textdomain
39
  define( 'ADVADS_SLUG', 'advanced-ads' );
40
  define( 'ADVADS_URL', 'https://wpadvancedads.com/' );
41
- define( 'ADVADS_VERSION', '1.6.10.1' );
42
 
43
  /*----------------------------------------------------------------------------*
44
  * 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.6.10.2
16
  * Author: Thomas Maier
17
  * Author URI: http://webgilde.com
18
  * Text Domain: advanced-ads
38
  // general and global slug, e.g. to store options in WP, textdomain
39
  define( 'ADVADS_SLUG', 'advanced-ads' );
40
  define( 'ADVADS_URL', 'https://wpadvancedads.com/' );
41
+ define( 'ADVADS_VERSION', '1.6.10.2' );
42
 
43
  /*----------------------------------------------------------------------------*
44
  * Autoloading, modules and functions
classes/ad_placements.php CHANGED
@@ -195,12 +195,12 @@ class Advanced_Ads_Placements {
195
  * @return arr $tags array with tags that can be used for content injection
196
  */
197
  public static function tags_for_content_injection(){
198
- $tags = array(
199
  'p' => sprintf( __( 'paragraph (%s)', 'advanced-ads' ), '&lt;p&gt;' ),
200
  'h2' => sprintf( __( 'headline 2 (%s)', 'advanced-ads' ), '&lt;h2&gt;' ),
201
  'h3' => sprintf( __( 'headline 3 (%s)', 'advanced-ads' ), '&lt;h3&gt;' ),
202
  'h4' => sprintf( __( 'headline 4 (%s)', 'advanced-ads' ), '&lt;h4&gt;' ),
203
- );
204
 
205
  return $tags;
206
  }
@@ -317,6 +317,10 @@ class Advanced_Ads_Placements {
317
  $content = mb_convert_encoding( $content, 'HTML-ENTITIES', $wpCharset );
318
  }
319
 
 
 
 
 
320
  $dom = new DOMDocument('1.0', $wpCharset);
321
  // may loose some fragments or add autop-like code
322
  libxml_use_internal_errors(true); // avoid notices and warnings - html is most likely malformed
@@ -342,21 +346,33 @@ class Advanced_Ads_Placements {
342
  $items = $xpath->query('/html/body/' . $tag);
343
  $offset = null;
344
 
345
- // if there are to few items at this level test nesting
346
- $itemLimit = $tag === 'p' ? 2 : 1;
347
- if ($items->length < $itemLimit) {
 
 
 
 
 
 
 
 
 
 
348
  $items = $xpath->query('/html/body/*/' . $tag);
349
  }
350
  // try third level as last resort
351
- if ($items->length < $itemLimit) {
352
  $items = $xpath->query('/html/body/*/*/' . $tag);
353
  }
354
 
 
 
355
 
356
  // filter empty tags from items
357
  $paragraphs = array();
358
  foreach ($items as $item) {
359
- if ( isset($item->textContent) && trim($item->textContent, $whitespaces) !== '' ) {
360
  $paragraphs[] = $item;
361
  }
362
  }
@@ -377,12 +393,14 @@ class Advanced_Ads_Placements {
377
  $adNode->appendXML($adContent);
378
 
379
  // inject
 
380
  if ($before) {
381
- $refNode = $paragraphs[$offset];
 
382
  $refNode->parentNode->insertBefore($adNode, $refNode);
383
  } else {
384
  // append before next node or as last child to body
385
- $refNode = $paragraphs[$offset]->nextSibling;
386
  if (isset($refNode)) {
387
  $refNode->parentNode->insertBefore($adNode, $refNode);
388
  } else {
195
  * @return arr $tags array with tags that can be used for content injection
196
  */
197
  public static function tags_for_content_injection(){
198
+ $tags = apply_filters( 'advanced-ads-tags-for-injection', array(
199
  'p' => sprintf( __( 'paragraph (%s)', 'advanced-ads' ), '&lt;p&gt;' ),
200
  'h2' => sprintf( __( 'headline 2 (%s)', 'advanced-ads' ), '&lt;h2&gt;' ),
201
  'h3' => sprintf( __( 'headline 3 (%s)', 'advanced-ads' ), '&lt;h3&gt;' ),
202
  'h4' => sprintf( __( 'headline 4 (%s)', 'advanced-ads' ), '&lt;h4&gt;' ),
203
+ ));
204
 
205
  return $tags;
206
  }
317
  $content = mb_convert_encoding( $content, 'HTML-ENTITIES', $wpCharset );
318
  }
319
 
320
+ if ( Advanced_Ads_Plugin::get_instance()->get_content_injection_priority() < 10 ) {
321
+ $content = wpautop( $content );
322
+ }
323
+
324
  $dom = new DOMDocument('1.0', $wpCharset);
325
  // may loose some fragments or add autop-like code
326
  libxml_use_internal_errors(true); // avoid notices and warnings - html is most likely malformed
346
  $items = $xpath->query('/html/body/' . $tag);
347
  $offset = null;
348
 
349
+ $options = array(
350
+ 'allowEmpty' => false, // whether the tag can be empty to be counted
351
+ );
352
+ // if there are too few items at this level test nesting
353
+ $options['itemLimit'] = $tag === 'p' ? 2 : 1;
354
+
355
+ // allow hooks to change some options
356
+ $options = apply_filters(
357
+ 'advanced-ads-placement-content-injection-options',
358
+ $options,
359
+ $tag );
360
+
361
+ if ($items->length < $options['itemLimit'] ) {
362
  $items = $xpath->query('/html/body/*/' . $tag);
363
  }
364
  // try third level as last resort
365
+ if ($items->length < $options['itemLimit']) {
366
  $items = $xpath->query('/html/body/*/*/' . $tag);
367
  }
368
 
369
+ // allow to select other elements
370
+ $items = apply_filters( 'advanced-ads-placement-content-injection-items', $items, $xpath, $tag );
371
 
372
  // filter empty tags from items
373
  $paragraphs = array();
374
  foreach ($items as $item) {
375
+ if ( $options['allowEmpty'] || ( isset($item->textContent) && trim($item->textContent, $whitespaces) !== '' ) ) {
376
  $paragraphs[] = $item;
377
  }
378
  }
393
  $adNode->appendXML($adContent);
394
 
395
  // inject
396
+ $node = apply_filters( 'advanced-ads-placement-content-injection-node', $paragraphs[$offset], $tag, $before );
397
  if ($before) {
398
+ $refNode = $node;
399
+ $items = $xpath->query('/html/body/' . $tag);
400
  $refNode->parentNode->insertBefore($adNode, $refNode);
401
  } else {
402
  // append before next node or as last child to body
403
+ $refNode = $node->nextSibling;
404
  if (isset($refNode)) {
405
  $refNode->parentNode->insertBefore($adNode, $refNode);
406
  } else {
classes/plugin.php CHANGED
@@ -469,4 +469,15 @@ class Advanced_Ads_Plugin {
469
  return $prefix;
470
  }
471
 
 
 
 
 
 
 
 
 
 
 
 
472
  }
469
  return $prefix;
470
  }
471
 
472
+ /**
473
+ * get priority used for injection inside content
474
+ *
475
+ * @since 1.6.10.2
476
+ */
477
+ public function get_content_injection_priority(){
478
+ $options = $this->options();
479
+
480
+ return isset( $options['content-injection-priority'] ) ? intval( $options['content-injection-priority'] ) : 100;
481
+ }
482
+
483
  }
modules/gadsense/admin/admin.php CHANGED
@@ -200,6 +200,10 @@ class Advanced_Ads_AdSense_Admin {
200
  esc_url( 'https://www.google.com/adsense/terms' ), 3
201
  ); ?><br/><?php
202
  _e( 'Notice: Advanced Ads only considers the AdSense ad type for this limit.', 'advanced-ads' );
 
 
 
 
203
  }
204
 
205
  /**
200
  esc_url( 'https://www.google.com/adsense/terms' ), 3
201
  ); ?><br/><?php
202
  _e( 'Notice: Advanced Ads only considers the AdSense ad type for this limit.', 'advanced-ads' );
203
+ ?></p>
204
+ <?php if( defined( 'AAP_VERSION' ) ) : /* give warning when cache-busting in Pro is active */ ?>
205
+ <p class="advads-error-message"><?php _e( 'Due to technical restrictions, the limit does not work on placements with cache-busting enabled.', 'advanced-ads' ); ?></p>
206
+ <?php endif;
207
  }
208
 
209
  /**
public/class-advanced-ads.php CHANGED
@@ -149,8 +149,6 @@ class Advanced_Ads {
149
  */
150
  public function wp_plugins_loaded()
151
  {
152
- $options = $this->plugin->options();
153
-
154
  // register hook for global constants
155
  add_action( 'wp', array( $this, 'set_disabled_constant' ) );
156
 
@@ -158,7 +156,7 @@ class Advanced_Ads {
158
  add_filter( 'advanced-ads-ad-types', array( $this, 'setup_default_ad_types' ), 5 );
159
 
160
  // register hooks and filters for auto ad injection
161
- $this->init_injection( $options );
162
 
163
  // allow add-ons to hook
164
  do_action( 'advanced-ads-plugin-loaded' );
@@ -204,12 +202,11 @@ class Advanced_Ads {
204
  $this->ad_types = apply_filters( 'advanced-ads-ad-types', $types );
205
  }
206
 
207
- public function init_injection($options) {
208
  // -TODO abstract
209
  add_action( 'wp_head', array( $this, 'inject_header' ), 20 );
210
  add_action( 'wp_footer', array( $this, 'inject_footer' ), 20 );
211
- $content_injection_priority = isset( $options['content-injection-priority'] ) ? intval( $options['content-injection-priority'] ) : 100;
212
- add_filter( 'the_content', array( $this, 'inject_content' ), $content_injection_priority );
213
  }
214
 
215
  /**
149
  */
150
  public function wp_plugins_loaded()
151
  {
 
 
152
  // register hook for global constants
153
  add_action( 'wp', array( $this, 'set_disabled_constant' ) );
154
 
156
  add_filter( 'advanced-ads-ad-types', array( $this, 'setup_default_ad_types' ), 5 );
157
 
158
  // register hooks and filters for auto ad injection
159
+ $this->init_injection();
160
 
161
  // allow add-ons to hook
162
  do_action( 'advanced-ads-plugin-loaded' );
202
  $this->ad_types = apply_filters( 'advanced-ads-ad-types', $types );
203
  }
204
 
205
+ public function init_injection() {
206
  // -TODO abstract
207
  add_action( 'wp_head', array( $this, 'inject_header' ), 20 );
208
  add_action( 'wp_footer', array( $this, 'inject_footer' ), 20 );
209
+ add_filter( 'the_content', array( $this, 'inject_content' ), $this->plugin->get_content_injection_priority() );
 
210
  }
211
 
212
  /**
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link:https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id
4
  Tags: ads, ad, adsense, display, banner, advertisements, adverts, advert, monetization
5
  Requires at least: WP 4.2, PHP 5.3
6
  Tested up to: 4.3.1
7
- Stable tag: 1.6.10.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -185,6 +185,14 @@ There is no revenue share. Advanced Ads doesn’t alter your ad codes in a way t
185
 
186
  == Changelog ==
187
 
 
 
 
 
 
 
 
 
188
  = 1.6.10.1 =
189
 
190
  * hotfix for empty id field
4
  Tags: ads, ad, adsense, display, banner, advertisements, adverts, advert, monetization
5
  Requires at least: WP 4.2, PHP 5.3
6
  Tested up to: 4.3.1
7
+ Stable tag: 1.6.10.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
185
 
186
  == Changelog ==
187
 
188
+ = 1.6.10.2 =
189
+
190
+ * warn on support page if ads are (partially) disabled
191
+ * inform users of Pro that AdSense limit does not work with cache-busting
192
+ * added hooks to extend content injection
193
+ * group slug hidden, because it currently serves no purpose
194
+ * fixed possible issues with content injection priority being lower than wpautop
195
+
196
  = 1.6.10.1 =
197
 
198
  * hotfix for empty id field