Version Description
- added option to hide ads from crawlers and other bots (option is disabled by default)
- added Secondary Queries display condition, e.g. to hide ads from posts in sidebars
- added frontend function
advads_can_display_ads()
to check if ads are displayed in general - global option to disable all ads in secondary queries
- search for term ids in display conditions
- fixed ad conditions using conditional tags of subquery instead of the main query
- fixed search for terms in display conditions
Download this release
Release Info
Developer | webzunft |
Plugin | Advanced Ads |
Version | 1.4.9 |
Comparing to | |
See all releases |
Code changes from version 1.4.8 to 1.4.9
- admin/assets/js/admin.js +1 -1
- admin/class-advanced-ads-admin.php +23 -0
- admin/includes/class-ad-groups-list.php +1 -1
- admin/views/settings_disable_ads.php +5 -1
- advanced-ads.php +1 -1
- classes/ad.php +19 -23
- classes/ad_ajax_callbacks.php +27 -1
- classes/ad_group.php +4 -4
- includes/array_ad_conditions.php +5 -0
- public/class-advanced-ads.php +66 -5
- public/functions.php +16 -0
- readme.txt +14 -1
admin/assets/js/admin.js
CHANGED
@@ -79,7 +79,7 @@ jQuery( document ).ready(function ($) {
|
|
79 |
// var searchField = request.term;
|
80 |
advads_term_search(self, callback);
|
81 |
},
|
82 |
-
minLength:
|
83 |
select: function( event, ui ) {
|
84 |
// append new line with input fields
|
85 |
$( '<label class="button">' + ui.item.label + '<input type="hidden" name="advanced_ad[conditions]['+ self.dataset.group +']['+ self.dataset.includeType +'][]" value="' + ui.item.value + '"></label>' ).appendTo( $(self).siblings('.advads-conditions-terms-buttons'));
|
79 |
// var searchField = request.term;
|
80 |
advads_term_search(self, callback);
|
81 |
},
|
82 |
+
minLength: 1,
|
83 |
select: function( event, ui ) {
|
84 |
// append new line with input fields
|
85 |
$( '<label class="button">' + ui.item.label + '<input type="hidden" name="advanced_ad[conditions]['+ self.dataset.group +']['+ self.dataset.includeType +'][]" value="' + ui.item.value + '"></label>' ).appendTo( $(self).siblings('.advads-conditions-terms-buttons'));
|
admin/class-advanced-ads-admin.php
CHANGED
@@ -692,6 +692,14 @@ class Advanced_Ads_Admin {
|
|
692 |
$hook,
|
693 |
'advanced_ads_setting_section'
|
694 |
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
695 |
|
696 |
// hook for additional settings from add-ons
|
697 |
do_action( 'advanced-ads-settings-init', $hook );
|
@@ -718,6 +726,7 @@ class Advanced_Ads_Admin {
|
|
718 |
$disable_all = isset($options['disabled-ads']['all']) ? 1 : 0;
|
719 |
$disable_404 = isset($options['disabled-ads']['404']) ? 1 : 0;
|
720 |
$disable_archives = isset($options['disabled-ads']['archives']) ? 1 : 0;
|
|
|
721 |
|
722 |
// load the template
|
723 |
$view = plugin_dir_path( __FILE__ ) . 'views/settings_disable_ads.php';
|
@@ -778,6 +787,20 @@ class Advanced_Ads_Admin {
|
|
778 |
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.', ADVADS_SLUG ) .'</p>';
|
779 |
}
|
780 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
781 |
/**
|
782 |
* add heading for extra column of ads list
|
783 |
* remove the date column
|
692 |
$hook,
|
693 |
'advanced_ads_setting_section'
|
694 |
);
|
695 |
+
// add setting fields for content injection priority
|
696 |
+
add_settings_field(
|
697 |
+
'block-bots',
|
698 |
+
__( 'Hide ads from bots', ADVADS_SLUG ),
|
699 |
+
array($this, 'render_settings_block_bots'),
|
700 |
+
$hook,
|
701 |
+
'advanced_ads_setting_section'
|
702 |
+
);
|
703 |
|
704 |
// hook for additional settings from add-ons
|
705 |
do_action( 'advanced-ads-settings-init', $hook );
|
726 |
$disable_all = isset($options['disabled-ads']['all']) ? 1 : 0;
|
727 |
$disable_404 = isset($options['disabled-ads']['404']) ? 1 : 0;
|
728 |
$disable_archives = isset($options['disabled-ads']['archives']) ? 1 : 0;
|
729 |
+
$disable_secondary = isset($options['disabled-ads']['secondary']) ? 1 : 0;
|
730 |
|
731 |
// load the template
|
732 |
$view = plugin_dir_path( __FILE__ ) . 'views/settings_disable_ads.php';
|
787 |
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.', ADVADS_SLUG ) .'</p>';
|
788 |
}
|
789 |
|
790 |
+
/**
|
791 |
+
* render setting for blocking bots
|
792 |
+
*
|
793 |
+
* @since 1.4.9
|
794 |
+
*/
|
795 |
+
public function render_settings_block_bots(){
|
796 |
+
$options = Advanced_Ads::get_instance()->options();
|
797 |
+
$checked = ( ! empty($options['block-bots'])) ? 1 : 0;
|
798 |
+
|
799 |
+
echo '<input id="advanced-ads-block-bots" type="checkbox" value="1" name="'.ADVADS_SLUG.'[block-bots]" '.checked( $checked, 1, false ).'>';
|
800 |
+
echo '<p class="description">'. sprintf(__( 'Hide ads from crawlers and other bots. Also prevents counting impressions for bots when using the <a href="%s" target="_blank">Tracking Add-On</a>.', ADVADS_SLUG ), 'http://wpadvancedads.com/ad-tracking/') .'<br/>'
|
801 |
+
. __( 'Disabling this option only makes sense if your ads contain content you want to display to bots (like search engines) or your site is cached and bots could create a cached version without the ads.', ADVADS_SLUG ) . '</p>';
|
802 |
+
}
|
803 |
+
|
804 |
/**
|
805 |
* add heading for extra column of ads list
|
806 |
* remove the date column
|
admin/includes/class-ad-groups-list.php
CHANGED
@@ -138,7 +138,7 @@ class AdvAds_Groups_List {
|
|
138 |
$ads = $this->get_ads($group);
|
139 |
|
140 |
$weights = $group->get_ad_weights();
|
141 |
-
$weight_sum = array_sum( $weights )
|
142 |
|
143 |
// The Loop
|
144 |
if ( $ads->have_posts() ) {
|
138 |
$ads = $this->get_ads($group);
|
139 |
|
140 |
$weights = $group->get_ad_weights();
|
141 |
+
$weight_sum = array_sum( $weights );
|
142 |
|
143 |
// The Loop
|
144 |
if ( $ads->have_posts() ) {
|
admin/views/settings_disable_ads.php
CHANGED
@@ -10,4 +10,8 @@
|
|
10 |
<br/><label><input id="advanced-ads-disable-ads-archives" type="checkbox" value="1" name="<?php
|
11 |
echo ADVADS_SLUG; ?>[disabled-ads][archives]" <?php checked( $disable_archives, 1 );
|
12 |
?>><?php _e( 'Disable ads on non-singular pages', ADVADS_SLUG ); ?></label>
|
13 |
-
<p class="description"><?php _e( 'e.g. archive pages like categories, tags, authors, front page (if a list)', ADVADS_SLUG ); ?></p>
|
|
|
|
|
|
|
|
10 |
<br/><label><input id="advanced-ads-disable-ads-archives" type="checkbox" value="1" name="<?php
|
11 |
echo ADVADS_SLUG; ?>[disabled-ads][archives]" <?php checked( $disable_archives, 1 );
|
12 |
?>><?php _e( 'Disable ads on non-singular pages', ADVADS_SLUG ); ?></label>
|
13 |
+
<p class="description"><?php _e( 'e.g. archive pages like categories, tags, authors, front page (if a list)', ADVADS_SLUG ); ?></p>
|
14 |
+
<label><input id="advanced-ads-disable-ads-secondary" type="checkbox" value="1" name="<?php
|
15 |
+
echo ADVADS_SLUG; ?>[disabled-ads][secondary]" <?php checked( $disable_secondary, 1 );
|
16 |
+
?>><?php _e( 'Disable ads on secondary queries', ADVADS_SLUG ); ?></label>
|
17 |
+
<p class="description"><?php _e( 'Secondary queries are custom queries of posts outside the main query of a page. Try this option if you see ads injected on places where they shouldn’t appear.', ADVADS_SLUG ); ?></p>
|
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.4.
|
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.4.9
|
16 |
* Author: Thomas Maier
|
17 |
* Author URI: http://webgilde.com
|
18 |
* Text Domain: advanced-ads
|
classes/ad.php
CHANGED
@@ -241,29 +241,18 @@ class Advads_Ad {
|
|
241 |
}
|
242 |
|
243 |
/**
|
244 |
-
* check if the ad can be displayed in frontend due to its conditions
|
245 |
*
|
246 |
* @since 1.0.0
|
247 |
* @return bool $can_display true if can be displayed in frontend
|
248 |
*/
|
249 |
public function can_display(){
|
250 |
|
251 |
-
$options = Advanced_Ads::get_instance()->options();
|
252 |
-
$see_ads_capability = ( ! empty($options['hide-for-user-role'])) ? $options['hide-for-user-role'] : 0;
|
253 |
-
|
254 |
-
// check global constant if ads are enabled or disabled
|
255 |
-
if ( defined( 'ADVADS_ADS_DISABLED' ) ) { return false; }
|
256 |
-
|
257 |
// don’t display ads that are not published or private for users not logged in
|
258 |
if ( $this->status !== 'publish' && ! ($this->status === 'private' && ! is_user_logged_in()) ){
|
259 |
return false;
|
260 |
}
|
261 |
|
262 |
-
// check if user is logged in and if so if users with his rights can see ads
|
263 |
-
if ( is_user_logged_in() && $see_ads_capability && current_user_can( $see_ads_capability ) ) {
|
264 |
-
return false;
|
265 |
-
}
|
266 |
-
|
267 |
if ( ! $this->can_display_by_conditions()
|
268 |
|| ! $this->can_display_by_visitor()
|
269 |
|| ! $this->can_display_by_expiry_date() ) {
|
@@ -283,9 +272,10 @@ class Advads_Ad {
|
|
283 |
* @return bool $can_display true if can be displayed in frontend
|
284 |
*/
|
285 |
public function can_display_by_conditions(){
|
286 |
-
|
|
|
287 |
|
288 |
-
$query = $
|
289 |
|
290 |
if ( empty($this->options['conditions']) ||
|
291 |
! is_array( $this->options['conditions'] ) ) { return true; }
|
@@ -298,7 +288,7 @@ class Advads_Ad {
|
|
298 |
switch ( $_cond_key ){
|
299 |
// check for post ids
|
300 |
case 'postids' :
|
301 |
-
if ( is_singular() && empty($_cond_value['all']) ){
|
302 |
// included posts
|
303 |
if ( ! empty($_cond_value['include']) ){
|
304 |
if ( is_string( $_cond_value['include'] ) ){
|
@@ -327,7 +317,7 @@ class Advads_Ad {
|
|
327 |
// check for category ids
|
328 |
case 'categoryids' :
|
329 |
// included
|
330 |
-
if ( is_singular() && empty($_cond_value['all']) ){
|
331 |
// get all taxonomies of the post
|
332 |
$term_ids = $this->get_object_terms( $post->ID );
|
333 |
|
@@ -363,7 +353,7 @@ class Advads_Ad {
|
|
363 |
// check for included category archive ids
|
364 |
// @link http://codex.wordpress.org/Conditional_Tags#A_Category_Page
|
365 |
case 'categoryarchiveids' :
|
366 |
-
if ( isset($query->term_id) && is_archive() && empty($_cond_value['all']) ){
|
367 |
if ( ! empty($_cond_value['include']) ){
|
368 |
if ( is_string( $_cond_value['include'] ) ){
|
369 |
$category_ids = explode( ',', $_cond_value['include'] );
|
@@ -415,37 +405,43 @@ class Advads_Ad {
|
|
415 |
// check is_front_page
|
416 |
// @link https://codex.wordpress.org/Conditional_Tags#The_Front_Page
|
417 |
case 'is_front_page' :
|
418 |
-
if ( $_cond_value == 0 &&
|
419 |
return false; }
|
420 |
break;
|
421 |
// check is_singular
|
422 |
// @link https://codex.wordpress.org/Conditional_Tags#A_Post_Type
|
423 |
case 'is_singular' :
|
424 |
-
if ( $_cond_value == 0 && is_singular() ) {
|
425 |
return false; }
|
426 |
break;
|
427 |
// check is_archive
|
428 |
// @link https://codex.wordpress.org/Conditional_Tags#Any_Archive_Page
|
429 |
case 'is_archive' :
|
430 |
-
if ( $_cond_value == 0 && is_archive() ) {
|
431 |
return false; }
|
432 |
break;
|
433 |
// check is_search
|
434 |
// @link https://codex.wordpress.org/Conditional_Tags#A_Search_Result_Page
|
435 |
case 'is_search' :
|
436 |
-
if ( $_cond_value == 0 && is_search() ) {
|
437 |
return false; }
|
438 |
break;
|
439 |
// check is_404
|
440 |
// @link https://codex.wordpress.org/Conditional_Tags#A_404_Not_Found_Page
|
441 |
case 'is_404' :
|
442 |
-
if ( $_cond_value == 0 && is_404() ) {
|
443 |
return false; }
|
444 |
break;
|
445 |
// check is_attachment
|
446 |
// @link https://codex.wordpress.org/Conditional_Tags#An_Attachment
|
447 |
case 'is_attachment' :
|
448 |
-
if ( $_cond_value == 0 && is_attachment() ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
return false; }
|
450 |
break;
|
451 |
}
|
241 |
}
|
242 |
|
243 |
/**
|
244 |
+
* check if the ad can be displayed in frontend due to its own conditions
|
245 |
*
|
246 |
* @since 1.0.0
|
247 |
* @return bool $can_display true if can be displayed in frontend
|
248 |
*/
|
249 |
public function can_display(){
|
250 |
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
// don’t display ads that are not published or private for users not logged in
|
252 |
if ( $this->status !== 'publish' && ! ($this->status === 'private' && ! is_user_logged_in()) ){
|
253 |
return false;
|
254 |
}
|
255 |
|
|
|
|
|
|
|
|
|
|
|
256 |
if ( ! $this->can_display_by_conditions()
|
257 |
|| ! $this->can_display_by_visitor()
|
258 |
|| ! $this->can_display_by_expiry_date() ) {
|
272 |
* @return bool $can_display true if can be displayed in frontend
|
273 |
*/
|
274 |
public function can_display_by_conditions(){
|
275 |
+
// use $wp_the_query to check the original query and not custom queries
|
276 |
+
global $post, $wp_the_query;
|
277 |
|
278 |
+
$query = $wp_the_query->get_queried_object();
|
279 |
|
280 |
if ( empty($this->options['conditions']) ||
|
281 |
! is_array( $this->options['conditions'] ) ) { return true; }
|
288 |
switch ( $_cond_key ){
|
289 |
// check for post ids
|
290 |
case 'postids' :
|
291 |
+
if ( $wp_the_query->is_singular() && empty($_cond_value['all']) ){
|
292 |
// included posts
|
293 |
if ( ! empty($_cond_value['include']) ){
|
294 |
if ( is_string( $_cond_value['include'] ) ){
|
317 |
// check for category ids
|
318 |
case 'categoryids' :
|
319 |
// included
|
320 |
+
if ( $wp_the_query->is_singular() && empty($_cond_value['all']) ){
|
321 |
// get all taxonomies of the post
|
322 |
$term_ids = $this->get_object_terms( $post->ID );
|
323 |
|
353 |
// check for included category archive ids
|
354 |
// @link http://codex.wordpress.org/Conditional_Tags#A_Category_Page
|
355 |
case 'categoryarchiveids' :
|
356 |
+
if ( isset($query->term_id) && $wp_the_query->is_archive() && empty($_cond_value['all']) ){
|
357 |
if ( ! empty($_cond_value['include']) ){
|
358 |
if ( is_string( $_cond_value['include'] ) ){
|
359 |
$category_ids = explode( ',', $_cond_value['include'] );
|
405 |
// check is_front_page
|
406 |
// @link https://codex.wordpress.org/Conditional_Tags#The_Front_Page
|
407 |
case 'is_front_page' :
|
408 |
+
if ( $_cond_value == 0 && $wp_the_query->is_front_page()) {
|
409 |
return false; }
|
410 |
break;
|
411 |
// check is_singular
|
412 |
// @link https://codex.wordpress.org/Conditional_Tags#A_Post_Type
|
413 |
case 'is_singular' :
|
414 |
+
if ( $_cond_value == 0 && $wp_the_query->is_singular() ) {
|
415 |
return false; }
|
416 |
break;
|
417 |
// check is_archive
|
418 |
// @link https://codex.wordpress.org/Conditional_Tags#Any_Archive_Page
|
419 |
case 'is_archive' :
|
420 |
+
if ( $_cond_value == 0 && $wp_the_query->is_archive() ) {
|
421 |
return false; }
|
422 |
break;
|
423 |
// check is_search
|
424 |
// @link https://codex.wordpress.org/Conditional_Tags#A_Search_Result_Page
|
425 |
case 'is_search' :
|
426 |
+
if ( $_cond_value == 0 && $wp_the_query->is_search() ) {
|
427 |
return false; }
|
428 |
break;
|
429 |
// check is_404
|
430 |
// @link https://codex.wordpress.org/Conditional_Tags#A_404_Not_Found_Page
|
431 |
case 'is_404' :
|
432 |
+
if ( $_cond_value == 0 && $wp_the_query->is_404() ) {
|
433 |
return false; }
|
434 |
break;
|
435 |
// check is_attachment
|
436 |
// @link https://codex.wordpress.org/Conditional_Tags#An_Attachment
|
437 |
case 'is_attachment' :
|
438 |
+
if ( $_cond_value == 0 && $wp_the_query->is_attachment() ) {
|
439 |
+
return false; }
|
440 |
+
break;
|
441 |
+
// check !is_main_query
|
442 |
+
// @link https://codex.wordpress.org/Function_Reference/is_main_query
|
443 |
+
case 'is_main_query' :
|
444 |
+
if ( $_cond_value == 0 && !is_main_query() ) {
|
445 |
return false; }
|
446 |
break;
|
447 |
}
|
classes/ad_ajax_callbacks.php
CHANGED
@@ -22,7 +22,7 @@ class Advads_Ad_Ajax_Callbacks {
|
|
22 |
|
23 |
add_action( 'wp_ajax_load_content_editor', array( $this, 'load_content_editor' ) );
|
24 |
add_action( 'wp_ajax_load_ad_parameters_metabox', array( $this, 'load_ad_parameters_metabox' ) );
|
25 |
-
|
26 |
}
|
27 |
|
28 |
/**
|
@@ -53,4 +53,30 @@ class Advads_Ad_Ajax_Callbacks {
|
|
53 |
wp_die();
|
54 |
|
55 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
}
|
22 |
|
23 |
add_action( 'wp_ajax_load_content_editor', array( $this, 'load_content_editor' ) );
|
24 |
add_action( 'wp_ajax_load_ad_parameters_metabox', array( $this, 'load_ad_parameters_metabox' ) );
|
25 |
+
add_action( 'wp_ajax_advads-terms-search', array( $this, 'search_terms' ) );
|
26 |
}
|
27 |
|
28 |
/**
|
53 |
wp_die();
|
54 |
|
55 |
}
|
56 |
+
|
57 |
+
/**
|
58 |
+
* search terms belonging to a specific taxonomy
|
59 |
+
*
|
60 |
+
* @sinc 1.4.7
|
61 |
+
*/
|
62 |
+
public function search_terms(){
|
63 |
+
$args = array();
|
64 |
+
$taxonomy = $_POST['tax'];
|
65 |
+
$args = array('hide_empty' => false, 'number' => 20);
|
66 |
+
|
67 |
+
if ( !isset( $_POST['search'] ) || $_POST['search'] === '' ) { wp_die(); }
|
68 |
+
|
69 |
+
// if search is an id, search for the term id, else do a full text search
|
70 |
+
if(0 !== absint($_POST['search'])){
|
71 |
+
$args['include'] = array(absint($_POST['search']));
|
72 |
+
} else {
|
73 |
+
$args['search'] = $_POST['search'];
|
74 |
+
}
|
75 |
+
|
76 |
+
$results = get_terms( $taxonomy, $args );
|
77 |
+
// $results = _WP_Editors::wp_link_query( $args );
|
78 |
+
echo wp_json_encode( $results );
|
79 |
+
echo "\n";
|
80 |
+
wp_die();
|
81 |
+
}
|
82 |
}
|
classes/ad_group.php
CHANGED
@@ -145,7 +145,7 @@ class Advads_Ad_Group {
|
|
145 |
$ads = $this->load_all_ads();
|
146 |
if ( $ads === array() ) { return; }
|
147 |
|
148 |
-
// get ad weights serving as
|
149 |
$weights = $this->get_ad_weights();
|
150 |
asort($weights);
|
151 |
|
@@ -287,10 +287,10 @@ class Advads_Ad_Group {
|
|
287 |
|
288 |
$rand = mt_rand( 1, $max );
|
289 |
|
290 |
-
foreach ( $ad_weights as $
|
291 |
-
$rand -= $
|
292 |
if ( $rand <= 0 ) {
|
293 |
-
return $
|
294 |
}
|
295 |
}
|
296 |
}
|
145 |
$ads = $this->load_all_ads();
|
146 |
if ( $ads === array() ) { return; }
|
147 |
|
148 |
+
// get ad weights serving as an order here
|
149 |
$weights = $this->get_ad_weights();
|
150 |
asort($weights);
|
151 |
|
287 |
|
288 |
$rand = mt_rand( 1, $max );
|
289 |
|
290 |
+
foreach ( $ad_weights as $ad_id => $_weight ) {
|
291 |
+
$rand -= $_weight;
|
292 |
if ( $rand <= 0 ) {
|
293 |
+
return $ad_id;
|
294 |
}
|
295 |
}
|
296 |
}
|
includes/array_ad_conditions.php
CHANGED
@@ -82,6 +82,11 @@ $advanced_ads_ad_conditions = array(
|
|
82 |
'label' => __( 'Attachment Pages', $advanced_ads_slug ),
|
83 |
'description' => __( 'show on attachment pages', $advanced_ads_slug ),
|
84 |
'type' => 'radio',
|
|
|
|
|
|
|
|
|
|
|
85 |
)
|
86 |
);
|
87 |
|
82 |
'label' => __( 'Attachment Pages', $advanced_ads_slug ),
|
83 |
'description' => __( 'show on attachment pages', $advanced_ads_slug ),
|
84 |
'type' => 'radio',
|
85 |
+
),
|
86 |
+
'is_main_query' => array(
|
87 |
+
'label' => __( 'Secondary Queries', $advanced_ads_slug ),
|
88 |
+
'description' => __( 'allow ads in secondary queries', $advanced_ads_slug ),
|
89 |
+
'type' => 'radio',
|
90 |
)
|
91 |
);
|
92 |
|
public/class-advanced-ads.php
CHANGED
@@ -25,7 +25,7 @@ class Advanced_Ads {
|
|
25 |
* @var string
|
26 |
*/
|
27 |
|
28 |
-
const VERSION = '1.4.
|
29 |
|
30 |
/**
|
31 |
* post type slug
|
@@ -89,6 +89,14 @@ class Advanced_Ads {
|
|
89 |
*/
|
90 |
protected $internal_options = false;
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
/**
|
93 |
* Initialize the plugin by setting localization and loading public scripts
|
94 |
* and styles.
|
@@ -152,7 +160,7 @@ class Advanced_Ads {
|
|
152 |
*/
|
153 |
public function set_disabled_constant(){
|
154 |
|
155 |
-
global $post;
|
156 |
|
157 |
// don't set the constant if already defined
|
158 |
if ( defined( 'ADVADS_ADS_DISABLED' ) ) { return; }
|
@@ -166,19 +174,25 @@ class Advanced_Ads {
|
|
166 |
}
|
167 |
|
168 |
// check if ads are disabled from 404 pages
|
169 |
-
if ( is_404() && ! empty($options['disabled-ads']['404']) ){
|
170 |
define( 'ADVADS_ADS_DISABLED', true );
|
171 |
return;
|
172 |
}
|
173 |
|
174 |
// check if ads are disabled from non singular pages (often = archives)
|
175 |
-
if ( ! is_singular() && ! empty($options['disabled-ads']['archives']) ){
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
define( 'ADVADS_ADS_DISABLED', true );
|
177 |
return;
|
178 |
}
|
179 |
|
180 |
// check if ads are disabled on the current page
|
181 |
-
if ( is_singular() && isset($post->ID) ){
|
182 |
$post_ad_options = get_post_meta( $post->ID, '_advads_ad_settings', true );
|
183 |
|
184 |
if ( ! empty($post_ad_options['disable_ads']) ){
|
@@ -750,4 +764,51 @@ class Advanced_Ads {
|
|
750 |
|
751 |
return get_terms( Advanced_Ads::AD_GROUP_TAXONOMY, $args );
|
752 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
753 |
}
|
25 |
* @var string
|
26 |
*/
|
27 |
|
28 |
+
const VERSION = '1.4.9';
|
29 |
|
30 |
/**
|
31 |
* post type slug
|
89 |
*/
|
90 |
protected $internal_options = false;
|
91 |
|
92 |
+
/**
|
93 |
+
* list of bots and crawlers to exclude from ad impressions
|
94 |
+
*
|
95 |
+
* @since 1.4.9
|
96 |
+
* @var array list of bots
|
97 |
+
*/
|
98 |
+
protected $bots = array('008','ABACHOBot','Accoona-AI-Agent','AddSugarSpiderBot','ADmantX','AhrefsBot','alexa','AnyApexBot','appie','Apple-PubSub','Arachmo','Ask Jeeves','avira.com','B-l-i-t-z-B-O-T','Baiduspider','BecomeBot','BeslistBot','BillyBobBot','Bimbot','Bingbot','BLEXBot','BlitzBOT','boitho.com-dc','boitho.com-robot','bot','btbot','CatchBot','Cerberian Drtrs','Charlotte','ConveraCrawler','cosmos','Covario IDS','crawler','CrystalSemanticsBot','curl','DataparkSearch','DiamondBot','Discobot','Dotbot','EmeraldShield.com WebBot','envolk[ITS]spider','EsperanzaBot','Exabot','expo9','facebookexternalhit','FAST Enterprise Crawler','FAST-WebCrawler','FDSE robot','Feedfetcher-Google','FindLinks','Firefly','froogle','FurlBot','FyberSpider','g2crawler','Gaisbot','GalaxyBot','genieBot','Genieo','Gigabot','Girafabot','Googlebot','Googlebot-Image','GrapeshotCrawler','GurujiBot','HappyFunBot','heritrix','hl_ftien_spider','Holmes','htdig','https://developers.google.com','ia_archiver','iaskspider','iCCrawler','ichiro','igdeSpyder','InfoSeek','inktomi','IRLbot','IssueCrawler','Jaxified Bot','Jyxobot','KoepaBot','Kraken','L.webis','LapozzBot','Larbin','LDSpider','LexxeBot','Linguee','Bot','LinkWalker','lmspider','looksmart','lwp-trivial','mabontland','magpie-crawler','Mail.RU_Bot','MaxPointCrawler','Mediapartners-Google','MJ12bot','Mnogosearch','mogimogi','MojeekBot','Moreoverbot','Morning Paper','msnbot','MSRBot','MVAClient','mxbot','NationalDirectory','NetResearchServer','NetSeer Crawler','NewsGator','NG-Search','nicebot','noxtrumbot','Nusearch','Spider','Nutch crawler','NutchCVS','Nymesis','obot','oegp','omgilibot','OmniExplorer_Bot','OOZBOT','Orbiter','PageBitesHyperBot','Peew','polybot','Pompos','PostPost','proximic','Psbot','PycURL','Qseero','rabaz','Radian6','RAMPyBot','Rankivabot','RufusBot','SandCrawler','savetheworldheritage','SBIder','Scooter','ScoutJet','Scrubby','SearchSight','Seekbot','semanticdiscovery','Sensis','Web Crawler','SEOChat::Bot','SeznamBot','Shim-Crawler','ShopWiki','Shoula robot','silk','Sitebot','Snappy','sogou spider','Sogou web spider','Sosospider','Spade','Speedy Spider','Sqworm','StackRambler','suggybot','SurveyBot','SynooBot','TechnoratiSnoop','TECNOSEEK','Teoma','TerrawizBot','TheSuBot','Thumbnail.CZ','robot','TinEye','truwoGPS','TurnitinBot','TweetedTimes Bot','TwengaBot','updated','URL_Spider_SQL','Urlfilebot','Vagabondo','VoilaBot','voltron','Vortex','voyager','VYU2','WebAlta Crawler','WebBug','webcollage','WebFindBot','WebIndex','Websquash.com','WeSEE:Ads','wf84','Wget','WoFindeIch Robot','WomlpeFactory','WordPress','Xaldon_WebSpider','yacy','Yahoo! Slurp','Yahoo! Slurp China','YahooSeeker','YahooSeeker-Testing','YandexBot','YandexImages','Yasaklibot','Yeti','YodaoBot','yoogliFetchAgent','YoudaoBot','Zao','Zealbot','zspider','ZyBorg');
|
99 |
+
|
100 |
/**
|
101 |
* Initialize the plugin by setting localization and loading public scripts
|
102 |
* and styles.
|
160 |
*/
|
161 |
public function set_disabled_constant(){
|
162 |
|
163 |
+
global $post, $wp_the_query;
|
164 |
|
165 |
// don't set the constant if already defined
|
166 |
if ( defined( 'ADVADS_ADS_DISABLED' ) ) { return; }
|
174 |
}
|
175 |
|
176 |
// check if ads are disabled from 404 pages
|
177 |
+
if ( $wp_the_query->is_404() && ! empty($options['disabled-ads']['404']) ){
|
178 |
define( 'ADVADS_ADS_DISABLED', true );
|
179 |
return;
|
180 |
}
|
181 |
|
182 |
// check if ads are disabled from non singular pages (often = archives)
|
183 |
+
if ( ! $wp_the_query->is_singular() && ! empty($options['disabled-ads']['archives']) ){
|
184 |
+
define( 'ADVADS_ADS_DISABLED', true );
|
185 |
+
return;
|
186 |
+
}
|
187 |
+
|
188 |
+
// check if ads are disabled in secondary queries
|
189 |
+
if ( ! is_main_query() && ! empty($options['disabled-ads']['secondary']) ){
|
190 |
define( 'ADVADS_ADS_DISABLED', true );
|
191 |
return;
|
192 |
}
|
193 |
|
194 |
// check if ads are disabled on the current page
|
195 |
+
if ( $wp_the_query->is_singular() && isset($post->ID) ){
|
196 |
$post_ad_options = get_post_meta( $post->ID, '_advads_ad_settings', true );
|
197 |
|
198 |
if ( ! empty($post_ad_options['disable_ads']) ){
|
764 |
|
765 |
return get_terms( Advanced_Ads::AD_GROUP_TAXONOMY, $args );
|
766 |
}
|
767 |
+
|
768 |
+
/**
|
769 |
+
* general check if ads can be displayed for the whole page impression
|
770 |
+
*
|
771 |
+
* @since 1.4.9
|
772 |
+
* @return bool true, if ads can be displayed
|
773 |
+
* @todo move this to set_disabled_constant()
|
774 |
+
*/
|
775 |
+
public function can_display_ads(){
|
776 |
+
|
777 |
+
// check global constant if ads are enabled or disabled
|
778 |
+
if ( defined( 'ADVADS_ADS_DISABLED' ) ) { return false; }
|
779 |
+
|
780 |
+
$options = $this->options();
|
781 |
+
$see_ads_capability = ( ! empty($options['hide-for-user-role'])) ? $options['hide-for-user-role'] : 0;
|
782 |
+
|
783 |
+
// check if user is logged in and if so if users with his rights can see ads
|
784 |
+
if ( is_user_logged_in() && $see_ads_capability && current_user_can( $see_ads_capability ) ) {
|
785 |
+
return false;
|
786 |
+
}
|
787 |
+
|
788 |
+
// check bots if option is enabled
|
789 |
+
if(isset($options['block-bots']) && $options['block-bots'] && $this->is_bot()) return false;
|
790 |
+
|
791 |
+
return true;
|
792 |
+
}
|
793 |
+
|
794 |
+
/**
|
795 |
+
* check if the current user agent is given or a bot
|
796 |
+
*
|
797 |
+
* @since 1.4.9
|
798 |
+
* @return bool true if the current user agent is empty or a bot
|
799 |
+
*/
|
800 |
+
public function is_bot(){
|
801 |
+
$bots = apply_filters('advanced-ads-bots', $this->bots);
|
802 |
+
$bots = implode('|', $bots);
|
803 |
+
$bots = preg_replace('@[^-_;/|\][ a-z0-9]@i', '', $bots);
|
804 |
+
$regex = "@$bots@i";
|
805 |
+
|
806 |
+
if(isset($_SERVER['HTTP_USER_AGENT'])) {
|
807 |
+
$agent = $_SERVER['HTTP_USER_AGENT'];
|
808 |
+
|
809 |
+
return preg_match($regex, $agent) === 1;
|
810 |
+
}
|
811 |
+
|
812 |
+
return true;
|
813 |
+
}
|
814 |
}
|
public/functions.php
CHANGED
@@ -15,6 +15,8 @@ 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 |
|
@@ -47,6 +49,8 @@ function get_ad_group($id = 0){
|
|
47 |
$id = absint( $id );
|
48 |
if ( empty($id) ) { return; }
|
49 |
|
|
|
|
|
50 |
// get ad
|
51 |
$adgroup = new Advads_Ad_Group( $id );
|
52 |
return $adgroup->output();
|
@@ -74,6 +78,8 @@ function the_ad_group($id = 0){
|
|
74 |
function get_ad_placement($id = ''){
|
75 |
if ( $id == '' ) { return; }
|
76 |
|
|
|
|
|
77 |
// get placement content
|
78 |
$output = Advads_Ad_Placements::output( $id );
|
79 |
return $output;
|
@@ -89,4 +95,14 @@ function the_ad_placement($id = ''){
|
|
89 |
|
90 |
echo get_ad_placement( $id );
|
91 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
}
|
15 |
$id = absint( $id );
|
16 |
if ( empty($id) ) { return; }
|
17 |
|
18 |
+
if(!advads_can_display_ads()) return;
|
19 |
+
|
20 |
// get ad
|
21 |
$ad = new Advads_Ad( $id, $args );
|
22 |
|
49 |
$id = absint( $id );
|
50 |
if ( empty($id) ) { return; }
|
51 |
|
52 |
+
if(!advads_can_display_ads()) return;
|
53 |
+
|
54 |
// get ad
|
55 |
$adgroup = new Advads_Ad_Group( $id );
|
56 |
return $adgroup->output();
|
78 |
function get_ad_placement($id = ''){
|
79 |
if ( $id == '' ) { return; }
|
80 |
|
81 |
+
if(!advads_can_display_ads()) return;
|
82 |
+
|
83 |
// get placement content
|
84 |
$output = Advads_Ad_Placements::output( $id );
|
85 |
return $output;
|
95 |
|
96 |
echo get_ad_placement( $id );
|
97 |
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* return true if ads can be displayed
|
102 |
+
*
|
103 |
+
* @since 1.4.9
|
104 |
+
* @return bool, true if ads can be displayed
|
105 |
+
*/
|
106 |
+
function advads_can_display_ads(){
|
107 |
+
return Advanced_Ads::get_instance()->can_display_ads();
|
108 |
}
|
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 beta
|
7 |
-
Stable tag: 1.4.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -56,12 +56,15 @@ deliver ads based on conditions like
|
|
56 |
* posts by category, tags, taxonomies
|
57 |
* archive pages by category, tags, taxonomies
|
58 |
* special page types like 404, attachment and front page
|
|
|
59 |
|
60 |
global conditions
|
61 |
|
62 |
* disable all ads in the frontend (e.g. when your ad network breaks down)
|
63 |
* disable all ads on 404 pages (e.g. AdSense doesn’t allow that)
|
64 |
* disable all ads on non-singular pages with a single click
|
|
|
|
|
65 |
|
66 |
= visitor conditions =
|
67 |
|
@@ -171,6 +174,16 @@ There is no revenue share. Advanced Ads doesn’t alter your ad codes in a way t
|
|
171 |
|
172 |
== Changelog ==
|
173 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
= 1.4.8 =
|
175 |
|
176 |
* COMPLETE MAKEOVER OF AD GROUPS
|
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 beta
|
7 |
+
Stable tag: 1.4.9
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
56 |
* posts by category, tags, taxonomies
|
57 |
* archive pages by category, tags, taxonomies
|
58 |
* special page types like 404, attachment and front page
|
59 |
+
* hide ads on secondary queries (e.g. posts in sidebars)
|
60 |
|
61 |
global conditions
|
62 |
|
63 |
* disable all ads in the frontend (e.g. when your ad network breaks down)
|
64 |
* disable all ads on 404 pages (e.g. AdSense doesn’t allow that)
|
65 |
* disable all ads on non-singular pages with a single click
|
66 |
+
* disable all ads in secondary queries
|
67 |
+
* hide ads from bots and web crawlers
|
68 |
|
69 |
= visitor conditions =
|
70 |
|
174 |
|
175 |
== Changelog ==
|
176 |
|
177 |
+
= 1.4.9 =
|
178 |
+
|
179 |
+
* added option to hide ads from crawlers and other bots (option is disabled by default)
|
180 |
+
* added Secondary Queries display condition, e.g. to hide ads from posts in sidebars
|
181 |
+
* added frontend function `advads_can_display_ads()` to check if ads are displayed in general
|
182 |
+
* global option to disable all ads in secondary queries
|
183 |
+
* search for term ids in display conditions
|
184 |
+
* fixed ad conditions using conditional tags of subquery instead of the main query
|
185 |
+
* fixed search for terms in display conditions
|
186 |
+
|
187 |
= 1.4.8 =
|
188 |
|
189 |
* COMPLETE MAKEOVER OF AD GROUPS
|