Version Description
=
major changes:
- moved auto injections from ads to placements [PLEASE MOVE YOUR INJECTIONS THERE]
- added post content injections
- reading suggestion: My test of AdSense Responsive Ads
other fixes:
- fix bugs with ad weights throwing issues when not set
- removed public ad groups query
- updated arrays displayed on debug page
- ad groups are now displayed before ads in placements and ad widget
- added title to widget
Download this release
Release Info
Developer | webzunft |
Plugin | Advanced Ads |
Version | 1.2.1 |
Comparing to | |
See all releases |
Code changes from version 1.2 to 1.2.1
- admin/assets/css/admin.css +4 -2
- admin/class-advanced-ads-admin.php +38 -5
- admin/includes/class-ad-groups-list-table.php +2 -1
- admin/views/ad-inject-metabox.php +6 -1
- admin/views/debug.php +5 -2
- admin/views/placements.php +102 -60
- advanced-ads.php +1 -1
- classes/ad.php +17 -15
- classes/ad_group.php +26 -16
- classes/ad_placements.php +110 -20
- classes/widget.php +19 -7
- public/assets/js/public.js +1 -38
- public/class-advanced-ads.php +33 -14
- readme.txt +18 -2
admin/assets/css/admin.css
CHANGED
@@ -45,13 +45,15 @@
|
|
45 |
/**
|
46 |
AD PLACEMENTS
|
47 |
*/
|
|
|
48 |
.advads-placements-new-form label { display: inline-block; width: 10em; }
|
49 |
.advads-placements-new-form input { display: inline-block; }
|
50 |
.advads-placements-table { min-width: 80%; }
|
51 |
.advads-placements-table thead tr { background: #fff; }
|
52 |
.advads-placements-table tbody tr:nth-child(even) { background: #fff; }
|
53 |
-
.advads-placements-table th { margin: 0; padding: 10px; text-align: left; }
|
54 |
-
.advads-placements-table td { margin: 0; padding: 10px; text-align: left; }
|
|
|
55 |
/**
|
56 |
GENERAL ELEMENTS
|
57 |
*/
|
45 |
/**
|
46 |
AD PLACEMENTS
|
47 |
*/
|
48 |
+
.advads-placements-new-form select { display: inline-block; min-width: 10em; }
|
49 |
.advads-placements-new-form label { display: inline-block; width: 10em; }
|
50 |
.advads-placements-new-form input { display: inline-block; }
|
51 |
.advads-placements-table { min-width: 80%; }
|
52 |
.advads-placements-table thead tr { background: #fff; }
|
53 |
.advads-placements-table tbody tr:nth-child(even) { background: #fff; }
|
54 |
+
.advads-placements-table th { margin: 0; padding: 10px; text-align: left; vertical-align: top; }
|
55 |
+
.advads-placements-table td { margin: 0; padding: 10px; text-align: left; vertical-align: top; }
|
56 |
+
.advads-placements-table-options { text-align: right; }
|
57 |
/**
|
58 |
GENERAL ELEMENTS
|
59 |
*/
|
admin/class-advanced-ads-admin.php
CHANGED
@@ -94,6 +94,9 @@ class Advanced_Ads_Admin {
|
|
94 |
// settings handling
|
95 |
add_action('admin_init', array($this, 'settings_init'));
|
96 |
|
|
|
|
|
|
|
97 |
// Add an action link pointing to the options page.
|
98 |
$plugin_basename = plugin_basename(plugin_dir_path('__DIR__') . $this->plugin_slug . '.php');
|
99 |
add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links'));
|
@@ -155,6 +158,33 @@ class Advanced_Ads_Admin {
|
|
155 |
|
156 |
}
|
157 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
/**
|
159 |
* Register the administration menu for this plugin into the WordPress Dashboard menu.
|
160 |
*
|
@@ -205,6 +235,7 @@ class Advanced_Ads_Admin {
|
|
205 |
} elseif(isset($return) && $return === true){
|
206 |
$success = __('Placements updated', ADVADS_SLUG);
|
207 |
}
|
|
|
208 |
$placements = Advanced_Ads::get_ad_placements_array();
|
209 |
// load ads and groups for select field
|
210 |
|
@@ -220,8 +251,9 @@ class Advanced_Ads_Admin {
|
|
220 |
public function display_plugin_debug_page() {
|
221 |
// load array with ads by condition
|
222 |
$plugin = Advanced_Ads::get_instance();
|
|
|
223 |
$ads_by_conditions = $plugin->get_ads_by_conditions_array();
|
224 |
-
$
|
225 |
|
226 |
include_once( 'views/debug.php' );
|
227 |
}
|
@@ -569,10 +601,11 @@ class Advanced_Ads_Admin {
|
|
569 |
}
|
570 |
}
|
571 |
|
572 |
-
// save global injection array to WP options table
|
573 |
-
|
574 |
-
|
575 |
-
|
|
|
576 |
}
|
577 |
|
578 |
}
|
94 |
// settings handling
|
95 |
add_action('admin_init', array($this, 'settings_init'));
|
96 |
|
97 |
+
// admin notices
|
98 |
+
add_action('admin_notices', array($this, 'admin_notices'));
|
99 |
+
|
100 |
// Add an action link pointing to the options page.
|
101 |
$plugin_basename = plugin_basename(plugin_dir_path('__DIR__') . $this->plugin_slug . '.php');
|
102 |
add_filter('plugin_action_links_' . $plugin_basename, array($this, 'add_action_links'));
|
158 |
|
159 |
}
|
160 |
|
161 |
+
/**
|
162 |
+
* display admin notices
|
163 |
+
*
|
164 |
+
* @since 1.2.1
|
165 |
+
*/
|
166 |
+
public function admin_notices()
|
167 |
+
{
|
168 |
+
|
169 |
+
// display notice in case there are still old ad injections
|
170 |
+
$old_injections = get_option('advads-ads-injections', array());
|
171 |
+
|
172 |
+
// display ad before the content
|
173 |
+
if(isset($old_injections) && count($old_injections) > 0){
|
174 |
+
$_injection_ids = array();
|
175 |
+
foreach($old_injections as $_inj){
|
176 |
+
$_injection_ids = array_merge($_injection_ids, $_inj);
|
177 |
+
}
|
178 |
+
$ad_links = array();
|
179 |
+
foreach($_injection_ids as $_inj_id){
|
180 |
+
$ad_links[] = '<a href="' . get_edit_post_link($_inj_id) . '">'.$_inj_id.'</a>';
|
181 |
+
}
|
182 |
+
?>
|
183 |
+
<div class="error"><p><?php printf(__('Advanced Ads Update: Auto injections are now managed through placements. Please convert these ads with auto injections: %s', ADVADS_SLUG), implode(', ', $ad_links));?></p></div>
|
184 |
+
<?php
|
185 |
+
}
|
186 |
+
}
|
187 |
+
|
188 |
/**
|
189 |
* Register the administration menu for this plugin into the WordPress Dashboard menu.
|
190 |
*
|
235 |
} elseif(isset($return) && $return === true){
|
236 |
$success = __('Placements updated', ADVADS_SLUG);
|
237 |
}
|
238 |
+
$placement_types = Advads_Ad_Placements::get_placement_types();
|
239 |
$placements = Advanced_Ads::get_ad_placements_array();
|
240 |
// load ads and groups for select field
|
241 |
|
251 |
public function display_plugin_debug_page() {
|
252 |
// load array with ads by condition
|
253 |
$plugin = Advanced_Ads::get_instance();
|
254 |
+
$plugin_options = $plugin->options();
|
255 |
$ads_by_conditions = $plugin->get_ads_by_conditions_array();
|
256 |
+
$ad_placements = Advanced_Ads::get_ad_placements_array();
|
257 |
|
258 |
include_once( 'views/debug.php' );
|
259 |
}
|
601 |
}
|
602 |
}
|
603 |
|
604 |
+
// save global injection array to WP options table or remove it
|
605 |
+
if(is_array($all_injections) && count($all_injections) > 0)
|
606 |
+
update_option('advads-ads-injections', $all_injections);
|
607 |
+
else
|
608 |
+
delete_option ('advads-ads-injections');
|
609 |
}
|
610 |
|
611 |
}
|
admin/includes/class-ad-groups-list-table.php
CHANGED
@@ -142,7 +142,8 @@ class AdvAds_Groups_List_Table extends AdvAds_List_Table {
|
|
142 |
$args = array(
|
143 |
'post_type' => $this->post_type,
|
144 |
'post_status' => 'publish',
|
145 |
-
|
|
|
146 |
);
|
147 |
$ads = new WP_Query($args);
|
148 |
|
142 |
$args = array(
|
143 |
'post_type' => $this->post_type,
|
144 |
'post_status' => 'publish',
|
145 |
+
'taxonomy' => $this->taxonomy,
|
146 |
+
'term' => $tag->slug
|
147 |
);
|
148 |
$ads = new WP_Query($args);
|
149 |
|
admin/views/ad-inject-metabox.php
CHANGED
@@ -1,5 +1,7 @@
|
|
1 |
<p class="description"><?php _e('Include ads on specific places automatically without shortcodes or functions.', ADVADS_SLUG); ?></p>
|
2 |
<?php $options = $ad->options('injection'); ?>
|
|
|
|
|
3 |
<ul id="advanced-ad-injection">
|
4 |
<li>
|
5 |
<input type="checkbox" name="advanced_ad[injection][header]"
|
@@ -25,4 +27,7 @@
|
|
25 |
<?php checked(!empty($options['post_end']), 1); ?>/>
|
26 |
<label for="advanced-ad-injection-post_end"><?php _e('Include after the post content', ADVADS_SLUG); ?></label>
|
27 |
</li>
|
28 |
-
</ul>
|
|
|
|
|
|
1 |
<p class="description"><?php _e('Include ads on specific places automatically without shortcodes or functions.', ADVADS_SLUG); ?></p>
|
2 |
<?php $options = $ad->options('injection'); ?>
|
3 |
+
<?php if($options) : ?>
|
4 |
+
<p style="color: red;"><?php _e('This feature is now provided through placements. Please convert the settings made here to placements.', ADVADS_SLUG); ?></p>
|
5 |
<ul id="advanced-ad-injection">
|
6 |
<li>
|
7 |
<input type="checkbox" name="advanced_ad[injection][header]"
|
27 |
<?php checked(!empty($options['post_end']), 1); ?>/>
|
28 |
<label for="advanced-ad-injection-post_end"><?php _e('Include after the post content', ADVADS_SLUG); ?></label>
|
29 |
</li>
|
30 |
+
</ul>
|
31 |
+
<?php else : ?>
|
32 |
+
<p><?php _e('This feature is now provided through placements. Please convert the settings made here to placements.', ADVADS_SLUG); ?></p>
|
33 |
+
<?php endif; ?>
|
admin/views/debug.php
CHANGED
@@ -10,10 +10,13 @@
|
|
10 |
<?php screen_icon(); ?>
|
11 |
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
12 |
|
|
|
|
|
|
|
13 |
<h2><?php _e('Ad Condition Overview', $this->plugin_slug); ?></h2>
|
14 |
<pre><?php print_r($ads_by_conditions); ?></pre>
|
15 |
|
16 |
-
<h2><?php _e('Ad
|
17 |
-
<pre><?php print_r($
|
18 |
|
19 |
</div>
|
10 |
<?php screen_icon(); ?>
|
11 |
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
12 |
|
13 |
+
<h2><?php _e('Settings', $this->plugin_slug); ?></h2>
|
14 |
+
<pre><?php print_r($plugin_options); ?></pre>
|
15 |
+
|
16 |
<h2><?php _e('Ad Condition Overview', $this->plugin_slug); ?></h2>
|
17 |
<pre><?php print_r($ads_by_conditions); ?></pre>
|
18 |
|
19 |
+
<h2><?php _e('Ad Placements', $this->plugin_slug); ?></h2>
|
20 |
+
<pre><?php print_r($ad_placements); ?></pre>
|
21 |
|
22 |
</div>
|
admin/views/placements.php
CHANGED
@@ -2,20 +2,39 @@
|
|
2 |
/**
|
3 |
* the view for the placements page
|
4 |
*/
|
5 |
-
|
6 |
-
|
7 |
-
<div class="
|
8 |
-
<?php if ($error) : ?>
|
9 |
-
<div id="message" class="error"><p><?php echo $error; ?></p></div>
|
10 |
<?php endif; ?>
|
11 |
<?php if ($success) : ?>
|
12 |
-
|
13 |
<?php endif; ?>
|
14 |
<?php screen_icon(); ?>
|
15 |
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
16 |
<p class="description"><?php _e('Placements are physically places in your theme and posts. You can use them if you plan to change ads and ad groups on the same place without the need to change your templates.', ADVADS_SLUG); ?></p>
|
|
|
17 |
<h2><?php _e('Create a new placement', ADVADS_SLUG); ?></h2>
|
18 |
<form method="POST" action="" class="advads-placements-new-form">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
<label for="advads-placement-name"><?php _e('Name', ADVADS_SLUG); ?></label>
|
20 |
<input id="advads-plcement-name" name="advads[placement][name]" type="text" value=""/><br/>
|
21 |
<label for="advads-placement-slug"><?php _e('ID', ADVADS_SLUG); ?></label>
|
@@ -24,62 +43,85 @@
|
|
24 |
<p class=""><?php _e('You can assign Ads and Groups after you created the placement.', ADVADS_SLUG); ?></p>
|
25 |
<input type="submit" class="button button-primary" value="<?php _e('Save New Placement', ADVADS_SLUG); ?>"/>
|
26 |
</form>
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
<p class="description"><?php _e('To use an ad placement with the ID skyscraper_left in content fields', ADVADS_SLUG); ?></p>
|
34 |
<pre><input type="text" onclick="this.select();" style="width: 400px;" value='[the_ad_placement id="skyscraper_left"]'/></pre>
|
35 |
-
|
36 |
<p class="description"><?php _e('To use an ad placement with the ID skyscraper_left in template files', ADVADS_SLUG); ?></p>
|
37 |
<pre><input type="text" onclick="this.select();" style="width: 400px;" value='the_ad_placement("skyscraper_left");'/></pre>
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
</div>
|
2 |
/**
|
3 |
* the view for the placements page
|
4 |
*/
|
5 |
+
?><div class="wrap">
|
6 |
+
<?php if ($error) : ?>
|
7 |
+
<div id="message" class="error"><p><?php echo $error; ?></p></div>
|
|
|
|
|
8 |
<?php endif; ?>
|
9 |
<?php if ($success) : ?>
|
10 |
+
<div id="message" class="updated"><p><?php echo $success; ?></p></div>
|
11 |
<?php endif; ?>
|
12 |
<?php screen_icon(); ?>
|
13 |
<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
|
14 |
<p class="description"><?php _e('Placements are physically places in your theme and posts. You can use them if you plan to change ads and ad groups on the same place without the need to change your templates.', ADVADS_SLUG); ?></p>
|
15 |
+
<p class="description"><?php printf(__('See also the manual for more information on <a href="%s">placements</a> and <a href="%s">auto injection</a>.', ADVADS_SLUG), 'http://wpadvancedads.com/advancedads/manual/placements/', 'http://wpadvancedads.com/advancedads/manual/auto-injection/'); ?></p>
|
16 |
<h2><?php _e('Create a new placement', ADVADS_SLUG); ?></h2>
|
17 |
<form method="POST" action="" class="advads-placements-new-form">
|
18 |
+
<label for="advads-placement-type"><?php _e('Type', ADVADS_SLUG); ?></label>
|
19 |
+
<select id="advads-plcement-type" name="advads[placement][type]">
|
20 |
+
<?php
|
21 |
+
if (is_array($placement_types))
|
22 |
+
foreach ($placement_types as $_key => $_place) :
|
23 |
+
?><option value="<?php echo $_key; ?>"><?php echo $_place['title']; ?></option><?php
|
24 |
+
endforeach;
|
25 |
+
?>
|
26 |
+
</select>
|
27 |
+
<a onclick="advads_toggle('#advads-ad-place-type-info')"><?php _e('What is this?', ADVADS_SLUG); ?></a>
|
28 |
+
<div id="advads-ad-place-type-info" style="display: none;">
|
29 |
+
<p class="description"><?php _e('Placement types define how the placements works and where it is going to be displayed.', ADVADS_SLUG); ?></p>
|
30 |
+
<dl><?php foreach($placement_types as $_place) : ?>
|
31 |
+
<dt><?php echo $_place['title']; ?></dt><dd><?php echo $_place['description']; ?></dd>
|
32 |
+
<?php endforeach; ?>
|
33 |
+
</dl>
|
34 |
+
</div>
|
35 |
+
|
36 |
+
|
37 |
+
<br/>
|
38 |
<label for="advads-placement-name"><?php _e('Name', ADVADS_SLUG); ?></label>
|
39 |
<input id="advads-plcement-name" name="advads[placement][name]" type="text" value=""/><br/>
|
40 |
<label for="advads-placement-slug"><?php _e('ID', ADVADS_SLUG); ?></label>
|
43 |
<p class=""><?php _e('You can assign Ads and Groups after you created the placement.', ADVADS_SLUG); ?></p>
|
44 |
<input type="submit" class="button button-primary" value="<?php _e('Save New Placement', ADVADS_SLUG); ?>"/>
|
45 |
</form>
|
46 |
+
<?php if (isset($placements) && is_array($placements)) : ?>
|
47 |
+
<h2><?php _e('Placements', ADVADS_SLUG); ?></h2>
|
48 |
+
<a onclick="advads_toggle('#advads-ad-place-display-info')"><?php _e('How to use the ’default’ Ad Placement?', ADVADS_SLUG); ?></a>
|
49 |
+
<div id="advads-ad-place-display-info" style="display: none;">
|
50 |
+
<p><?php printf(__('Examples on how to use the ’default’ ad placement? Find more help and examples in the <a href="%s" target="_blank">manual</a>', ADVADS_SLUG), 'http://wpadvancedads.com/advanced-ads/manual/placements/'); ?></p>
|
51 |
+
<h4><?php _e('shortcode', ADVADS_SLUG); ?></h4>
|
52 |
<p class="description"><?php _e('To use an ad placement with the ID skyscraper_left in content fields', ADVADS_SLUG); ?></p>
|
53 |
<pre><input type="text" onclick="this.select();" style="width: 400px;" value='[the_ad_placement id="skyscraper_left"]'/></pre>
|
54 |
+
<h4><?php _e('template', ADVADS_SLUG); ?></h4>
|
55 |
<p class="description"><?php _e('To use an ad placement with the ID skyscraper_left in template files', ADVADS_SLUG); ?></p>
|
56 |
<pre><input type="text" onclick="this.select();" style="width: 400px;" value='the_ad_placement("skyscraper_left");'/></pre>
|
57 |
+
</div>
|
58 |
+
<form method="POST" action="">
|
59 |
+
<table class="advads-placements-table">
|
60 |
+
<thead>
|
61 |
+
<tr>
|
62 |
+
<th><?php _e('Name', ADVADS_SLUG); ?></th>
|
63 |
+
<th><?php _e('Type', ADVADS_SLUG); ?></th>
|
64 |
+
<th><?php _e('ID', ADVADS_SLUG); ?></th>
|
65 |
+
<th><?php _e('Options', ADVADS_SLUG); ?></th>
|
66 |
+
<th></th>
|
67 |
+
</tr>
|
68 |
+
</thead>
|
69 |
+
<tbody>
|
70 |
+
<?php foreach ($placements as $_placement_slug => $_placement) :
|
71 |
+
$_placement['type'] = (!empty($_placement['type'])) ? $_placement['type'] : 'default';
|
72 |
+
?>
|
73 |
+
<tr>
|
74 |
+
<td><?php echo $_placement['name']; ?></td>
|
75 |
+
<td><?php echo (isset($_placement['type']) && !empty($placement_types[$_placement['type']]['title'])) ? $placement_types[$_placement['type']]['title'] : __('default', ADVADS_SLUG); ?></td>
|
76 |
+
<th><?php echo $_placement_slug; ?></th>
|
77 |
+
<td class="advads-placements-table-options">
|
78 |
+
<?php do_action('advads-placement-options-before', $_placement_slug, $_placement);
|
79 |
+
$items = Advads_Ad_Placements::items_for_select(); ?>
|
80 |
+
<label for="adsads-placements-item-<?php echo $_placement_slug; ?>"><?php _e('Item', ADVADS_SLUG); ?></label>
|
81 |
+
<select id="adsads-placements-item-<?php echo $_placement_slug; ?>" name="advads[placements][<?php echo $_placement_slug; ?>][item]">
|
82 |
+
<option value=""><?php _e('--empty--', ADVADS_SLUG); ?></option>
|
83 |
+
<?php if (isset($items['ads'])) : ?>
|
84 |
+
<optgroup label="<?php _e('Ads', ADVADS_SLUG); ?>">
|
85 |
+
<?php foreach ($items['ads'] as $_item_id => $_item_title) : ?>
|
86 |
+
<option value="<?php echo $_item_id; ?>" <?php if (isset($_placement['item'])) selected($_item_id, $_placement['item']); ?>><?php echo $_item_title; ?></option>
|
87 |
+
<?php endforeach; ?>
|
88 |
+
</optgroup>
|
89 |
+
<?php endif; ?>
|
90 |
+
<?php if (isset($items['groups'])) : ?>
|
91 |
+
<optgroup label="<?php _e('Ad Groups', ADVADS_SLUG); ?>">
|
92 |
+
<?php foreach ($items['groups'] as $_item_id => $_item_title) : ?>
|
93 |
+
<option value="<?php echo $_item_id; ?>" <?php if (isset($_placement['item'])) selected($_item_id, $_placement['item']); ?>><?php echo $_item_title; ?></option>
|
94 |
+
<?php endforeach; ?>
|
95 |
+
</optgroup>
|
96 |
+
<?php endif; ?>
|
97 |
+
</select><br/>
|
98 |
+
<?php
|
99 |
+
switch ($_placement['type']) :
|
100 |
+
case 'post_content' :
|
101 |
+
?><label for="adsads-placements-options-index-<?php echo $_placement_slug; ?>"><?php _e('Index', ADVADS_SLUG); ?></label>
|
102 |
+
<input type="number" id="adsads-placements-options-index-<?php echo
|
103 |
+
$_placement_slug;
|
104 |
+
?>" name="advads[placements][<?php echo
|
105 |
+
$_placement_slug;
|
106 |
+
?>][options][index]" value="<?php
|
107 |
+
echo (isset($_placement['options']['index'])) ? $_placement['options']['index'] : 1;
|
108 |
+
?>"/>
|
109 |
+
<span class="description"><?php _e('After which paragraph to insert the placement content.', ADVADS_SLUG); ?></span>
|
110 |
+
<?php
|
111 |
+
break;
|
112 |
+
endswitch;
|
113 |
+
do_action('advads-placement-options-after', $_placement_slug, $_placement);
|
114 |
+
?>
|
115 |
+
</td>
|
116 |
+
<td>
|
117 |
+
<input type="checkbox" id="adsads-placements-item-delete-<?php echo $_placement_slug; ?>" name="advads[placements][<?php echo $_placement_slug; ?>][delete]" value="1"/>
|
118 |
+
<label for="adsads-placements-item-delete-<?php echo $_placement_slug; ?>"><?php _e('remove placement', ADVADS_SLUG); ?></label>
|
119 |
+
</td>
|
120 |
+
</tr>
|
121 |
+
<?php endforeach; ?>
|
122 |
+
</tbody>
|
123 |
+
</table>
|
124 |
+
<input type="submit" class="button button-primary" value="<?php _e('Save Placements', ADVADS_SLUG); ?>"/>
|
125 |
+
</form>
|
126 |
+
<?php endif; ?>
|
127 |
</div>
|
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.2
|
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.2.1
|
16 |
* Author: Thomas Maier
|
17 |
* Author URI: http://webgilde.com
|
18 |
* Text Domain: advanced-ads
|
classes/ad.php
CHANGED
@@ -86,14 +86,16 @@ class Advads_Ad {
|
|
86 |
// dynamically add sanitize filters for condition types
|
87 |
$_types = array();
|
88 |
foreach($advanced_ads_ad_conditions as $_condition) {
|
89 |
-
|
|
|
90 |
}
|
91 |
-
|
92 |
-
foreach($_types as $_type) {
|
|
|
93 |
$method_name = 'sanitize_condition_'. $_type;
|
94 |
-
if(method_exists($this, $method_name)) {
|
95 |
add_filter('advanced-ads-sanitize-condition-' . $_type, array($this, $method_name), 10, 1);
|
96 |
-
} elseif(function_exists('advads_sanitize_condition_' . $_type)) {
|
97 |
// check for public function to sanitize this
|
98 |
add_filter('advanced-ads-sanitize-condition-' . $_type, 'advads_sanitize_condition_' . $_type, 10, 1);
|
99 |
|
@@ -136,7 +138,7 @@ class Advads_Ad {
|
|
136 |
// set wrapper conditions
|
137 |
$this->wrapper = apply_filters('advanced-ads-set-wrapper', $this->wrapper, $this);
|
138 |
// add unique wrapper id, if options given
|
139 |
-
if(
|
140 |
// create unique id if not yet given
|
141 |
$this->wrapper['id'] = $this->create_wrapper_id();
|
142 |
}
|
@@ -152,13 +154,14 @@ class Advads_Ad {
|
|
152 |
*/
|
153 |
public function options($field = ''){
|
154 |
// retrieve options, if not given yet
|
155 |
-
if($this->options
|
|
|
156 |
$this->options = get_post_meta($this->id, self::$options_meta_field, true);
|
157 |
}
|
158 |
|
159 |
// return specific option
|
160 |
if($field != '') {
|
161 |
-
if(
|
162 |
return $this->options[$field];
|
163 |
} else { // return all options
|
164 |
if(!empty($this->options))
|
@@ -209,21 +212,20 @@ class Advads_Ad {
|
|
209 |
*/
|
210 |
public function can_display(){
|
211 |
|
212 |
-
$can_display = false;
|
213 |
$options = Advanced_Ads::get_instance()->options();
|
214 |
$see_ads_capability = (!empty($options['hide-for-user-role'])) ? $options['hide-for-user-role'] : 0;
|
215 |
|
216 |
// check if user is logged in and if so if users with his rights can see ads
|
217 |
-
if(is_user_logged_in() && $see_ads_capability && current_user_can($see_ads_capability))
|
|
|
|
|
218 |
|
219 |
-
if(
|
220 |
-
$can_display = true;
|
221 |
-
} else {
|
222 |
return false;
|
223 |
}
|
224 |
|
225 |
// add own conditions to flag output as possible or not
|
226 |
-
$can_display = apply_filters('advanced-ads-can-display',
|
227 |
|
228 |
return $can_display;
|
229 |
}
|
@@ -721,4 +723,4 @@ class Advads_Ad {
|
|
721 |
return 'advads-' . mt_rand();
|
722 |
}
|
723 |
|
724 |
-
}
|
86 |
// dynamically add sanitize filters for condition types
|
87 |
$_types = array();
|
88 |
foreach($advanced_ads_ad_conditions as $_condition) {
|
89 |
+
// add unique
|
90 |
+
$_types[$_condition['type']] = false;
|
91 |
}
|
92 |
+
// iterate types
|
93 |
+
foreach(array_keys($_types) as $_type) {
|
94 |
+
// -TODO might be faster to use __call() method or isset()-test class method array
|
95 |
$method_name = 'sanitize_condition_'. $_type;
|
96 |
+
if (method_exists($this, $method_name)) {
|
97 |
add_filter('advanced-ads-sanitize-condition-' . $_type, array($this, $method_name), 10, 1);
|
98 |
+
} elseif (function_exists('advads_sanitize_condition_' . $_type)) {
|
99 |
// check for public function to sanitize this
|
100 |
add_filter('advanced-ads-sanitize-condition-' . $_type, 'advads_sanitize_condition_' . $_type, 10, 1);
|
101 |
|
138 |
// set wrapper conditions
|
139 |
$this->wrapper = apply_filters('advanced-ads-set-wrapper', $this->wrapper, $this);
|
140 |
// add unique wrapper id, if options given
|
141 |
+
if(is_array($this->wrapper) && $this->wrapper !== array() && !isset($this->wrapper['id'])){
|
142 |
// create unique id if not yet given
|
143 |
$this->wrapper['id'] = $this->create_wrapper_id();
|
144 |
}
|
154 |
*/
|
155 |
public function options($field = ''){
|
156 |
// retrieve options, if not given yet
|
157 |
+
if ($this->options === array()) {
|
158 |
+
// get_post_meta() may return false
|
159 |
$this->options = get_post_meta($this->id, self::$options_meta_field, true);
|
160 |
}
|
161 |
|
162 |
// return specific option
|
163 |
if($field != '') {
|
164 |
+
if(isset($this->options[$field]))
|
165 |
return $this->options[$field];
|
166 |
} else { // return all options
|
167 |
if(!empty($this->options))
|
212 |
*/
|
213 |
public function can_display(){
|
214 |
|
|
|
215 |
$options = Advanced_Ads::get_instance()->options();
|
216 |
$see_ads_capability = (!empty($options['hide-for-user-role'])) ? $options['hide-for-user-role'] : 0;
|
217 |
|
218 |
// check if user is logged in and if so if users with his rights can see ads
|
219 |
+
if (is_user_logged_in() && $see_ads_capability && current_user_can($see_ads_capability)) {
|
220 |
+
return false;
|
221 |
+
}
|
222 |
|
223 |
+
if (!$this->can_display_by_conditions() || !$this->can_display_by_visitor()) {
|
|
|
|
|
224 |
return false;
|
225 |
}
|
226 |
|
227 |
// add own conditions to flag output as possible or not
|
228 |
+
$can_display = apply_filters('advanced-ads-can-display', true, $this);
|
229 |
|
230 |
return $can_display;
|
231 |
}
|
723 |
return 'advads-' . mt_rand();
|
724 |
}
|
725 |
|
726 |
+
}
|
classes/ad_group.php
CHANGED
@@ -178,12 +178,11 @@ class Advads_Ad_Group {
|
|
178 |
$args = array(
|
179 |
'post_type' => $this->post_type,
|
180 |
'post_status' => 'publish',
|
181 |
-
|
|
|
182 |
'orderby' => 'id'
|
183 |
);
|
184 |
$ads = new WP_Query($args);
|
185 |
-
// not sure if reset of postdata is needed here
|
186 |
-
wp_reset_postdata();
|
187 |
|
188 |
if ($ads->have_posts()) {
|
189 |
return $this->ads = $this->add_post_ids($ads->posts);
|
@@ -223,20 +222,21 @@ class Advads_Ad_Group {
|
|
223 |
$weights = $this->get_ad_weights();
|
224 |
|
225 |
// if ads and weights don’t have the same keys, update weights array
|
226 |
-
if(count($weights) != count($ads) || array_diff_key($weights, $ads) != array()
|
227 |
|| array_diff_key($ads, $weights) != array()) {
|
228 |
$this->update_ad_weights();
|
229 |
}
|
230 |
|
231 |
// get a random ad for every ad there is
|
232 |
$shuffled_ads = array();
|
233 |
-
|
234 |
-
|
235 |
-
|
|
|
236 |
// remove chosen ad from weights array
|
237 |
unset($weights[$random_ad_id]);
|
238 |
// put random ad into shuffled array
|
239 |
-
|
240 |
}
|
241 |
|
242 |
return $shuffled_ads;
|
@@ -251,11 +251,13 @@ class Advads_Ad_Group {
|
|
251 |
*/
|
252 |
private function get_random_ad_by_weight(array $ad_weights) {
|
253 |
|
254 |
-
// order array by ad weight; lowest first
|
255 |
-
asort($ad_weights);
|
256 |
-
|
257 |
// use maximum ad weight for ads without this
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
259 |
$rand = mt_rand(1, $max);
|
260 |
|
261 |
foreach ($ad_weights as $key => $value) {
|
@@ -272,14 +274,18 @@ class Advads_Ad_Group {
|
|
272 |
* @since 1.0.0
|
273 |
*/
|
274 |
public function get_ad_weights() {
|
|
|
275 |
if ($this->ad_weights == 0) {
|
276 |
$weights = get_option('advads-ad-weights', array());
|
277 |
-
|
|
|
|
|
|
|
278 |
return $this->ad_weights;
|
279 |
}
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
}
|
284 |
|
285 |
/**
|
@@ -299,7 +305,11 @@ class Advads_Ad_Group {
|
|
299 |
$global_weights[$this->id] = $this->sanitize_ad_weights($weights);
|
300 |
|
301 |
update_option('advads-ad-weights', $global_weights);
|
|
|
|
|
|
|
302 |
}
|
|
|
303 |
/**
|
304 |
* update ad weight based on current ads for the group and ad weight
|
305 |
*
|
178 |
$args = array(
|
179 |
'post_type' => $this->post_type,
|
180 |
'post_status' => 'publish',
|
181 |
+
'taxonomy' => $this->taxonomy,
|
182 |
+
'term' => $this->slug,
|
183 |
'orderby' => 'id'
|
184 |
);
|
185 |
$ads = new WP_Query($args);
|
|
|
|
|
186 |
|
187 |
if ($ads->have_posts()) {
|
188 |
return $this->ads = $this->add_post_ids($ads->posts);
|
222 |
$weights = $this->get_ad_weights();
|
223 |
|
224 |
// if ads and weights don’t have the same keys, update weights array
|
225 |
+
if((count($weights) == 0 && count($ads) > 0) || count($weights) != count($ads) || array_diff_key($weights, $ads) != array()
|
226 |
|| array_diff_key($ads, $weights) != array()) {
|
227 |
$this->update_ad_weights();
|
228 |
}
|
229 |
|
230 |
// get a random ad for every ad there is
|
231 |
$shuffled_ads = array();
|
232 |
+
// order array by ad weight; lowest first
|
233 |
+
asort($weights);
|
234 |
+
// while non-zero weights are set select random next
|
235 |
+
while (null !== $random_ad_id = $this->get_random_ad_by_weight($weights)) {
|
236 |
// remove chosen ad from weights array
|
237 |
unset($weights[$random_ad_id]);
|
238 |
// put random ad into shuffled array
|
239 |
+
$shuffled_ads[] = $ads[$random_ad_id];
|
240 |
}
|
241 |
|
242 |
return $shuffled_ads;
|
251 |
*/
|
252 |
private function get_random_ad_by_weight(array $ad_weights) {
|
253 |
|
|
|
|
|
|
|
254 |
// use maximum ad weight for ads without this
|
255 |
+
// ads might have a weight of zero (0); to avoid mt_rand fail assume that at least 1 is set.
|
256 |
+
$max = array_sum($ad_weights);
|
257 |
+
if ($max < 1) {
|
258 |
+
return ;
|
259 |
+
}
|
260 |
+
|
261 |
$rand = mt_rand(1, $max);
|
262 |
|
263 |
foreach ($ad_weights as $key => $value) {
|
274 |
* @since 1.0.0
|
275 |
*/
|
276 |
public function get_ad_weights() {
|
277 |
+
// load and save ad weights if not yet set
|
278 |
if ($this->ad_weights == 0) {
|
279 |
$weights = get_option('advads-ad-weights', array());
|
280 |
+
if (isset($weights[$this->id])) {
|
281 |
+
return $this->ad_weights = $weights[$this->id];
|
282 |
+
}
|
283 |
+
} elseif(is_array($this->ad_weights)) { // return ad weigths if not empty
|
284 |
return $this->ad_weights;
|
285 |
}
|
286 |
+
|
287 |
+
// return empty array
|
288 |
+
return array();
|
289 |
}
|
290 |
|
291 |
/**
|
305 |
$global_weights[$this->id] = $this->sanitize_ad_weights($weights);
|
306 |
|
307 |
update_option('advads-ad-weights', $global_weights);
|
308 |
+
|
309 |
+
// refresh ad weights after update to avoid conflict
|
310 |
+
$this->ad_weights = $global_weights[$this->id];
|
311 |
}
|
312 |
+
|
313 |
/**
|
314 |
* update ad weight based on current ads for the group and ad weight
|
315 |
*
|
classes/ad_placements.php
CHANGED
@@ -19,6 +19,42 @@
|
|
19 |
*/
|
20 |
class Advads_Ad_Placements {
|
21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
/**
|
23 |
* save a new placement
|
24 |
*
|
@@ -26,7 +62,7 @@ class Advads_Ad_Placements {
|
|
26 |
* @param array $new_placement
|
27 |
* @return mixed true if saved; error message if not
|
28 |
*/
|
29 |
-
static function save_new_placement($new_placement){
|
30 |
// load placements
|
31 |
$placements = Advanced_Ads::get_ad_placements_array();
|
32 |
|
@@ -34,14 +70,22 @@ class Advads_Ad_Placements {
|
|
34 |
$new_placement['slug'] = sanitize_title($new_placement['slug']);
|
35 |
|
36 |
// check if slug already exists
|
37 |
-
if($new_placement['slug'] == '')
|
38 |
-
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
40 |
// escape name
|
41 |
$new_placement['name'] = esc_attr($new_placement['name']);
|
42 |
|
43 |
// add new place to all placements
|
44 |
-
$placements[$new_placement['slug']] = array(
|
|
|
|
|
|
|
45 |
|
46 |
// save array
|
47 |
update_option('advads-ads-placements', $placements);
|
@@ -56,19 +100,26 @@ class Advads_Ad_Placements {
|
|
56 |
* @param array $placement_items
|
57 |
* @return mixed true if saved; error message if not
|
58 |
*/
|
59 |
-
static function save_placements($placement_items){
|
60 |
|
61 |
// load placements
|
62 |
$placements = Advanced_Ads::get_ad_placements_array();
|
63 |
|
64 |
-
foreach($placement_items as $_placement_slug => $_placement){
|
65 |
// remove the placement
|
66 |
-
if(isset($_placement['delete'])) {
|
67 |
unset($placements[$_placement_slug]);
|
68 |
continue;
|
69 |
}
|
70 |
// save item
|
71 |
-
if(isset($_placement['item']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
73 |
|
74 |
// save array
|
@@ -83,18 +134,18 @@ class Advads_Ad_Placements {
|
|
83 |
* @since 1.1
|
84 |
* @return arr $select items for select field
|
85 |
*/
|
86 |
-
static function items_for_select(){
|
87 |
$select = array();
|
88 |
|
89 |
// load all ads
|
90 |
$ads = Advanced_Ads::get_ads();
|
91 |
-
foreach($ads as $_ad){
|
92 |
$select['ads']['ad_' . $_ad->ID] = $_ad->post_title;
|
93 |
}
|
94 |
|
95 |
// load all ad groups
|
96 |
$groups = Advanced_Ads::get_ad_groups();
|
97 |
-
foreach($groups as $_group){
|
98 |
$select['groups']['group_' . $_group->term_id] = $_group->name;
|
99 |
}
|
100 |
|
@@ -107,23 +158,25 @@ class Advads_Ad_Placements {
|
|
107 |
* @since 1.1.0
|
108 |
* @param string $id slug of the display
|
109 |
*/
|
110 |
-
static function output($id = ''){
|
111 |
// get placement data for the slug
|
112 |
-
if($id == '')
|
|
|
113 |
|
114 |
$placements = get_option('advads-ads-placements', array());
|
115 |
|
116 |
-
if(isset($placements[$id]['item'])) {
|
117 |
$_item = explode('_', $placements[$id]['item']);
|
118 |
|
119 |
-
if(isset($_item[1]))
|
120 |
$_item_id = absint($_item[1]);
|
121 |
-
elseif(empty($_item_id))
|
|
|
122 |
|
123 |
// return either ad or group content
|
124 |
-
if($_item[0] == 'ad'){
|
125 |
return get_ad($_item_id);
|
126 |
-
} elseif($_item[0] == 'group'){
|
127 |
return get_ad_group($_item_id);
|
128 |
}
|
129 |
} else {
|
@@ -132,4 +185,41 @@ class Advads_Ad_Placements {
|
|
132 |
|
133 |
return;
|
134 |
}
|
135 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
*/
|
20 |
class Advads_Ad_Placements {
|
21 |
|
22 |
+
/**
|
23 |
+
* get placement types
|
24 |
+
*
|
25 |
+
* @since 1.2.1
|
26 |
+
* @return arr $types array with placement types
|
27 |
+
*/
|
28 |
+
static function get_placement_types() {
|
29 |
+
$types = array(
|
30 |
+
'default' => array(
|
31 |
+
'title' => __('default', ADVADS_SLUG),
|
32 |
+
'description' => __('Manual placement.', ADVADS_SLUG),
|
33 |
+
),
|
34 |
+
'header' => array(
|
35 |
+
'title' => __('header', ADVADS_SLUG),
|
36 |
+
'description' => __('Injected in Header (before closing </head> Tag, often not visible).', ADVADS_SLUG),
|
37 |
+
),
|
38 |
+
'footer' => array(
|
39 |
+
'title' => __('footer', ADVADS_SLUG),
|
40 |
+
'description' => __('Injected in Footer (before closing </body> Tag).', ADVADS_SLUG),
|
41 |
+
),
|
42 |
+
'post_top' => array(
|
43 |
+
'title' => __('before post', ADVADS_SLUG),
|
44 |
+
'description' => __('Injected before the post content.', ADVADS_SLUG),
|
45 |
+
),
|
46 |
+
'post_bottom' => array(
|
47 |
+
'title' => __('after post', ADVADS_SLUG),
|
48 |
+
'description' => __('Injected after the post content.', ADVADS_SLUG),
|
49 |
+
),
|
50 |
+
'post_content' => array(
|
51 |
+
'title' => __('post content', ADVADS_SLUG),
|
52 |
+
'description' => __('Injected into the post content. You can choose the paragraph after which the ad content is displayed.', ADVADS_SLUG),
|
53 |
+
),
|
54 |
+
);
|
55 |
+
return apply_filters('advads-placement-types', $types);
|
56 |
+
}
|
57 |
+
|
58 |
/**
|
59 |
* save a new placement
|
60 |
*
|
62 |
* @param array $new_placement
|
63 |
* @return mixed true if saved; error message if not
|
64 |
*/
|
65 |
+
static function save_new_placement($new_placement) {
|
66 |
// load placements
|
67 |
$placements = Advanced_Ads::get_ad_placements_array();
|
68 |
|
70 |
$new_placement['slug'] = sanitize_title($new_placement['slug']);
|
71 |
|
72 |
// check if slug already exists
|
73 |
+
if ($new_placement['slug'] == '')
|
74 |
+
return __('Slug can’t be empty.', ADVADS_SLUG);
|
75 |
+
if (isset($placements[$new_placement['slug']]))
|
76 |
+
return __('Slug already exists.', ADVADS_SLUG);
|
77 |
+
|
78 |
+
// make sure only allowed types are being saved
|
79 |
+
$placement_types = Advads_Ad_Placements::get_placement_types();
|
80 |
+
$new_placement['type'] = (isset($placement_types[$new_placement['type']])) ? $new_placement['type'] : 'default';
|
81 |
// escape name
|
82 |
$new_placement['name'] = esc_attr($new_placement['name']);
|
83 |
|
84 |
// add new place to all placements
|
85 |
+
$placements[$new_placement['slug']] = array(
|
86 |
+
'type' => $new_placement['type'],
|
87 |
+
'name' => $new_placement['name']
|
88 |
+
);
|
89 |
|
90 |
// save array
|
91 |
update_option('advads-ads-placements', $placements);
|
100 |
* @param array $placement_items
|
101 |
* @return mixed true if saved; error message if not
|
102 |
*/
|
103 |
+
static function save_placements($placement_items) {
|
104 |
|
105 |
// load placements
|
106 |
$placements = Advanced_Ads::get_ad_placements_array();
|
107 |
|
108 |
+
foreach ($placement_items as $_placement_slug => $_placement) {
|
109 |
// remove the placement
|
110 |
+
if (isset($_placement['delete'])) {
|
111 |
unset($placements[$_placement_slug]);
|
112 |
continue;
|
113 |
}
|
114 |
// save item
|
115 |
+
if (isset($_placement['item']))
|
116 |
+
$placements[$_placement_slug]['item'] = $_placement['item'];
|
117 |
+
// save item options
|
118 |
+
if (isset($_placement['options'])){
|
119 |
+
$placements[$_placement_slug]['options'] = $_placement['options'];
|
120 |
+
if(isset($placements[$_placement_slug]['options']['index']))
|
121 |
+
$placements[$_placement_slug]['options']['index'] = absint($placements[$_placement_slug]['options']['index']);
|
122 |
+
}
|
123 |
}
|
124 |
|
125 |
// save array
|
134 |
* @since 1.1
|
135 |
* @return arr $select items for select field
|
136 |
*/
|
137 |
+
static function items_for_select() {
|
138 |
$select = array();
|
139 |
|
140 |
// load all ads
|
141 |
$ads = Advanced_Ads::get_ads();
|
142 |
+
foreach ($ads as $_ad) {
|
143 |
$select['ads']['ad_' . $_ad->ID] = $_ad->post_title;
|
144 |
}
|
145 |
|
146 |
// load all ad groups
|
147 |
$groups = Advanced_Ads::get_ad_groups();
|
148 |
+
foreach ($groups as $_group) {
|
149 |
$select['groups']['group_' . $_group->term_id] = $_group->name;
|
150 |
}
|
151 |
|
158 |
* @since 1.1.0
|
159 |
* @param string $id slug of the display
|
160 |
*/
|
161 |
+
static function output($id = '') {
|
162 |
// get placement data for the slug
|
163 |
+
if ($id == '')
|
164 |
+
return;
|
165 |
|
166 |
$placements = get_option('advads-ads-placements', array());
|
167 |
|
168 |
+
if (isset($placements[$id]['item'])) {
|
169 |
$_item = explode('_', $placements[$id]['item']);
|
170 |
|
171 |
+
if (isset($_item[1]))
|
172 |
$_item_id = absint($_item[1]);
|
173 |
+
elseif (empty($_item_id))
|
174 |
+
return;
|
175 |
|
176 |
// return either ad or group content
|
177 |
+
if ($_item[0] == 'ad') {
|
178 |
return get_ad($_item_id);
|
179 |
+
} elseif ($_item[0] == 'group') {
|
180 |
return get_ad_group($_item_id);
|
181 |
}
|
182 |
} else {
|
185 |
|
186 |
return;
|
187 |
}
|
188 |
+
|
189 |
+
/**
|
190 |
+
* inject ads directly into the content
|
191 |
+
*
|
192 |
+
* @since 1.2.1
|
193 |
+
* @param string $placement_id id of the placement
|
194 |
+
* @param arr $options placement options
|
195 |
+
* @param string $content
|
196 |
+
* @return type
|
197 |
+
* @link inspired by http://www.wpbeginner.com/wp-tutorials/how-to-insert-ads-within-your-post-content-in-wordpress/
|
198 |
+
*/
|
199 |
+
static function inject_in_content($placement_id, $options, $content) {
|
200 |
+
$closing_p = '</p>';
|
201 |
+
$paragraph_id = isset($options['index']) ? $options['index'] : 1;
|
202 |
+
$ad_content = Advads_Ad_Placements::output($placement_id);
|
203 |
+
|
204 |
+
$paragraphs = explode($closing_p, $content);
|
205 |
+
$offset = 0;
|
206 |
+
$running = true;
|
207 |
+
foreach ($paragraphs as $index => $paragraph) {
|
208 |
+
|
209 |
+
// check if current paragraph is empty and if so, increate offset
|
210 |
+
if($running && $index > 0 && trim(str_replace(array('<p>', ' '), '', $paragraph)) == '')
|
211 |
+
$offset++;
|
212 |
+
|
213 |
+
if (trim($paragraph)) {
|
214 |
+
$paragraphs[$index] .= $closing_p;
|
215 |
+
}
|
216 |
+
|
217 |
+
if ($paragraph_id + $offset == $index + 1) {
|
218 |
+
$paragraphs[$index] .= $ad_content;
|
219 |
+
$running = false;
|
220 |
+
}
|
221 |
+
}
|
222 |
+
return implode('', $paragraphs);
|
223 |
+
}
|
224 |
+
|
225 |
+
}
|
classes/widget.php
CHANGED
@@ -22,37 +22,49 @@ class Advads_Widget extends WP_Widget {
|
|
22 |
}
|
23 |
|
24 |
function widget($args, $instance) {
|
|
|
|
|
|
|
25 |
extract($args);
|
26 |
$item_id = empty($instance['item_id']) ? '' : $instance['item_id'];
|
|
|
27 |
echo $before_widget;
|
|
|
|
|
|
|
28 |
echo self::output($item_id);
|
29 |
echo $after_widget;
|
30 |
}
|
31 |
|
32 |
function update($new_instance, $old_instance) {
|
33 |
$instance = $old_instance;
|
|
|
34 |
$instance['item_id'] = $new_instance['item_id'];
|
35 |
return $instance;
|
36 |
}
|
37 |
|
38 |
function form($instance) {
|
39 |
$instance = wp_parse_args((array) $instance, array('title' => '', 'item_id' => ''));
|
40 |
-
$
|
|
|
|
|
|
|
|
|
41 |
|
42 |
$items = self::items_for_select();
|
43 |
?>
|
44 |
<select id="<?php echo $this->get_field_id('item_id'); ?>" name="<?php echo $this->get_field_name('item_id'); ?>">
|
45 |
<option value=""><?php _e('--empty--', ADVADS_SLUG); ?></option>
|
46 |
-
<?php if(isset($items['
|
47 |
-
<optgroup label="<?php _e('
|
48 |
-
<?php foreach($items['
|
49 |
<option value="<?php echo $_item_id; ?>" <?php selected($_item_id, $elementid); ?>><?php echo $_item_title; ?></option>
|
50 |
<?php endforeach; ?>
|
51 |
</optgroup>
|
52 |
<?php endif; ?>
|
53 |
-
<?php if(isset($items['
|
54 |
-
<optgroup label="<?php _e('
|
55 |
-
<?php foreach($items['
|
56 |
<option value="<?php echo $_item_id; ?>" <?php selected($_item_id, $elementid); ?>><?php echo $_item_title; ?></option>
|
57 |
<?php endforeach; ?>
|
58 |
</optgroup>
|
22 |
}
|
23 |
|
24 |
function widget($args, $instance) {
|
25 |
+
/** This filter is documented in wp-includes/default-widgets.php */
|
26 |
+
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
|
27 |
+
|
28 |
extract($args);
|
29 |
$item_id = empty($instance['item_id']) ? '' : $instance['item_id'];
|
30 |
+
$title = empty($instance['title']) ? '' : $instance['title'];
|
31 |
echo $before_widget;
|
32 |
+
if ( ! empty( $title ) ) {
|
33 |
+
echo $before_title . $title . $after_title;
|
34 |
+
}
|
35 |
echo self::output($item_id);
|
36 |
echo $after_widget;
|
37 |
}
|
38 |
|
39 |
function update($new_instance, $old_instance) {
|
40 |
$instance = $old_instance;
|
41 |
+
$instance['title'] = $new_instance['title'];
|
42 |
$instance['item_id'] = $new_instance['item_id'];
|
43 |
return $instance;
|
44 |
}
|
45 |
|
46 |
function form($instance) {
|
47 |
$instance = wp_parse_args((array) $instance, array('title' => '', 'item_id' => ''));
|
48 |
+
$title = strip_tags($instance['title']);
|
49 |
+
$elementid = $instance['item_id'];
|
50 |
+
|
51 |
+
?><p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label>
|
52 |
+
<input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>" /></p><?php
|
53 |
|
54 |
$items = self::items_for_select();
|
55 |
?>
|
56 |
<select id="<?php echo $this->get_field_id('item_id'); ?>" name="<?php echo $this->get_field_name('item_id'); ?>">
|
57 |
<option value=""><?php _e('--empty--', ADVADS_SLUG); ?></option>
|
58 |
+
<?php if(isset($items['groups'])) : ?>
|
59 |
+
<optgroup label="<?php _e('Ad Groups', ADVADS_SLUG); ?>">
|
60 |
+
<?php foreach($items['groups'] as $_item_id => $_item_title) : ?>
|
61 |
<option value="<?php echo $_item_id; ?>" <?php selected($_item_id, $elementid); ?>><?php echo $_item_title; ?></option>
|
62 |
<?php endforeach; ?>
|
63 |
</optgroup>
|
64 |
<?php endif; ?>
|
65 |
+
<?php if(isset($items['ads'])) : ?>
|
66 |
+
<optgroup label="<?php _e('Ads', ADVADS_SLUG); ?>">
|
67 |
+
<?php foreach($items['ads'] as $_item_id => $_item_title) : ?>
|
68 |
<option value="<?php echo $_item_id; ?>" <?php selected($_item_id, $elementid); ?>><?php echo $_item_title; ?></option>
|
69 |
<?php endforeach; ?>
|
70 |
</optgroup>
|
public/assets/js/public.js
CHANGED
@@ -1,42 +1,5 @@
|
|
1 |
jQuery('document').ready(function($) {
|
2 |
|
3 |
"use strict";
|
4 |
-
// check all banners with item conditions on load page load
|
5 |
-
$.each(advads_items.conditions, function(key, value) {
|
6 |
-
// iterate through conditions
|
7 |
-
advads_check_item_conditions(key);
|
8 |
-
});
|
9 |
|
10 |
-
});
|
11 |
-
|
12 |
-
/**
|
13 |
-
* check item conditions and display the ad if all conditions are true
|
14 |
-
*
|
15 |
-
* @param {string} id id of the ad, without #
|
16 |
-
* @returns {undefined}
|
17 |
-
*/
|
18 |
-
function advads_check_item_conditions(id) {
|
19 |
-
var item = jQuery('#' + id);
|
20 |
-
if (item.length == 0)
|
21 |
-
return;
|
22 |
-
|
23 |
-
var display = true;
|
24 |
-
jQuery.each(advads_items.conditions[id], function(method, flag) {
|
25 |
-
if (flag === false) {
|
26 |
-
// display the banner
|
27 |
-
display = false;
|
28 |
-
}
|
29 |
-
});
|
30 |
-
if (display) {
|
31 |
-
var ad = jQuery('#' + id);
|
32 |
-
// iterate through display callbacks
|
33 |
-
jQuery.each(advads_items.display_callbacks, function(adid, callbacks){
|
34 |
-
// iterate through all callback function and call them
|
35 |
-
jQuery.each(callbacks, function(key, funcname){
|
36 |
-
var callback = window[funcname];
|
37 |
-
callback(adid);
|
38 |
-
})
|
39 |
-
})
|
40 |
-
ad.show();
|
41 |
-
}
|
42 |
-
}
|
1 |
jQuery('document').ready(function($) {
|
2 |
|
3 |
"use strict";
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public/class-advanced-ads.php
CHANGED
@@ -25,7 +25,7 @@ class Advanced_Ads {
|
|
25 |
* @var string
|
26 |
*/
|
27 |
|
28 |
-
const VERSION = '1.2';
|
29 |
|
30 |
/**
|
31 |
* post type slug
|
@@ -116,9 +116,6 @@ class Advanced_Ads {
|
|
116 |
// setup default ad types
|
117 |
add_filter('advanced-ads-ad-types', array($this, 'setup_default_ad_types'));
|
118 |
|
119 |
-
// frontend output
|
120 |
-
add_action('wp_head', array($this, 'header_output'));
|
121 |
-
|
122 |
// register hooks and filters for auto ad injection
|
123 |
add_action('wp_head', array($this, 'inject_header'), 20);
|
124 |
add_action('wp_footer', array($this, 'inject_footer'), 20);
|
@@ -315,7 +312,7 @@ class Advanced_Ads {
|
|
315 |
* @since 1.0.0
|
316 |
*/
|
317 |
public function enqueue_scripts() {
|
318 |
-
wp_enqueue_script($this->plugin_slug . '-plugin-script', plugins_url('assets/js/public.js', __FILE__), array('jquery'), self::VERSION);
|
319 |
}
|
320 |
|
321 |
/**
|
@@ -506,7 +503,7 @@ class Advanced_Ads {
|
|
506 |
'show_in_nav_menus' => false,
|
507 |
'show_tagcloud' => false,
|
508 |
'show_admin_column' => false,
|
509 |
-
'query_var' =>
|
510 |
'rewrite' => false,
|
511 |
);
|
512 |
|
@@ -616,6 +613,14 @@ class Advanced_Ads {
|
|
616 |
* @since 1.1.0
|
617 |
*/
|
618 |
public function inject_header(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
619 |
// get information about injected ads
|
620 |
$injections = get_option('advads-ads-injections', array());
|
621 |
if(isset($injections['header']) && is_array($injections['header'])){
|
@@ -640,6 +645,14 @@ class Advanced_Ads {
|
|
640 |
* @since 1.1.0
|
641 |
*/
|
642 |
public function inject_footer(){
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
643 |
// get information about injected ads
|
644 |
$injections = get_option('advads-ads-injections', array());
|
645 |
if(isset($injections['footer']) && is_array($injections['footer'])){
|
@@ -658,14 +671,6 @@ class Advanced_Ads {
|
|
658 |
}
|
659 |
}
|
660 |
|
661 |
-
/**
|
662 |
-
* content output in the header
|
663 |
-
*/
|
664 |
-
public function header_output(){
|
665 |
-
// inject js array for banner conditions
|
666 |
-
echo '<script>advads_items = { conditions: {}, display_callbacks: {}, hide_callbacks: {}};</script>';
|
667 |
-
}
|
668 |
-
|
669 |
/**
|
670 |
* injected ad into content (before and after)
|
671 |
* displays ALL ads
|
@@ -677,6 +682,20 @@ class Advanced_Ads {
|
|
677 |
// run only on single pages
|
678 |
if(!is_singular(array('post', 'page'))) return $content;
|
679 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
680 |
// get information about injected ads
|
681 |
$injections = get_option('advads-ads-injections', array());
|
682 |
|
25 |
* @var string
|
26 |
*/
|
27 |
|
28 |
+
const VERSION = '1.2.1';
|
29 |
|
30 |
/**
|
31 |
* post type slug
|
116 |
// setup default ad types
|
117 |
add_filter('advanced-ads-ad-types', array($this, 'setup_default_ad_types'));
|
118 |
|
|
|
|
|
|
|
119 |
// register hooks and filters for auto ad injection
|
120 |
add_action('wp_head', array($this, 'inject_header'), 20);
|
121 |
add_action('wp_footer', array($this, 'inject_footer'), 20);
|
312 |
* @since 1.0.0
|
313 |
*/
|
314 |
public function enqueue_scripts() {
|
315 |
+
// wp_enqueue_script($this->plugin_slug . '-plugin-script', plugins_url('assets/js/public.js', __FILE__), array('jquery'), self::VERSION);
|
316 |
}
|
317 |
|
318 |
/**
|
503 |
'show_in_nav_menus' => false,
|
504 |
'show_tagcloud' => false,
|
505 |
'show_admin_column' => false,
|
506 |
+
'query_var' => false,
|
507 |
'rewrite' => false,
|
508 |
);
|
509 |
|
613 |
* @since 1.1.0
|
614 |
*/
|
615 |
public function inject_header(){
|
616 |
+
$placements = get_option('advads-ads-placements', array());
|
617 |
+
foreach($placements as $_placement_id => $_placement){
|
618 |
+
if(isset($_placement['type']) && $_placement['type'] == 'header'){
|
619 |
+
echo Advads_Ad_Placements::output($_placement_id);
|
620 |
+
}
|
621 |
+
}
|
622 |
+
|
623 |
+
/* FROM HERE, THE CODE IS DEPRECATED – MOVE AUTO INJECTED ADS TO PLACEMENTS */
|
624 |
// get information about injected ads
|
625 |
$injections = get_option('advads-ads-injections', array());
|
626 |
if(isset($injections['header']) && is_array($injections['header'])){
|
645 |
* @since 1.1.0
|
646 |
*/
|
647 |
public function inject_footer(){
|
648 |
+
$placements = get_option('advads-ads-placements', array());
|
649 |
+
foreach($placements as $_placement_id => $_placement){
|
650 |
+
if(isset($_placement['type']) && $_placement['type'] == 'footer'){
|
651 |
+
echo Advads_Ad_Placements::output($_placement_id);
|
652 |
+
}
|
653 |
+
}
|
654 |
+
|
655 |
+
/* FROM HERE, THE CODE IS DEPRECATED – MOVE AUTO INJECTED ADS TO PLACEMENTS */
|
656 |
// get information about injected ads
|
657 |
$injections = get_option('advads-ads-injections', array());
|
658 |
if(isset($injections['footer']) && is_array($injections['footer'])){
|
671 |
}
|
672 |
}
|
673 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
674 |
/**
|
675 |
* injected ad into content (before and after)
|
676 |
* displays ALL ads
|
682 |
// run only on single pages
|
683 |
if(!is_singular(array('post', 'page'))) return $content;
|
684 |
|
685 |
+
$placements = get_option('advads-ads-placements', array());
|
686 |
+
foreach($placements as $_placement_id => $_placement){
|
687 |
+
if(isset($_placement['type']) && $_placement['type'] == 'post_top'){
|
688 |
+
$content = Advads_Ad_Placements::output($_placement_id) . $content;
|
689 |
+
}
|
690 |
+
if(isset($_placement['type']) && $_placement['type'] == 'post_bottom'){
|
691 |
+
$content .= Advads_Ad_Placements::output($_placement_id);
|
692 |
+
}
|
693 |
+
if(isset($_placement['type']) && $_placement['type'] == 'post_content'){
|
694 |
+
$content = Advads_Ad_Placements::inject_in_content($_placement_id, $_placement['options'], $content);
|
695 |
+
}
|
696 |
+
}
|
697 |
+
|
698 |
+
/* FROM HERE, THE CODE IS DEPRECATED – MOVE AUTO INJECTED ADS TO PLACEMENTS */
|
699 |
// get information about injected ads
|
700 |
$injections = get_option('advads-ads-injections', array());
|
701 |
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: webzunft
|
|
3 |
Tags: ads, ad, adsense, display, banner, advertisements, adverts, advert, monetization
|
4 |
Requires at least: 3.5
|
5 |
Tested up to: 4.0.0
|
6 |
-
Stable tag: 1.2
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -22,7 +22,7 @@ Learn more on the [plugin homepage](http://wpadvancedads.com).
|
|
22 |
|
23 |
= display ads =
|
24 |
|
25 |
-
* auto inject ads into header, footer and posts
|
26 |
* display ad in template files (with functions)
|
27 |
* display ad in post content (with shortcodes)
|
28 |
* widget to display ads in widget areas (sidebars)
|
@@ -119,6 +119,22 @@ There is no revenue share. Advanced Ads doesn’t alter your ad codes in a way t
|
|
119 |
|
120 |
== Changelog ==
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
= 1.2 =
|
123 |
|
124 |
* added widget for ads or ad groups
|
3 |
Tags: ads, ad, adsense, display, banner, advertisements, adverts, advert, monetization
|
4 |
Requires at least: 3.5
|
5 |
Tested up to: 4.0.0
|
6 |
+
Stable tag: 1.2.1
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
22 |
|
23 |
= display ads =
|
24 |
|
25 |
+
* auto inject ads into header, footer and posts content
|
26 |
* display ad in template files (with functions)
|
27 |
* display ad in post content (with shortcodes)
|
28 |
* widget to display ads in widget areas (sidebars)
|
119 |
|
120 |
== Changelog ==
|
121 |
|
122 |
+
= 1.2.1 ==
|
123 |
+
|
124 |
+
major changes:
|
125 |
+
|
126 |
+
* moved auto injections from ads to placements [PLEASE MOVE YOUR INJECTIONS THERE]
|
127 |
+
* added post content injections
|
128 |
+
* reading suggestion: [My test of AdSense Responsive Ads](http://webgilde.com/en/adsense-responsive-ad/)
|
129 |
+
|
130 |
+
other fixes:
|
131 |
+
|
132 |
+
* fix bugs with ad weights throwing issues when not set
|
133 |
+
* removed public ad groups query
|
134 |
+
* updated arrays displayed on debug page
|
135 |
+
* ad groups are now displayed before ads in placements and ad widget
|
136 |
+
* added title to widget
|
137 |
+
|
138 |
= 1.2 =
|
139 |
|
140 |
* added widget for ads or ad groups
|