Advanced Ads - Version 1.8.20

Version Description

  • added "placement_has_ads" and "group_has_ads" functions to test if a placement/group has not empty output
  • allowed to rotate ordered ads with same weight
Download this release

Release Info

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

Code changes from version 1.8.19 to 1.8.20

admin/includes/class-overview-widgets.php CHANGED
@@ -100,7 +100,7 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
100
  }
101
 
102
  if ( $is_subscribed ) {
103
- ?><a class="button button-primary" href="<?php echo ADVADS_URL; ?>add-ons/pro-bundle/#utm_source=advanced-ads&utm_medium=link&utm_campaign=pitch-bundle" target="_blank"><?php _e( 'Get the Pro Bundle', 'advanced-ads' ); ?></a><?php
104
  }
105
 
106
  /*$_notice = 'nl_adsense';
@@ -417,13 +417,13 @@ class Advanced_Ads_Overview_Widgets_Callbacks {
417
  }
418
  }
419
 
420
- // only show Pro Bundle Pitch if less than 2 add-ons exist
421
  if( $installed_pro_plugins < 2 ){
422
  $add_ons['bundle'] = array(
423
- 'title' => 'Pro Bundle',
424
- 'desc' => __( 'Our best deal with all current and future add-ons included.', 'advanced-ads' ),
425
- 'link' => ADVADS_URL . 'add-ons/bundle-pro/#utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
426
- 'link_title' => __( 'Get the Bundle', 'advanced-ads' ),
427
  'link_primary' => true,
428
  'order' => 0,
429
  );
100
  }
101
 
102
  if ( $is_subscribed ) {
103
+ ?><a class="button button-primary" href="<?php echo ADVADS_URL; ?>add-ons/all-access/#utm_source=advanced-ads&utm_medium=link&utm_campaign=pitch-bundle" target="_blank"><?php _e( 'Get the All Access pass', 'advanced-ads' ); ?></a><?php
104
  }
105
 
106
  /*$_notice = 'nl_adsense';
417
  }
418
  }
419
 
420
+ // only show All Access Pitch if less than 2 add-ons exist
421
  if( $installed_pro_plugins < 2 ){
422
  $add_ons['bundle'] = array(
423
+ 'title' => 'All Access',
424
+ 'desc' => __( 'Our best deal with all add-ons included.', 'advanced-ads' ),
425
+ 'link' => ADVADS_URL . 'add-ons/all-access/#utm_source=advanced-ads&utm_medium=link&utm_campaign=overview-add-ons',
426
+ 'link_title' => __( 'Get full access', 'advanced-ads' ),
427
  'link_primary' => true,
428
  'order' => 0,
429
  );
admin/views/pitch-bundle.php CHANGED
@@ -1,4 +1,4 @@
1
- <h3><?php _e( 'Pro Bundle – with all available add-ons', 'advanced-ads' ); ?></h3>
2
  <ul>
3
  <li><span class="dashicons dashicons-yes"></span><?php echo 'Advanced Ads Pro'; ?></li>
4
  <li><span class="dashicons dashicons-yes"></span><?php echo 'Tracking'; ?></li>
@@ -10,4 +10,4 @@
10
  <li><span class="dashicons dashicons-yes"></span><?php echo 'Ad Slider'; ?></li>
11
  </ul>
12
  <p><?php _e( 'Risk free with 30-day Money-Back guarantee', 'advanced-ads' ); ?></p>
13
- <a class="button button-primary" href="<?php echo ADVADS_URL; ?>add-ons/pro-bundle/#utm_source=advanced-ads&utm_medium=link&utm_campaign=pitch-bundle" target="_blank"><?php _e( 'Get the Pro Bundle', 'advanced-ads' ); ?></a>
1
+ <h3><?php _e( 'All Access – with all available add-ons', 'advanced-ads' ); ?></h3>
2
  <ul>
3
  <li><span class="dashicons dashicons-yes"></span><?php echo 'Advanced Ads Pro'; ?></li>
4
  <li><span class="dashicons dashicons-yes"></span><?php echo 'Tracking'; ?></li>
10
  <li><span class="dashicons dashicons-yes"></span><?php echo 'Ad Slider'; ?></li>
11
  </ul>
12
  <p><?php _e( 'Risk free with 30-day Money-Back guarantee', 'advanced-ads' ); ?></p>
13
+ <a class="button button-primary" href="<?php echo ADVADS_URL; ?>add-ons/all-access/#utm_source=advanced-ads&utm_medium=link&utm_campaign=pitch-bundle" target="_blank"><?php _e( 'Get the Pro Bundle', 'advanced-ads' ); ?></a>
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.8.19
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, textdomain
40
  define( 'ADVADS_SLUG', 'advanced-ads' );
41
  define( 'ADVADS_URL', 'https://wpadvancedads.com/' );
42
- define( 'ADVADS_VERSION', '1.8.19' );
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.8.20
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, textdomain
40
  define( 'ADVADS_SLUG', 'advanced-ads' );
41
  define( 'ADVADS_URL', 'https://wpadvancedads.com/' );
42
+ define( 'ADVADS_VERSION', '1.8.20' );
43
 
44
  /*----------------------------------------------------------------------------*
45
  * Autoloading, modules and functions
classes/ad_group.php CHANGED
@@ -225,9 +225,11 @@ class Advanced_Ads_Group {
225
  }
226
  }
227
 
228
- // add the group to the global output array
229
- $advads = Advanced_Ads::get_instance();
230
- $advads->current_ads[] = array('type' => 'group', 'id' => $this->id, 'title' => $this->name);
 
 
231
 
232
  if ( ! $output ) { return ''; }
233
 
@@ -283,9 +285,7 @@ class Advanced_Ads_Group {
283
  // order ads based on group type
284
  switch($this->type){
285
  case 'ordered' :
286
- // order to highest weight first
287
- arsort( $weights );
288
- $ordered_ad_ids = array_keys($weights);
289
  break;
290
  default : // default
291
  $ordered_ad_ids = $this->shuffle_ads($ads, $weights);
@@ -392,6 +392,36 @@ class Advanced_Ads_Group {
392
  return $shuffled_ads;
393
  }
394
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
395
  /**
396
  * get random ad by ad weight
397
  *
225
  }
226
  }
227
 
228
+ if ( ! isset( $args['global_output'] ) || $args['global_output'] ) {
229
+ // add the group to the global output array
230
+ $advads = Advanced_Ads::get_instance();
231
+ $advads->current_ads[] = array('type' => 'group', 'id' => $this->id, 'title' => $this->name);
232
+ }
233
 
234
  if ( ! $output ) { return ''; }
235
 
285
  // order ads based on group type
286
  switch($this->type){
287
  case 'ordered' :
288
+ $ordered_ad_ids = $this->shuffle_ordered_ads( $weights );
 
 
289
  break;
290
  default : // default
291
  $ordered_ad_ids = $this->shuffle_ads($ads, $weights);
392
  return $shuffled_ads;
393
  }
394
 
395
+ /**
396
+ * Shuffle ads that have the same width.
397
+ *
398
+ * @since untagged
399
+ * @param array $weights Array of $ad_id => weight pairs.
400
+ * @return array $ordered_ad_ids Ordered ad ids.
401
+ */
402
+ public function shuffle_ordered_ads( array $weights ) {
403
+ // order to highest weight first
404
+ arsort( $weights );
405
+ $ordered_ad_ids = array_keys( $weights );
406
+
407
+ $weights = array_values( $weights );
408
+ $count = count( $weights );
409
+ $pos = 0;
410
+ for ( $i = 1; $i <= $count; $i++ ) {
411
+ if ( $i == $count || $weights[ $i ] !== $weights[ $i - 1] ) {
412
+ $slice_len = $i - $pos;
413
+ if ( $slice_len !== 1 ) {
414
+ $shuffled = array_slice( $ordered_ad_ids, $pos, $slice_len );
415
+ shuffle ( $shuffled );
416
+ // Replace the unshuffled chunk with the shuffled one.
417
+ array_splice( $ordered_ad_ids, $pos, $slice_len, $shuffled );
418
+ }
419
+ $pos = $i;
420
+ }
421
+ }
422
+ return $ordered_ad_ids;
423
+ }
424
+
425
  /**
426
  * get random ad by ad weight
427
  *
classes/ad_placements.php CHANGED
@@ -314,7 +314,10 @@ class Advanced_Ads_Placements {
314
  // add the placement to the global output array
315
  $advads = Advanced_Ads::get_instance();
316
  $name = isset( $placement['name'] ) ? $placement['name'] : $id;
317
- $advads->current_ads[] = array( 'type' => 'placement', 'id' => $id, 'title' => $name );
 
 
 
318
 
319
  $result = Advanced_Ads_Select::get_instance()->get_ad_by_method( (int) $_item[1], $_item[0], $args );
320
 
314
  // add the placement to the global output array
315
  $advads = Advanced_Ads::get_instance();
316
  $name = isset( $placement['name'] ) ? $placement['name'] : $id;
317
+
318
+ if ( ! isset( $args['global_output'] ) || $args['global_output'] ) {
319
+ $advads->current_ads[] = array( 'type' => 'placement', 'id' => $id, 'title' => $name );
320
+ }
321
 
322
  $result = Advanced_Ads_Select::get_instance()->get_ad_by_method( (int) $_item[1], $_item[0], $args );
323
 
classes/ad_type_plain.php CHANGED
@@ -29,7 +29,7 @@ class Advanced_Ads_Ad_Type_Plain extends Advanced_Ads_Ad_Type_Abstract{
29
  */
