Insert Post Ads - Version 1.0.4

Version Description

  • Added: New options to position advert before content or after content
  • Added: WordPress 4.0 compatibility
Download this release

Release Info

Developer n7studios
Plugin Icon 128x128 Insert Post Ads
Version 1.0.4
Comparing to
See all releases

Code changes from version 1.0.3 to 1.0.4

Files changed (2) hide show
  1. insert-post-ads.php +24 -13
  2. readme.txt +5 -1
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.3
6
  * Author: WPBeginner
7
  * Author URI: http://www.wpbeginner.com/
8
  * Description: Allows you to insert ads after paragraphs of your post content
@@ -27,12 +27,6 @@
27
 
28
  /**
29
  * Insert Post Ads Class
30
- *
31
- * @package WPBeginner
32
- * @subpackage Insert Post Ads
33
- * @author Tim Carr
34
- * @version 1.0.3
35
- * @copyright WPBeginner
36
  */
37
  class InsertPostAds {
38
  /**
@@ -44,7 +38,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.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
 
@@ -174,10 +168,8 @@ class InsertPostAds {
174
  function displayMetaBox($post) {
175
  // Get meta
176
  $adCode = get_post_meta($post->ID, '_ad_code', true);
 
177
  $paragraphNumber = get_post_meta($post->ID, '_paragraph_number', true);
178
- if (empty($paragraphNumber)) {
179
- $paragraphNumber = 1;
180
- }
181
 
182
  // Nonce field
183
  wp_nonce_field($this->plugin->name, $this->plugin->name.'_nonce');
@@ -186,7 +178,12 @@ class InsertPostAds {
186
  <textarea name="ad_code" id="ad_code" style="width: 100%; height: 100px; font-family: Courier; font-size: 12px;"><?php echo $adCode; ?></textarea>
187
  </p>
188
  <p>
189
- <label for="paragraph_number"><?php _e('Display the advert after which paragraph:', $this->plugin->name); ?></label>
 
 
 
 
 
190
  <input type="number" name="paragraph_number" value="<?php echo $paragraphNumber; ?>" min="1" max="999" step="1" id="paragraph_number" />
191
  </p>
192
  <?php
@@ -245,6 +242,9 @@ class InsertPostAds {
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
  }
@@ -330,9 +330,20 @@ class InsertPostAds {
330
 
331
  $adID = get_the_ID();
332
  $adCode = get_post_meta($adID, '_ad_code', true);
 
333
  $paragraphNumber = get_post_meta($adID, '_paragraph_number', true);
334
 
335
- $content = $this->insertAdAfterParagraph($adCode, $paragraphNumber , $content);
 
 
 
 
 
 
 
 
 
 
336
  }
337
  }
338
 
2
  /**
3
  * Plugin Name: Insert Post Ads
4
  * Plugin URI: http://www.wpbeginner.com/
5
+ * Version: 1.0.4
6
  * Author: WPBeginner
7
  * Author URI: http://www.wpbeginner.com/
8
  * Description: Allows you to insert ads after paragraphs of your post content
27
 
28
  /**
29
  * Insert Post Ads Class
 
 
 
 
 
 
30
  */
31
  class InsertPostAds {
32
  /**
38
  $this->plugin->name = 'insert-post-ads'; // Plugin Folder
39
  $this->plugin->displayName = 'Post Adverts'; // Plugin Name
40
  $this->plugin->posttype = 'insertpostads';
41
+ $this->plugin->version = '1.0.4';
42
  $this->plugin->folder = WP_PLUGIN_DIR.'/'.$this->plugin->name; // Full Path to Plugin Folder
43
  $this->plugin->url = WP_PLUGIN_URL.'/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__));
44
 
168
  function displayMetaBox($post) {
169
  // Get meta
170
  $adCode = get_post_meta($post->ID, '_ad_code', true);
171
+ $adPosition = get_post_meta($post->ID, '_ad_position', true);
172
  $paragraphNumber = get_post_meta($post->ID, '_paragraph_number', true);
 
 
 
173
 
174
  // Nonce field
175
  wp_nonce_field($this->plugin->name, $this->plugin->name.'_nonce');
178
  <textarea name="ad_code" id="ad_code" style="width: 100%; height: 100px; font-family: Courier; font-size: 12px;"><?php echo $adCode; ?></textarea>
179
  </p>
180
  <p>
181
+ <label for="ad_position"><?php _e('Display the advert:', $this->plugin->name); ?></label>
182
+ <select name="ad_position" size="1">
183
+ <option value="top"<?php echo (($adPosition == 'top') ? ' selected' : ''); ?>><?php _e('Before Content', $this->plugin->name); ?></option>
184
+ <option value=""<?php echo (($adPosition == '') ? ' selected' : ''); ?>><?php _e('After Paragraph Number', $this->plugin->name); ?></option>
185
+ <option value="bottom"<?php echo (($adPosition == 'bottom') ? ' selected' : ''); ?>><?php _e('After Content', $this->plugin->name); ?></option>
186
+ </select>
187
  <input type="number" name="paragraph_number" value="<?php echo $paragraphNumber; ?>" min="1" max="999" step="1" id="paragraph_number" />
188
  </p>
189
  <?php
242
  if (isset($_POST['ad_code'])) {
243
  update_post_meta($post_id, '_ad_code', $_POST['ad_code']);
244
  }
245
+ if (isset($_POST['ad_position'])) {
246
+ update_post_meta($post_id, '_ad_position', $_POST['ad_position']);
247
+ }
248
  if (isset($_POST['paragraph_number'])) {
249
  update_post_meta($post_id, '_paragraph_number', $_POST['paragraph_number']);
250
  }
330
 
331
  $adID = get_the_ID();
332
  $adCode = get_post_meta($adID, '_ad_code', true);
333
+ $adPosition = get_post_meta($adID, '_ad_position', true);
334
  $paragraphNumber = get_post_meta($adID, '_paragraph_number', true);
335
 
336
+ switch ($adPosition) {
337
+ case 'top':
338
+ $content = $adCode.$content;
339
+ break;
340
+ case 'bottom':
341
+ $content = $content.$adCode;
342
+ break;
343
+ default:
344
+ $content = $this->insertAdAfterParagraph($adCode, $paragraphNumber , $content);
345
+ break;
346
+ }
347
  }
348
  }
349
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: WPbeginner, smub, iamdpegg, n7studios
3
  Donate link:http://www.wpbeginner.com/wpbeginner-needs-your-help/
4
  Tags: ads, adsense, google adsense, insert ads in post, wordpress ads plugin, advertising plugin, banners plugin, post ads, insert post ads
5
  Requires at least: 3.6
6
- Tested up to: 3.9.1
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -46,6 +46,10 @@ Lastly, if you like this plugin then follow WPBeginner on <a href="http://twitte
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
3
  Donate link:http://www.wpbeginner.com/wpbeginner-needs-your-help/
4
  Tags: ads, adsense, google adsense, insert ads in post, wordpress ads plugin, advertising plugin, banners plugin, post ads, insert post ads
5
  Requires at least: 3.6
6
+ Tested up to: 4.0
7
  Stable tag: trunk
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
46
 
47
  == Changelog ==
48
 
49
+ = 1.0.4 =
50
+ * Added: New options to position advert before content or after content
51
+ * Added: WordPress 4.0 compatibility
52
+
53
  = 1.0.3 =
54
  * Added: Option to exclude inline CSS on adverts
55
  * Added: .insert-post-ads class on advert containers