Advanced Ads - Version 1.3.7

Version Description

  • fixed bug with display conditions not working for custom post types and taxonomies
  • minor fix in ad injection
Download this release

Release Info

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

Code changes from version 1.3.6 to 1.3.7

Files changed (4) hide show
  1. advanced-ads.php +1 -1
  2. classes/ad.php +42 -2
  3. classes/ad_placements.php +2 -2
  4. readme.txt +6 -1
advanced-ads.php CHANGED
@@ -12,7 +12,7 @@
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: http://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
- * Version: 1.3.6
16
  * Author: Thomas Maier
17
  * Author URI: http://webgilde.com
18
  * Text Domain: advanced-ads
12
  * Plugin Name: Advanced Ads
13
  * Plugin URI: http://wpadvancedads.com
14
  * Description: Manage and optimize your ads in WordPress
15
+ * Version: 1.3.7
16
  * Author: Thomas Maier
17
  * Author URI: http://webgilde.com
18
  * Text Domain: advanced-ads
classes/ad.php CHANGED
@@ -306,15 +306,19 @@ class Advads_Ad {
306
  case 'categoryids' :
307
  // included
308
  if(is_singular() && empty($_cond_value['all'])){
 
 
 
309
  if(!empty($_cond_value['include'])){
310
  if(is_string($_cond_value['include'])){
311
  $category_ids = explode(',', $_cond_value['include']);
312
  } else {
313
  $category_ids = $_cond_value['include'];
314
  }
 
315
  // check if currently in a post (not post page, but also posts in loops)
316
  if(is_array($category_ids) && isset($post->ID)
317
- && !in_category($category_ids, $post)) {
318
  return false;
319
  }
320
  }
@@ -327,7 +331,7 @@ class Advads_Ad {
327
  }
328
  // check if currently in a post (not post page, but also posts in loops)
329
  if(is_array($category_ids) && isset($post->ID)
330
- && in_category($category_ids, $post) ) {
331
  // being only in one excluded category is enough to not display the ad
332
  return false;
333
  }
@@ -434,6 +438,42 @@ class Advads_Ad {
434
  return true;
435
  }
436
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
437
  /**
438
  * check visitor conditions
439
  *
306
  case 'categoryids' :
307
  // included
308
  if(is_singular() && empty($_cond_value['all'])){
309
+ // get all taxonomies of the post
310
+ $term_ids = $this->get_object_terms($post->ID);
311
+
312
  if(!empty($_cond_value['include'])){
313
  if(is_string($_cond_value['include'])){
314
  $category_ids = explode(',', $_cond_value['include']);
315
  } else {
316
  $category_ids = $_cond_value['include'];
317
  }
318
+
319
  // check if currently in a post (not post page, but also posts in loops)
320
  if(is_array($category_ids) && isset($post->ID)
321
+ && !count(array_intersect($category_ids, $term_ids))) { // is there any taxonomy the same?
322
  return false;
323
  }
324
  }
331
  }
332
  // check if currently in a post (not post page, but also posts in loops)
333
  if(is_array($category_ids) && isset($post->ID)
334
+ && count(array_intersect($category_ids, $term_ids))) { // is there any taxonomy the same
335
  // being only in one excluded category is enough to not display the ad
336
  return false;
337
  }
438
  return true;
439
  }
440
 
441
+ /**
442
+ * get all terms of a specific post or post type
443
+ *
444
+ * @param int $post_id id of the post
445
+ * @return arr $out ids of terms this post belongs to
446
+ */
447
+ private function get_object_terms($post_id = 0){
448
+
449
+ $post_id = absint($post_id);
450
+ if(!$post_id) return array();
451
+
452
+ // get post by post id
453
+ $post = get_post( $post_id );
454
+
455
+ // get post type by post
456
+ $post_type = $post->post_type;
457
+
458
+ // get post type taxonomies
459
+ $taxonomies = get_object_taxonomies( $post_type, 'objects' );
460
+
461
+ $term_ids = array();
462
+ foreach ( $taxonomies as $taxonomy_slug => $taxonomy ){
463
+
464
+ // get the terms related to post
465
+ $terms = get_the_terms( $post->ID, $taxonomy_slug );
466
+
467
+ if ( !empty( $terms ) ) {
468
+ foreach ( $terms as $term ) {
469
+ $term_ids[] = $term->term_id;
470
+ }
471
+ }
472
+ }
473
+
474
+ return $term_ids;
475
+ }
476
+
477
  /**
478
  * check visitor conditions
479
  *
classes/ad_placements.php CHANGED
@@ -239,8 +239,8 @@ class Advads_Ad_Placements {
239
  $running = true;
240
  foreach ($paragraphs as $index => $paragraph) {
241
 
242
- // check if current paragraph is empty and if so, increate offset
243
- if($running && $index > 0 && trim(str_replace(array('<p>', '&nbsp;'), '', $paragraph)) == '')
244
  $offset++;
245
 
246
  if (trim($paragraph)) {
239
  $running = true;
240
  foreach ($paragraphs as $index => $paragraph) {
241
 
242
+ // check if current paragraph is empty and if so, create offset
243
+ if($running && $index > 0 && trim(str_replace(array($tag, '&nbsp;'), '', $paragraph)) == '')
244
  $offset++;
245
 
246
  if (trim($paragraph)) {
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 3.5, PHP 5.3
6
  Tested up to: 4.1.
7
- Stable tag: 1.3.6
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -147,6 +147,11 @@ There is no revenue share. Advanced Ads doesn’t alter your ad codes in a way t
147
 
148
  == Changelog ==
149
 
 
 
 
 
 
150
  = 1.3.6 =
151
 
152
  * COOL: inject ads into content before or after specific paragraphs or headlines
4
  Tags: ads, ad, adsense, display, banner, advertisements, adverts, advert, monetization
5
  Requires at least: WP 3.5, PHP 5.3
6
  Tested up to: 4.1.
7
+ Stable tag: 1.3.7
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
147
 
148
  == Changelog ==
149
 
150
+ = 1.3.7 =
151
+
152
+ * fixed bug with display conditions not working for custom post types and taxonomies
153
+ * minor fix in ad injection
154
+
155
  = 1.3.6 =
156
 
157
  * COOL: inject ads into content before or after specific paragraphs or headlines