Advanced Ads - Version 1.6.2

Version Description

  • display dashboard widget only to authors and higher roles
  • include admin javascript file only on pages which need it
  • no need to save AdSense publisher ID separately anymore
  • added warning if AdSense publisher ID has wrong format
  • list more than 10 ads from a group on the group overview page
  • active settings and conditions are now blue
  • clear object cache when saving an ad (thanks to pete-sch)
Download this release

Release Info

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

Code changes from version 1.6.1 to 1.6.2

admin/assets/css/admin.css CHANGED
@@ -85,7 +85,7 @@
85
 
86
  .advads-buttonset .ui-state-active,
87
  .advads-buttonset .button,
88
- .advads-buttonset .ui-button.ui-state-active { border-color: #0074a2; background: #2ea2cc; color: #fff; box-shadow: none; }
89
 
90
  #ad-display-box .advads-conditions-terms-show-search { height: 22px; line-height: 22px; font-weight: bold; font-size: 1.5em; }
91
  .advads-conditions-terms-show-search + .description { display: none; }
@@ -178,4 +178,9 @@ tr:hover .on-hover { display: block; }
178
  .advads-tab { display: none; }
179
  .advads-tab.active { display: block; }
180
  .advads-license-activate-active { color: green; }
181
- .advads-license-activate-error { color: red; }
 
 
 
 
 
85
 
86
  .advads-buttonset .ui-state-active,
87
  .advads-buttonset .button,
88
+ .advads-buttonset .ui-button.ui-state-active { border-color: #0074a2 !important; background: #2ea2cc !important; color: #fff !important; box-shadow: none; }
89
 
90
  #ad-display-box .advads-conditions-terms-show-search { height: 22px; line-height: 22px; font-weight: bold; font-size: 1.5em; }
91
  .advads-conditions-terms-show-search + .description { display: none; }
178
  .advads-tab { display: none; }
179
  .advads-tab.active { display: block; }
180
  .advads-license-activate-active { color: green; }
181
+ .advads-license-activate-error { color: red; }
182
+
183
+ /**
184
+ - GENERAL
185
+ -*/
186
+ .advads-error-message { color: red; }
admin/assets/js/admin-global.js ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ * global js functions for Advanced Ads
3
+ */
4
+ jQuery( document ).ready(function () {
5
+
6
+ /**
7
+ * ADMIN NOTICES
8
+ */
9
+ // close button
10
+ jQuery(document).on('click', '.advads-notices-button-close', function(){
11
+ if(this.dataset.notice === undefined) return;
12
+ var messagebox = jQuery(this).parents('.advads-admin-notice');
13
+
14
+ var query = {
15
+ action: 'advads-close-notice',
16
+ notice: this.dataset.notice
17
+ };
18
+ // send and close message
19
+ jQuery.post(ajaxurl, query, function (r) {
20
+ messagebox.fadeOut();
21
+ });
22
+
23
+ });
24
+ // autoresponder button
25
+ jQuery('.advads-notices-button-subscribe').click(function(){
26
+ if(this.dataset.notice === undefined) return;
27
+ var messagebox = jQuery(this).parents('.advads-admin-notice');
28
+ messagebox.find('p').append( '<span class="spinner advads-spinner"></span>' );
29
+
30
+ var query = {
31
+ action: 'advads-subscribe-notice',
32
+ notice: this.dataset.notice
33
+ };
34
+ // send and close message
35
+ jQuery.post(ajaxurl, query, function (r) {
36
+ if(r === '1'){
37
+ messagebox.fadeOut();
38
+ } else {
39
+ messagebox.find('p').html(r);
40
+ messagebox.removeClass('updated').addClass('error');
41
+ }
42
+ });
43
+
44
+ });
45
+
46
+ });
admin/assets/js/admin.js CHANGED
@@ -45,18 +45,19 @@ jQuery( document ).ready(function ($) {
45
  advads_toggle_single_display_conditions( this );
46
  });
47
 
 
 
 
48
  // toggle single display condition checkboxes that have a counterpart
49
  $( document ).on('click', '.advads-conditions-single input[type="checkbox"]', function () {
50
- advads_toggle_single_display_condition_checkbox( this );
51
- // update buttons
52
- $( '.advads-conditions-terms-buttons label' ).button( 'refresh' );
53
  });
54
  // toggle single display condition checkboxes that have a counterpart on load
55
  $( '.advads-conditions-single input[type="checkbox"]' ).each(function () {
56
  advads_toggle_single_display_condition_checkbox( this );
57
  });
58
- // activate general buttons
59
- $( '.advads-buttonset' ).buttonset();
60
 
61
  $( document ).on('click', '.advads-conditions-terms-buttons .button', function (e) {
62
  $( this ).remove();
@@ -175,55 +176,11 @@ jQuery( document ).ready(function ($) {
175
  /**
176
  * SETTINGS PAGE
177
  */
178
- // render button sets on settings page
179
- $(function() {
180
- $( ".advads-settings-buttonset" ).buttonset();
181
- });
182
-
183
- /**
184
- * ADMIN NOTICES
185
- */
186
- // close button
187
- $(document).on('click', '.advads-notices-button-close', function(){
188
- if(this.dataset.notice === undefined) return;
189
- var messagebox = $(this).parents('.advads-admin-notice');
190
-
191
- var query = {
192
- action: 'advads-close-notice',
193
- notice: this.dataset.notice
194
- };
195
- // send and close message
196
- $.post(ajaxurl, query, function (r) {
197
- messagebox.fadeOut();
198
- });
199
-
200
- });
201
- // autoresponder button
202
- $('.advads-notices-button-subscribe').click(function(){
203
- if(this.dataset.notice === undefined) return;
204
- var messagebox = $(this).parents('.advads-admin-notice');
205
- messagebox.find('p').append( '<span class="spinner advads-spinner"></span>' );
206
-
207
- var query = {
208
- action: 'advads-subscribe-notice',
209
- notice: this.dataset.notice
210
- };
211
- // send and close message
212
- $.post(ajaxurl, query, function (r) {
213
- if(r === '1'){
214
- messagebox.fadeOut();
215
- } else {
216
- messagebox.find('p').html(r);
217
- messagebox.removeClass('updated').addClass('error');
218
- }
219
- });
220
-
221
- });
222
 
223
  // activate licenses
224
  $('.advads-license-activate').click(function(){
225
 
226
- var button = $(this);
227
  if( ! this.dataset.addon ) { return }
228
 
229
  var query = {
45
  advads_toggle_single_display_conditions( this );
46
  });
47
 
48
+ // activate general buttons
49
+ $( '.advads-buttonset' ).buttonset();
50
+
51
  // toggle single display condition checkboxes that have a counterpart
52
  $( document ).on('click', '.advads-conditions-single input[type="checkbox"]', function () {
53
+ advads_toggle_single_display_condition_checkbox( this );
54
+ // update buttons
55
+ // $( '.advads-conditions-terms-buttons' ).button( 'refresh' );
56
  });
57
  // toggle single display condition checkboxes that have a counterpart on load
58
  $( '.advads-conditions-single input[type="checkbox"]' ).each(function () {
59
  advads_toggle_single_display_condition_checkbox( this );
60
  });
 
 
61
 
62
  $( document ).on('click', '.advads-conditions-terms-buttons .button', function (e) {
63
  $( this ).remove();
176
  /**
177
  * SETTINGS PAGE
178
  */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
180
  // activate licenses
181
  $('.advads-license-activate').click(function(){
182
 
183
+ var button = $(this);
184
  if( ! this.dataset.addon ) { return }
185
 
186
  var query = {
admin/class-advanced-ads-admin.php CHANGED
@@ -175,18 +175,39 @@ class Advanced_Ads_Admin {
175
  */
176
  public function enqueue_admin_scripts() {
177
 
178
- global $post;
179
- if ( ! isset($this->plugin_screen_hook_suffix) && isset($post) && Advanced_Ads::POST_TYPE_SLUG != $post->type ) {
180
- return;
181
- }
 
 
 
 
 
 
 
182
 
183
- wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array('jquery', 'jquery-ui-autocomplete'), Advanced_Ads::VERSION );
184
- // jquery ui
185
- wp_enqueue_script( 'jquery-ui-accordion' );
186
- wp_enqueue_script( 'jquery-ui-button' );
 
187
 
188
- // just register this script for later inclusion on ad group list page
189
- wp_register_script( 'inline-edit-group-ads', plugins_url( 'assets/js/inline-edit-group-ads.js', __FILE__ ), array('jquery'), Advanced_Ads::VERSION );
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
191
  }
192
 
@@ -525,6 +546,9 @@ class Advanced_Ads_Admin {
525
  return;
526
  }
527
 
 
 
 
528
  $ad->type = $_POST['advanced_ad']['type'];
529
  if ( isset($_POST['advanced_ad']['output']) ) {
530
  $ad->set_option( 'output', $_POST['advanced_ad']['output'] );
@@ -1072,6 +1096,10 @@ class Advanced_Ads_Admin {
1072
  * @since 1.3.12
1073
  */
1074
  public function add_dashboard_widget(){
 
 
 
 
1075
  add_meta_box( 'advads_dashboard_widget', __( 'Ads Dashboard', ADVADS_SLUG ), array($this, 'dashboard_widget_function'), 'dashboard', 'side', 'high' );
1076
  }
1077
 
175
  */
176
  public function enqueue_admin_scripts() {
177
 
178
+ // global js script
179
+ wp_enqueue_script( $this->plugin_slug . '-admin-global-script', plugins_url( 'assets/js/admin-global.js', __FILE__ ), array('jquery'), Advanced_Ads::VERSION );
180
+
181
+ /**
182
+ * only include on
183
+ * * advads settings pages
184
+ * * ad post type
185
+ * * ad groups
186
+ * * ad placements
187
+ * * ad overview
188
+ */
189
 
190
+ $screen = get_current_screen();
191
+ //echo $screen->id;
192
+ if( !isset( $screen->id ) ) {
193
+ return;
194
+ }
195
 
196
+ if( $screen->id === 'advanced-ads_page_advanced-ads-groups' || // ad groups
197
+ $screen->id === 'edit-advanced_ads' || // ads overview
198
+ $screen->id === 'advanced_ads' || // ad edit page
199
+ $screen->id === 'advanced-ads_page_advanced-ads-placements' || // placements
200
+ $screen->id === 'advanced-ads_page_advanced-ads-settings' || // settings
201
+ $screen->id === 'toplevel_page_advanced-ads' // overview
202
+ ){
203
+ wp_enqueue_script( $this->plugin_slug . '-admin-script', plugins_url( 'assets/js/admin.js', __FILE__ ), array('jquery', 'jquery-ui-autocomplete'), Advanced_Ads::VERSION );
204
+ // jquery ui
205
+ wp_enqueue_script( 'jquery-ui-accordion' );
206
+ wp_enqueue_script( 'jquery-ui-button' );
207
+
208
+ // just register this script for later inclusion on ad group list page
209
+ wp_register_script( 'inline-edit-group-ads', plugins_url( 'assets/js/inline-edit-group-ads.js', __FILE__ ), array('jquery'), Advanced_Ads::VERSION );
210
+ }
211
 
212
  }
213
 
546
  return;
547
  }
548
 
549
+ // filter to allow change of submitted ad settings
550
+ $_POST['advanced_ad'] = apply_filters( 'advanced-ads-ad-settings-pre-save', $_POST['advanced_ad'] );
551
+
552
  $ad->type = $_POST['advanced_ad']['type'];
553
  if ( isset($_POST['advanced_ad']['output']) ) {
554
  $ad->set_option( 'output', $_POST['advanced_ad']['output'] );
1096
  * @since 1.3.12
1097
  */
1098
  public function add_dashboard_widget(){
1099
+ // display dashboard widget only to authors and higher roles
1100
+ if( ! current_user_can('publish_posts') ) {
1101
+ return;
1102
+ }
1103
  add_meta_box( 'advads_dashboard_widget', __( 'Ads Dashboard', ADVADS_SLUG ), array($this, 'dashboard_widget_function'), 'dashboard', 'side', 'high' );
1104
  }
1105
 
admin/includes/class-ad-groups-list.php CHANGED
@@ -218,7 +218,8 @@ class Advanced_Ads_Groups_List {
218
  'post_type' => $this->post_type,
219
  'post_status' => array('publish', 'pending', 'future', 'private'),
220
  'taxonomy' => $group->taxonomy,
221
- 'term' => $group->slug
 
222
  );
223
  return $ads = new WP_Query( $args );
224
  }
218
  'post_type' => $this->post_type,
219
  'post_status' => array('publish', 'pending', 'future', 'private'),
220
  'taxonomy' => $group->taxonomy,
221
+ 'term' => $group->slug,
222
+ 'posts_per_page' => -1
223
  );
224
  return $ads = new WP_Query( $args );
225
  }
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.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.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.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.2' );
42
 
43
  /*----------------------------------------------------------------------------*
44
  * Autoloading, modules and functions
classes/ad.php CHANGED
@@ -367,6 +367,9 @@ class Advanced_Ads_Ad {
367
  $where = array('ID' => $this->id);
368
  $wpdb->update( $wpdb->posts, array( 'post_content' => $content ), $where );
369
 
 
 
 
370
  // sanitize conditions
371
  // see sanitize_conditions function for example on using this filter
372
  $conditions = self::sanitize_conditions_on_save( $this->conditions );
367
  $where = array('ID' => $this->id);
368
  $wpdb->update( $wpdb->posts, array( 'post_content' => $content ), $where );
369
 
370
+ // clean post from object cache
371
+ clean_post_cache( $this->id );
372
+
373
  // sanitize conditions
374
  // see sanitize_conditions function for example on using this filter
375
  $conditions = self::sanitize_conditions_on_save( $this->conditions );
classes/visitor-conditions.php CHANGED
@@ -35,6 +35,8 @@ class Advanced_Ads_Visitor_Conditions {
35
  'check' => array( 'Advanced_Ads_Visitor_Conditions', 'check_mobile' ) // callback for frontend check
36
  ),
37
  ));
 
 
38
  }
39
 
40
  /**
@@ -119,6 +121,48 @@ class Advanced_Ads_Visitor_Conditions {
119
  </select></label><input type="number" name="<?php echo $name; ?>[value]" value="<?php echo absint( $value ); ?>"/></p><?php
120
  }
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  /**
123
  * controls frontend checks for conditions
124
  *
35
  'check' => array( 'Advanced_Ads_Visitor_Conditions', 'check_mobile' ) // callback for frontend check
36
  ),
37
  ));
38
+
39
+ ksort( $this->conditions );
40
  }
41
 
42
  /**
121
  </select></label><input type="number" name="<?php echo $name; ?>[value]" value="<?php echo absint( $value ); ?>"/></p><?php
122
  }
123
 
124
+ /**
125
+ * callback to display the any condition based on a number
126
+ *
127
+ * @param arr $options options of the condition
128
+ * @param int $index index of the condition
129
+ */
130
+ static function metabox_string( $options, $index = 0 ){
131
+
132
+ if ( ! isset ( $options['type'] ) || '' === $options['type'] ) { return; }
133
+
134
+ $type_options = self::get_instance()->conditions;
135
+
136
+ if ( ! isset( $type_options[ $options['type'] ] ) ) {
137
+ return;
138
+ }
139
+
140
+ // form name basis
141
+ $name = self::FORM_NAME . '[' . $index . ']';
142
+
143
+ // options
144
+ $value = isset( $options['value'] ) ? $options['value'] : '';
145
+ $operator = isset( $options['operator'] ) ? $options['operator'] : 'contains';
146
+ $connector = isset( $options['connector'] ) ? $options['connector'] : 'and';
147
+
148
+ ?><p>
149
+ <input type="hidden" name="<?php echo $name; ?>[type]" value="<?php echo $options['type']; ?>"/>
150
+ <input type="hidden" name="<?php echo $name; ?>[connector]" value="<?php echo $connector; ?>"/>
151
+ <label><?php echo $type_options[ $options['type'] ]['label'];
152
+ ?><select name="<?php echo $name; ?>[operator]">
153
+ <option value="contain" <?php selected( 'contain', $operator ); ?>><?php _e( 'contains', ADVADS_SLUG ); ?></option>
154
+ <option value="start" <?php selected( 'start', $operator ); ?>><?php _e( 'starts with', ADVADS_SLUG ); ?></option>
155
+ <option value="end" <?php selected( 'end', $operator ); ?>><?php _e( 'ends with', ADVADS_SLUG ); ?></option>
156
+ <option value="match" <?php selected( 'match', $operator ); ?>><?php _e( 'matches', ADVADS_SLUG ); ?></option>
157
+ <option value="regex" <?php selected( 'regex', $operator ); ?>><?php _e( 'matches regex', ADVADS_SLUG ); ?></option>
158
+ <option value="contain_not" <?php selected( 'contain_not', $operator ); ?>><?php _e( 'does not contain', ADVADS_SLUG ); ?></option>
159
+ <option value="start_not" <?php selected( 'start_not', $operator ); ?>><?php _e( 'does not start with', ADVADS_SLUG ); ?></option>
160
+ <option value="end_not" <?php selected( 'end_not', $operator ); ?>><?php _e( 'does not end with', ADVADS_SLUG ); ?></option>
161
+ <option value="match_not" <?php selected( 'match_not', $operator ); ?>><?php _e( 'does not match', ADVADS_SLUG ); ?></option>
162
+ <option value="regex_not" <?php selected( 'regex_not', $operator ); ?>><?php _e( 'does not match regex', ADVADS_SLUG ); ?></option>
163
+ </select></label><input type="text" name="<?php echo $name; ?>[value]" value="<?php echo $value; ?>"/></p><?php
164
+ }
165
+
166
  /**
167
  * controls frontend checks for conditions
168
  *
public/class-advanced-ads.php CHANGED
@@ -25,7 +25,7 @@ class Advanced_Ads {
25
  * @var string
26
  */
27
 
28
- const VERSION = '1.6.1';
29
 
30
  /**
31
  * post type slug
25
  * @var string
26
  */
27
 
28
+ const VERSION = '1.6.2';
29
 
30
  /**
31
  * post type slug
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.2.2
7
- Stable tag: 1.6.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -175,6 +175,16 @@ There is no revenue share. Advanced Ads doesn’t alter your ad codes in a way t
175
 
176
  == Changelog ==
177
 
 
 
 
 
 
 
 
 
 
 
178
  = 1.6.1 =
179
 
180
  * fix secondary query condition (this was revered in 1.6)
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.2.2
7
+ Stable tag: 1.6.2
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
175
 
176
  == Changelog ==
177
 
178
+ = 1.6.2 =
179
+
180
+ * display dashboard widget only to authors and higher roles
181
+ * include admin javascript file only on pages which need it
182
+ * no need to save AdSense publisher ID separately anymore
183
+ * added warning if AdSense publisher ID has wrong format
184
+ * list more than 10 ads from a group on the group overview page
185
+ * active settings and conditions are now blue
186
+ * clear object cache when saving an ad (thanks to pete-sch)
187
+
188
  = 1.6.1 =
189
 
190
  * fix secondary query condition (this was revered in 1.6)