30
  public function __construct() {
31
  $this->title = __( 'Plain Text and Code', 'advanced-ads' );
32
- $this->description = __( 'Simple text editor without any filters. You might use it to display unfiltered content, php code or javascript. Shortcodes and other WordPress content field magic does not work here.', 'advanced-ads' );
33
  $this->parameters = array(
34
  'content' => ''
35
  );
29
  */
30
  public function __construct() {
31
  $this->title = __( 'Plain Text and Code', 'advanced-ads' );
32
+ $this->description = __( 'Any ad network, Amazon, customized AdSense codes, shortcodes, and code like JavaScript, HTML or PHP.', 'advanced-ads' );
33
  $this->parameters = array(
34
  'content' => ''
35
  );
includes/functions.php CHANGED
@@ -90,11 +90,42 @@ function advads_can_display_ads(){
90
 
91
  /**
92
  * Are we currently on an AMP URL?
93
- * Will always return `false` if called before the `parse_query` hook.
94
  *
95
  * @return bool true if amp url, false otherwise
96
  */
97
  function advads_is_amp() {
 
 
 
 
98
  return ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() )
99
  || ( function_exists( 'is_wp_amp' ) && is_wp_amp() );
100
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  /**
92
  * Are we currently on an AMP URL?
93
+ * Will always return `false` and show PHP Notice if called before the `parse_query` hook.
94
  *
95
  * @return bool true if amp url, false otherwise
96
  */
97
  function advads_is_amp() {
98
+ if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
99
+ return false;
100
+ }
101
+
102
  return ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() )
103
  || ( function_exists( 'is_wp_amp' ) && is_wp_amp() );
104
+ }
105
+
106
+ /**
107
+ * Test if a placement has ads.
108
+ *
109
+ * @return bool
110
+ */
111
+ function placement_has_ads( $id = '' ) {
112
+ $args = array(
113
+ 'global_output' => false,
114
+ 'cache-busting' => 'ignore',
115
+ );
116
+ return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'placement', $args ) != '';
117
+
118
+ }
119
+
120
+ /**
121
+ * Test if a group has ads.
122
+ *
123
+ * @return bool
124
+ */
125
+ function group_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, 'group', $args ) != '';
131
+ }
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: ads, ad, ad inserter, ad injection, ad manager, ads manager, ad widget, ad
5
  Requires at least: 4.6
6
  Tested up to: 4.9
7
  Requires PHP: 5.2
8
- Stable tag: 1.8.19
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
@@ -230,6 +230,11 @@ Yes. Advanced Ads is based on WordPress standards and therefore easily customiza
230
 
231
  == Changelog ==
232
 
 
 
 
 
 
233
  = 1.8.19 =
234
 
235
  * delayed Ad Health checks for hidden AdSense ads
5
  Requires at least: 4.6
6
  Tested up to: 4.9
7
  Requires PHP: 5.2
8
+ Stable tag: 1.8.20
9
  License: GPLv2 or later
10
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
11
 
230
 
231
  == Changelog ==
232
 
233
+ = 1.8.20 =
234
+
235
+ * added "placement_has_ads" and "group_has_ads" functions to test if a placement/group has not empty output
236
+ * allowed to rotate ordered ads with same weight
237
+
238
  = 1.8.19 =
239
 
240
  * delayed Ad Health checks for hidden AdSense ads