Version Description
- Added: Option to exclude inline CSS on adverts
- Added: .insert-post-ads class on advert containers
- Added: Post/Page/CPT specific advert exclusion option
Download this release
Release Info
Developer | n7studios |
Plugin | Insert Post Ads |
Version | 1.0.3 |
Comparing to | |
See all releases |
Code changes from version 1.0.2 to 1.0.3
- insert-post-ads.php +61 -12
- readme.txt +5 -0
- views/settings.php +29 -11
insert-post-ads.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* Plugin Name: Insert Post Ads
|
4 |
* Plugin URI: http://www.wpbeginner.com/
|
5 |
-
* Version: 1.0.
|
6 |
* Author: WPBeginner
|
7 |
* Author URI: http://www.wpbeginner.com/
|
8 |
* Description: Allows you to insert ads after paragraphs of your post content
|
@@ -31,7 +31,7 @@
|
|
31 |
* @package WPBeginner
|
32 |
* @subpackage Insert Post Ads
|
33 |
* @author Tim Carr
|
34 |
-
* @version 1.0.
|
35 |
* @copyright WPBeginner
|
36 |
*/
|
37 |
class InsertPostAds {
|
@@ -44,7 +44,7 @@ class InsertPostAds {
|
|
44 |
$this->plugin->name = 'insert-post-ads'; // Plugin Folder
|
45 |
$this->plugin->displayName = 'Post Adverts'; // Plugin Name
|
46 |
$this->plugin->posttype = 'insertpostads';
|
47 |
-
$this->plugin->version = '1.0.
|
48 |
$this->plugin->folder = WP_PLUGIN_DIR.'/'.$this->plugin->name; // Full Path to Plugin Folder
|
49 |
$this->plugin->url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
|
50 |
|
@@ -118,6 +118,24 @@ class InsertPostAds {
|
|
118 |
function adminPanelsAndMetaBoxes() {
|
119 |
add_submenu_page('edit.php?post_type='.$this->plugin->posttype, __('Settings', $this->plugin->name), __('Settings', $this->plugin->name), 'manage_options', $this->plugin->name, array(&$this, 'adminPanel'));
|
120 |
add_meta_box('ipa_meta', __('Advert Code', $this->plugin->name), array( &$this, 'displayMetaBox'), $this->plugin->posttype, 'normal', 'high');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
121 |
}
|
122 |
|
123 |
/**
|
@@ -174,6 +192,28 @@ class InsertPostAds {
|
|
174 |
<?php
|
175 |
}
|
176 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
/**
|
178 |
* Saves the meta box field data
|
179 |
*
|
@@ -190,19 +230,24 @@ class InsertPostAds {
|
|
190 |
return $post_id;
|
191 |
}
|
192 |
|
193 |
-
// Check this is the Ad Custom Post Type
|
194 |
-
if ($_POST['post_type'] != $this->plugin->posttype) {
|
195 |
-
return $post_id;
|
196 |
-
}
|
197 |
-
|
198 |
// Check the logged in user has permission to edit this post
|
199 |
if (!current_user_can('edit_post', $post_id)) {
|
200 |
return $post_id;
|
201 |
}
|
202 |
|
203 |
// OK to save meta data
|
204 |
-
|
205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
206 |
}
|
207 |
|
208 |
/**
|
@@ -256,7 +301,11 @@ class InsertPostAds {
|
|
256 |
// Check if we are on a singular post type that's enabled
|
257 |
foreach ($this->settings as $postType=>$enabled) {
|
258 |
if (is_singular($postType)) {
|
259 |
-
|
|
|
|
|
|
|
|
|
260 |
}
|
261 |
}
|
262 |
|
@@ -313,7 +362,7 @@ class InsertPostAds {
|
|
313 |
|
314 |
// + 1 allows for considering the first paragraph as #1, not #0.
|
315 |
if ( $paragraph_id == $index + 1 ) {
|
316 |
-
$paragraphs[$index] .= '<div style="clear:both;float:left;width:100%;margin:0 0 20px 0;">'. $insertion .'</div>';
|
317 |
}
|
318 |
}
|
319 |
return implode( '', $paragraphs );
|
2 |
/**
|
3 |
* Plugin Name: Insert Post Ads
|
4 |
* Plugin URI: http://www.wpbeginner.com/
|
5 |
+
* Version: 1.0.3
|
6 |
* Author: WPBeginner
|
7 |
* Author URI: http://www.wpbeginner.com/
|
8 |
* Description: Allows you to insert ads after paragraphs of your post content
|
31 |
* @package WPBeginner
|
32 |
* @subpackage Insert Post Ads
|
33 |
* @author Tim Carr
|
34 |
+
* @version 1.0.3
|
35 |
* @copyright WPBeginner
|
36 |
*/
|
37 |
class InsertPostAds {
|
44 |
$this->plugin->name = 'insert-post-ads'; // Plugin Folder
|
45 |
$this->plugin->displayName = 'Post Adverts'; // Plugin Name
|
46 |
$this->plugin->posttype = 'insertpostads';
|
47 |
+
$this->plugin->version = '1.0.3';
|
48 |
$this->plugin->folder = WP_PLUGIN_DIR.'/'.$this->plugin->name; // Full Path to Plugin Folder
|
49 |
$this->plugin->url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
|
50 |
|
118 |
function adminPanelsAndMetaBoxes() {
|
119 |
add_submenu_page('edit.php?post_type='.$this->plugin->posttype, __('Settings', $this->plugin->name), __('Settings', $this->plugin->name), 'manage_options', $this->plugin->name, array(&$this, 'adminPanel'));
|
120 |
add_meta_box('ipa_meta', __('Advert Code', $this->plugin->name), array( &$this, 'displayMetaBox'), $this->plugin->posttype, 'normal', 'high');
|
121 |
+
$postTypes = get_post_types(array(
|
122 |
+
'public' => true,
|
123 |
+
), 'objects');
|
124 |
+
if ($postTypes) {
|
125 |
+
foreach ($postTypes as $postType) {
|
126 |
+
// Skip attachments
|
127 |
+
if ($postType->name == 'attachment') {
|
128 |
+
continue;
|
129 |
+
}
|
130 |
+
|
131 |
+
// Skip our CPT
|
132 |
+
if ($postType->name == $this->plugin->posttype) {
|
133 |
+
continue;
|
134 |
+
}
|
135 |
+
add_meta_box('ipa_meta', __($this->plugin->displayName, $this->plugin->name), array( &$this, 'displayOptionsMetaBox'), $postType->name, 'normal', 'high');
|
136 |
+
}
|
137 |
+
}
|
138 |
+
|
139 |
}
|
140 |
|
141 |
/**
|
192 |
<?php
|
193 |
}
|
194 |
|
195 |
+
/**
|
196 |
+
* Displays the meta box on Pages, Posts and CPTs
|
197 |
+
*
|
198 |
+
* @param object $post Post
|
199 |
+
*/
|
200 |
+
function displayOptionsMetaBox($post) {
|
201 |
+
// Get meta
|
202 |
+
$disable = get_post_meta($post->ID, '_ipa_disable_ads', true);
|
203 |
+
|
204 |
+
// Nonce field
|
205 |
+
wp_nonce_field($this->plugin->name, $this->plugin->name.'_nonce');
|
206 |
+
?>
|
207 |
+
<p>
|
208 |
+
<label for="ipa_disable_ads"><?php _e('Disable Adverts', $this->plugin->name); ?></label>
|
209 |
+
<input type="checkbox" name="ipa_disable_ads" id="ipa_disable_ads" value="1"<?php echo ($disable ? ' checked' : ''); ?> />
|
210 |
+
</p>
|
211 |
+
<p class="description">
|
212 |
+
<?php _e('Check this option if you wish to disable all Post Ads from displaying on this content.', $this->plugin->name); ?>
|
213 |
+
</p>
|
214 |
+
<?php
|
215 |
+
}
|
216 |
+
|
217 |
/**
|
218 |
* Saves the meta box field data
|
219 |
*
|
230 |
return $post_id;
|
231 |
}
|
232 |
|
|
|
|
|
|
|
|
|
|
|
233 |
// Check the logged in user has permission to edit this post
|
234 |
if (!current_user_can('edit_post', $post_id)) {
|
235 |
return $post_id;
|
236 |
}
|
237 |
|
238 |
// OK to save meta data
|
239 |
+
if (isset($_POST['ipa_disable_ads'])) {
|
240 |
+
update_post_meta($post_id, '_ipa_disable_ads', $_POST['ipa_disable_ads']);
|
241 |
+
} else {
|
242 |
+
delete_post_meta($post_id, '_ipa_disable_ads');
|
243 |
+
}
|
244 |
+
|
245 |
+
if (isset($_POST['ad_code'])) {
|
246 |
+
update_post_meta($post_id, '_ad_code', $_POST['ad_code']);
|
247 |
+
}
|
248 |
+
if (isset($_POST['paragraph_number'])) {
|
249 |
+
update_post_meta($post_id, '_paragraph_number', $_POST['paragraph_number']);
|
250 |
+
}
|
251 |
}
|
252 |
|
253 |
/**
|
301 |
// Check if we are on a singular post type that's enabled
|
302 |
foreach ($this->settings as $postType=>$enabled) {
|
303 |
if (is_singular($postType)) {
|
304 |
+
// Check the post hasn't disabled adverts
|
305 |
+
$disable = get_post_meta($post->ID, '_ipa_disable_ads', true);
|
306 |
+
if (!$disable) {
|
307 |
+
return $this->insertAds($content);
|
308 |
+
}
|
309 |
}
|
310 |
}
|
311 |
|
362 |
|
363 |
// + 1 allows for considering the first paragraph as #1, not #0.
|
364 |
if ( $paragraph_id == $index + 1 ) {
|
365 |
+
$paragraphs[$index] .= '<div class="'.$this->plugin->name.'"'.(isset($this->settings['css']) ? '' : ' style="clear:both;float:left;width:100%;margin:0 0 20px 0;"').'>'. $insertion .'</div>';
|
366 |
}
|
367 |
}
|
368 |
return implode( '', $paragraphs );
|
readme.txt
CHANGED
@@ -46,6 +46,11 @@ Lastly, if you like this plugin then follow WPBeginner on <a href="http://twitte
|
|
46 |
|
47 |
== Changelog ==
|
48 |
|
|
|
|
|
|
|
|
|
|
|
49 |
= 1.0.2 =
|
50 |
* Removed: readme.txt tags
|
51 |
* Fix: Content not outputting when no Post Adverts defined
|
46 |
|
47 |
== Changelog ==
|
48 |
|
49 |
+
= 1.0.3 =
|
50 |
+
* Added: Option to exclude inline CSS on adverts
|
51 |
+
* Added: .insert-post-ads class on advert containers
|
52 |
+
* Added: Post/Page/CPT specific advert exclusion option
|
53 |
+
|
54 |
= 1.0.2 =
|
55 |
* Removed: readme.txt tags
|
56 |
* Fix: Content not outputting when no Post Adverts defined
|
views/settings.php
CHANGED
@@ -19,11 +19,11 @@
|
|
19 |
<!-- Content -->
|
20 |
<div id="post-body-content">
|
21 |
<div id="normal-sortables" class="meta-box-sortables ui-sortable">
|
22 |
-
<
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
<
|
27 |
<p>
|
28 |
<?php
|
29 |
$postTypes = get_post_types(array(
|
@@ -42,15 +42,33 @@
|
|
42 |
}
|
43 |
}
|
44 |
?>
|
45 |
-
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
<p>
|
48 |
-
<input name="submit" type="submit" name="Submit" class="button button-primary" value="Save
|
49 |
</p>
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
|
55 |
<div id="wpbeginner" class="postbox">
|
56 |
<h3 class="hndle"><?php _e('Latest from WPBeginner', $this->plugin->name); ?></h3>
|
19 |
<!-- Content -->
|
20 |
<div id="post-body-content">
|
21 |
<div id="normal-sortables" class="meta-box-sortables ui-sortable">
|
22 |
+
<form action="edit.php?post_type=<?php echo $this->plugin->posttype; ?>&page=<?php echo $this->plugin->name; ?>" method="post">
|
23 |
+
<div class="postbox">
|
24 |
+
<h3 class="hndle"><?php _e('Where do you want ads to display?', $this->plugin->name); ?></h3>
|
25 |
+
|
26 |
+
<div class="inside">
|
27 |
<p>
|
28 |
<?php
|
29 |
$postTypes = get_post_types(array(
|
42 |
}
|
43 |
}
|
44 |
?>
|
45 |
+
</p>
|
46 |
+
<p>
|
47 |
+
<input name="submit" type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Settings', $this->plugin->name); ?>" />
|
48 |
+
</p>
|
49 |
+
</div>
|
50 |
+
</div>
|
51 |
+
<!-- /postbox -->
|
52 |
+
|
53 |
+
<div class="postbox">
|
54 |
+
<h3 class="hndle"><?php _e('Display Styling', $this->plugin->name); ?></h3>
|
55 |
+
|
56 |
+
<div class="inside">
|
57 |
+
<p>
|
58 |
+
<label for="css"><?php _e('Exclude CSS', $this->plugin->name) ;?></label>
|
59 |
+
<input type="checkbox" name="<?php echo $this->plugin->name; ?>[css]" value="1" id="css" <?php echo (isset($this->settings['css']) ? ' checked' : ''); ?>/>
|
60 |
+
</p>
|
61 |
+
<p class="description">
|
62 |
+
<?php _e('By default, Post Ads are wrapped in a container that has some CSS to aid layout. Developers may wish to use their own CSS, and should check this Exclude CSS option.', $this->plugin->name); ?>
|
63 |
+
</p>
|
64 |
|
65 |
<p>
|
66 |
+
<input name="submit" type="submit" name="Submit" class="button button-primary" value="<?php _e('Save Settings', $this->plugin->name); ?>" />
|
67 |
</p>
|
68 |
+
</div>
|
69 |
+
</div>
|
70 |
+
<!-- /postbox -->
|
71 |
+
</form>
|
72 |
|
73 |
<div id="wpbeginner" class="postbox">
|
74 |
<h3 class="hndle"><?php _e('Latest from WPBeginner', $this->plugin->name); ?></h3>
|