Advanced Ads - Version 1.3.12

Version Description

  • limited number of terms on ad edit screen to 200, introduced advanced-ads-admin-max-terms filter
  • wrapped placement ads in a container with a unique id and a class to target them with css and js
  • added dashboard widget with plugin version and news about ad optimization

Good to know: What you didnt know about the AdSense Program Policies.

Download this release

Release Info

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

Code changes from version 1.3.11 to 1.3.12

admin/assets/css/admin.css CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  /**
2
  * OVERVIEW PAGE
3
  */
@@ -42,6 +48,7 @@
42
  .post-type-advanced_ads .advads-conditions-all { display: block; }
43
  .post-type-advanced_ads .advads-conditions-single { margin-bottom: 10px; padding: 10px; }
44
  .post-type-advanced_ads .advads-conditions-single.disabled { display: none; opacity: .5; }
 
45
  .advads-conditions-postids-list li { background: #F1F1F1; padding: 3px; }
46
  .advads-conditions-postids-list .remove { margin-right: 1em; font-size: .9em; }
47
  .post-type-advanced_ads #advads-ad-content-plain {
1
+ /**
2
+ * DASHBOARD WIDGET
3
+ */
4
+ #advads_dashboard_widget a.rsswidget { font-weight: 400; }
5
+ #advads_dashboard_widget .rss-widget ul li { margin-bottom: 6px; }
6
+
7
  /**
8
  * OVERVIEW PAGE
9
  */
48
  .post-type-advanced_ads .advads-conditions-all { display: block; }
49
  .post-type-advanced_ads .advads-conditions-single { margin-bottom: 10px; padding: 10px; }
50
  .post-type-advanced_ads .advads-conditions-single.disabled { display: none; opacity: .5; }
51
+ .post-type-advanced_ads .advads-conditions-single th { vertical-align: top; }
52
  .advads-conditions-postids-list li { background: #F1F1F1; padding: 3px; }
53
  .advads-conditions-postids-list .remove { margin-right: 1em; font-size: .9em; }
54
  .post-type-advanced_ads #advads-ad-content-plain {
admin/class-advanced-ads-admin.php CHANGED
@@ -108,6 +108,9 @@ class Advanced_Ads_Admin {
108
  add_action( 'add_meta_boxes', array( $this, 'add_post_meta_box' ) );
109
  add_action( 'save_post', array( $this, 'save_post_meta_box' ) );
110
 
 
 
 
111
  }
112
 
113
  /**
@@ -837,5 +840,95 @@ class Advanced_Ads_Admin {
837
  update_post_meta( $post_id, '_advads_ad_settings', $_data );
838
  }
839
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
840
 
841
  }
108
  add_action( 'add_meta_boxes', array( $this, 'add_post_meta_box' ) );
109
  add_action( 'save_post', array( $this, 'save_post_meta_box' ) );
110
 
111
+ // register dashboard widget
112
+ add_action('wp_dashboard_setup', array($this, 'add_dashboard_widget'));
113
+
114
  }
115
 
116
  /**
840
  update_post_meta( $post_id, '_advads_ad_settings', $_data );
841
  }
842
 
843
+ /**
844
+ * add dashboard widget with ad stats and additional information
845
+ *
846
+ * @since 1.3.12
847
+ */
848
+ public function add_dashboard_widget(){
849
+ // wp_add_dashboard_widget('advads_dashboard_widget', __('Ads Dashboard', ADVADS_SLUG), array($this, 'dashboard_widget_function'));
850
+ add_meta_box('advads_dashboard_widget', __('Ads Dashboard', ADVADS_SLUG), array($this, 'dashboard_widget_function'), 'dashboard', 'side', 'high');
851
+ }
852
+
853
+ /**
854
+ * display widget functions
855
+ */
856
+ public function dashboard_widget_function($post, $callback_args){
857
+ // load ad optimization feed
858
+ $feed = array(
859
+ 'link' => 'http://webgilde.com/en/ad-optimization/',
860
+ 'url' => 'http://webgilde.com/en/ad-optimization/feed/',
861
+ 'title' => __('Tutorials and News'),
862
+ 'items' => 3,
863
+ 'show_summary' => 0,
864
+ 'show_author' => 0,
865
+ 'show_date' => 0,
866
+ );
867
+
868
+ // get number of ads
869
+ $recent_ads = Advanced_Ads::get_ads();
870
+ echo '<p>';
871
+ printf(__('%d ads – <a href="%s">manage</a> – <a href="%s">new</a>', ADVADS_SLUG),
872
+ count($recent_ads),
873
+ 'edit.php?post_type='. Advanced_Ads::POST_TYPE_SLUG,
874
+ 'post-new.php?post_type='. Advanced_Ads::POST_TYPE_SLUG);
875
+ echo '</p>';
876
+
877
+ // get and display plugin version
878
+ $advads_plugin_data = get_plugin_data(ADVADS_BASE_PATH . 'advanced-ads.php');
879
+ if(isset($advads_plugin_data['Version'])){
880
+ $version = $advads_plugin_data['Version'];
881
+ echo '<p><a href="http://wpadvancedads.com" target="_blank" title="'.
882
+ __('plugin manual and homepage', ADVADS_SLUG).'">Advanced Ads</a> '. $version .'</p>';
883
+ }
884
+
885
+ // rss feed
886
+ echo '<h4>' . __('From the ad optimization universe', ADVADS_SLUG) . '</h4>';
887
+ // $this->dashboard_widget_function_output('advads_dashboard_widget', $feed);
888
+ $this->dashboard_cached_rss_widget( 'advads_dashboard_widget', array($this, 'dashboard_widget_function_output'), array('advads' => $feed) );
889
+ }
890
+
891
+ /**
892
+ * checks to see if there are feed urls in transient cache; if not, load them
893
+ * built using a lot of https://developer.wordpress.org/reference/functions/wp_dashboard_cached_rss_widget/
894
+ *
895
+ * @since 1.3.12
896
+ * @param string $widget_id
897
+ * @param callback $callback
898
+ * @param array $check_urls RSS feeds
899
+ * @return bool False on failure. True on success.
900
+ */
901
+ function dashboard_cached_rss_widget( $widget_id, $callback, $feed = array() ) {
902
+ if ( empty($feed) ) {
903
+ return;
904
+ }
905
+
906
+ $cache_key = 'dash_' . md5( $widget_id );
907
+ if ( false !== ( $output = get_transient( $cache_key ) ) ) {
908
+ echo $output;
909
+ return true;
910
+ }
911
+
912
+ if ( $callback && is_callable( $callback ) ) {
913
+ ob_start();
914
+ call_user_func_array( $callback, $feed );
915
+ set_transient( $cache_key, ob_get_flush(), 12 * HOUR_IN_SECONDS ); // Default lifetime in cache of 12 hours (same as the feeds)
916
+ }
917
+
918
+ return true;
919
+ }
920
+
921
+ /**
922
+ * create the rss output of the widget
923
+ *
924
+ * @param string $widget_id Widget ID.
925
+ * @param array $feeds Array of RSS feeds.
926
+ */
927
+ function dashboard_widget_function_output( $feed ) {
928
+
929
+ echo '<div class="rss-widget">';
930
+ wp_widget_rss_output( $feed['url'], $feed );
931
+ echo "</div>";
932
+ }
933
 
934
  }
admin/includes/class-display-condition-callbacks.php CHANGED
@@ -89,7 +89,11 @@ class AdvAds_Display_Condition_Callbacks {
89
  <table><?php
90
  foreach($taxonomies as $_tax):
91
  if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups
92
- $terms = get_terms($_tax->name, array());
 
 
 
 
93
  if ( !empty( $terms ) && !is_wp_error( $terms ) ):
94
  ?><tr><th><?php echo $_tax->label; ?></th><?php
95
  ?><td><?php
@@ -118,7 +122,11 @@ class AdvAds_Display_Condition_Callbacks {
118
  <table><?php
119
  foreach($taxonomies as $_tax):
120
  if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups
121
- $terms = get_terms($_tax->name, array());
 
 
 
 
122
  if ( !empty( $terms ) && !is_wp_error( $terms ) ):
123
  ?><tr><th><?php echo $_tax->label; ?></th><?php
124
  ?><td><?php
@@ -168,7 +176,11 @@ class AdvAds_Display_Condition_Callbacks {
168
  <table><?php
169
  foreach($taxonomies as $_tax):
170
  if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups
171
- $terms = get_terms($_tax->name, array());
 
 
 
 
172
  if ( !empty( $terms ) && !is_wp_error( $terms ) ):
173
  ?><tr><th><?php echo $_tax->label; ?></th><?php
174
  ?><td><?php
@@ -197,7 +209,11 @@ class AdvAds_Display_Condition_Callbacks {
197
  <table><?php
198
  foreach($taxonomies as $_tax):
199
  if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups
200
- $terms = get_terms($_tax->name, array());
 
 
 
 
201
  if ( !empty( $terms ) && !is_wp_error( $terms ) ):
202
  ?><tr><th><?php echo $_tax->label; ?></th><?php
203
  ?><td><?php
89
  <table><?php
90
  foreach($taxonomies as $_tax):
91
  if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups
92
+
93
+ // limit the number of terms so many terms don’t break the admin page
94
+ $max_terms = absint(apply_filters('advanced-ads-admin-max-terms', 200));
95
+ $terms = get_terms($_tax->name, array('number' => $max_terms));
96
+
97
  if ( !empty( $terms ) && !is_wp_error( $terms ) ):
98
  ?><tr><th><?php echo $_tax->label; ?></th><?php
99
  ?><td><?php
122
  <table><?php
123
  foreach($taxonomies as $_tax):
124
  if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups
125
+
126
+ // limit the number of terms so many terms don’t break the admin page
127
+ $max_terms = absint(apply_filters('advanced-ads-admin-max-terms', 200));
128
+ $terms = get_terms($_tax->name, array('number' => $max_terms));
129
+
130
  if ( !empty( $terms ) && !is_wp_error( $terms ) ):
131
  ?><tr><th><?php echo $_tax->label; ?></th><?php
132
  ?><td><?php
176
  <table><?php
177
  foreach($taxonomies as $_tax):
178
  if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups
179
+
180
+ // limit the number of terms so many terms don’t break the admin page
181
+ $max_terms = absint(apply_filters('advanced-ads-admin-max-terms', 200));
182
+ $terms = get_terms($_tax->name, array('number' => $max_terms));
183
+
184
  if ( !empty( $terms ) && !is_wp_error( $terms ) ):
185
  ?><tr><th><?php echo $_tax->label; ?></th><?php
186
  ?><td><?php
209
  <table><?php
210
  foreach($taxonomies as $_tax):
211
  if($_tax->name === 'advanced_ads_groups') continue; // exclude adv ads groups
212
+
213
+ // limit the number of terms so many terms don’t break the admin page
214
+ $max_terms = absint(apply_filters('advanced-ads-admin-max-terms', 200));
215
+ $terms = get_terms($_tax->name, array('number' => $max_terms));
216
+
217
  if ( !empty( $terms ) && !is_wp_error( $terms ) ):
218
  ?><tr><th><?php echo $_tax->label; ?></th><?php
219
  ?><td><?php
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.11
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.12
16
  * Author: Thomas Maier
17
  * Author URI: http://webgilde.com
18
  * Text Domain: advanced-ads
classes/ad.php CHANGED
@@ -75,6 +75,11 @@ class Advads_Ad {
75
  */
76
  static $options_meta_field = 'advanced_ads_ad_options';
77
 
 
 
 
 
 
78
  /**
79
  * multidimensional array contains information about the wrapper
80
  * each possible html attribute is an array with possible multiple elements
@@ -85,11 +90,13 @@ class Advads_Ad {
85
  * init ad object
86
  *
87
  * @param int $id id of the ad (= post id)
 
88
  */
89
- public function __construct($id) {
90
  global $advanced_ads_ad_conditions;
91
  $id = absint($id);
92
  $this->id = $id;
 
93
 
94
  if(!empty($id)) $this->load($id);
95
 
@@ -169,8 +176,13 @@ class Advads_Ad {
169
  public function options($field = ''){
170
  // retrieve options, if not given yet
171
  if ($this->options === array()) {
 
 
172
  // get_post_meta() may return false
173
- $this->options = get_post_meta($this->id, self::$options_meta_field, true);
 
 
 
174
  }
175
 
176
  // return specific option
@@ -841,6 +853,10 @@ class Advads_Ad {
841
  }
842
  }
843
 
 
 
 
 
844
  if(!empty($this->output['margin']['top'])) {
845
  $wrapper['style']['margin-top'] = intval($this->output['margin']['top']) . 'px';
846
  }
@@ -854,8 +870,6 @@ class Advads_Ad {
854
  $wrapper['style']['margin-left'] = intval($this->output['margin']['left']) . 'px';
855
  }
856
 
857
- // print_r($wrapper);
858
-
859
  return $wrapper;
860
  }
861
 
75
  */
76
  static $options_meta_field = 'advanced_ads_ad_options';
77
 
78
+ /**
79
+ * additional arguments set when ad is loaded, overwrites or extends options
80
+ */
81
+ public $args = array();
82
+
83
  /**
84
  * multidimensional array contains information about the wrapper
85
  * each possible html attribute is an array with possible multiple elements
90
  * init ad object
91
  *
92
  * @param int $id id of the ad (= post id)
93
+ * @param arr $args additional arguments
94
  */
95
+ public function __construct($id, $args = array()) {
96
  global $advanced_ads_ad_conditions;
97
  $id = absint($id);
98
  $this->id = $id;
99
+ $this->args = is_array($args) ? $args : array();
100
 
101
  if(!empty($id)) $this->load($id);
102
 
176
  public function options($field = ''){
177
  // retrieve options, if not given yet
178
  if ($this->options === array()) {
179
+ // load arguments given on ad load
180
+ $this->options = $this->args;
181
  // get_post_meta() may return false
182
+ $meta = get_post_meta($this->id, self::$options_meta_field, true);
183
+ if($meta){
184
+ $this->options = $this->options + $meta;
185
+ }
186
  }
187
 
188
  // return specific option
853
  }
854
  }
855
 
856
+ if(!empty($this->output['class']) && is_string($this->output['class']) && '' != trim($this->output['class'])) {
857
+ $wrapper['class'] = sanitize_key($this->output['class']);
858
+ }
859
+
860
  if(!empty($this->output['margin']['top'])) {
861
  $wrapper['style']['margin-top'] = intval($this->output['margin']['top']) . 'px';
862
  }
870
  $wrapper['style']['margin-left'] = intval($this->output['margin']['left']) . 'px';
871
  }
872
 
 
 
873
  return $wrapper;
874
  }
875
 
classes/ad_placements.php CHANGED
@@ -196,13 +196,17 @@ class Advads_Ad_Placements {
196
  $advads = Advanced_Ads::get_instance();
197
  $advads->current_ads[] = array('type' => 'placement', 'id' => $id, 'title' => $placements[$id]['name']);
198
 
199
- return get_ad($_item_id);
 
 
 
200
  } elseif ($_item[0] == 'group') {
201
  // add the placement to the global output array
202
  $advads = Advanced_Ads::get_instance();
203
  $advads->current_ads[] = array('type' => 'placement', 'id' => $id, 'title' => $placements[$id]['name']);
204
 
205
  return get_ad_group($_item_id);
 
206
  }
207
  } else {
208
  return;
196
  $advads = Advanced_Ads::get_instance();
197
  $advads->current_ads[] = array('type' => 'placement', 'id' => $id, 'title' => $placements[$id]['name']);
198
 
199
+ // create class from placement id
200
+ $class = 'advads-' . $id;
201
+ return get_ad($_item_id, array('output' => array('class' => $class)));
202
+
203
  } elseif ($_item[0] == 'group') {
204
  // add the placement to the global output array
205
  $advads = Advanced_Ads::get_instance();
206
  $advads->current_ads[] = array('type' => 'placement', 'id' => $id, 'title' => $placements[$id]['name']);
207
 
208
  return get_ad_group($_item_id);
209
+
210
  }
211
  } else {
212
  return;
public/functions.php CHANGED
@@ -9,14 +9,14 @@
9
  *
10
  * @since 1.0.0
11
  * @param int $id id of the ad (post)
12
- *
13
  */
14
- function get_ad($id = 0){
15
  $id = absint($id);
16
  if(empty($id)) return;
17
 
18
  // get ad
19
- $ad = new Advads_Ad($id);
20
 
21
  // check conditions
22
  if($ad->can_display())
@@ -28,10 +28,11 @@ function get_ad($id = 0){
28
  *
29
  * @since 1.0.0
30
  * @param int $id id of the ad (post)
 
31
  */
32
- function the_ad($id = 0){
33
 
34
- echo get_ad($id);
35
 
36
  }
37
 
9
  *
10
  * @since 1.0.0
11
  * @param int $id id of the ad (post)
12
+ * @param arr $args additional arguments
13
  */
14
+ function get_ad($id = 0, $args = array()){
15
  $id = absint($id);
16
  if(empty($id)) return;
17
 
18
  // get ad
19
+ $ad = new Advads_Ad($id, $args);
20
 
21
  // check conditions
22
  if($ad->can_display())
28
  *
29
  * @since 1.0.0
30
  * @param int $id id of the ad (post)
31
+ * @param arr $args additional arguments
32
  */
33
+ function the_ad($id = 0, $args = array()){
34
 
35
+ echo get_ad($id, $args);
36
 
37
  }
38
 
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.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -52,6 +52,12 @@ deliver ads based on conditions like
52
  * archive pages by category, tags, taxonomies
53
  * special page types like 404, attachment and front page
54
 
 
 
 
 
 
 
55
  = visitor conditions =
56
 
57
  display ads by conditions based on the visitor
@@ -148,6 +154,14 @@ There is no revenue share. Advanced Ads doesn’t alter your ad codes in a way t
148
 
149
  == Changelog ==
150
 
 
 
 
 
 
 
 
 
151
  = 1.3.11 =
152
 
153
  * COOL: disable ads completely, on 404 pages or for non-singular pages with a single click
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.12
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
52
  * archive pages by category, tags, taxonomies
53
  * special page types like 404, attachment and front page
54
 
55
+ global conditions
56
+
57
+ * disable all ads in the frontend (e.g. when your ad network breaks down)
58
+ * disable all ads on 404 pages (e.g. AdSense doesn’t allow that)
59
+ * disable all ads on non-singular pages with a single click
60
+
61
  = visitor conditions =
62
 
63
  display ads by conditions based on the visitor
154
 
155
  == Changelog ==
156
 
157
+ = 1.3.12 =
158
+
159
+ * limited number of terms on ad edit screen to 200, introduced _advanced-ads-admin-max-terms_ filter
160
+ * wrapped placement ads in a container with a unique id and a class to target them with css and js
161
+ * added dashboard widget with plugin version and news about ad optimization
162
+
163
+ Good to know: [What you didn’t know about the AdSense Program Policies](http://webgilde.com/en/adsense-program-policies/).
164
+
165
  = 1.3.11 =
166
 
167
  * COOL: disable ads completely, on 404 pages or for non-singular pages with a single click