Insert Post Ads - Version 1.1.2

Version Description

  • Change the insert 'ad after para# N' container to a random classname to prevent adblockers from blocking it
  • In the ad creation page, hide the paragraph# input field when the position in the dropdown are top or bottom
  • Add a new filter 'insert_post_ads_enabled' - that can be used to temporarily stop ads from printing, say for AMP pages
Download this release

Release Info

Developer insertpostads
Plugin Icon 128x128 Insert Post Ads
Version 1.1.2
Comparing to
See all releases

Code changes from version 1.1.1 to 1.1.2

Files changed (2) hide show
  1. insert-post-ads.php +43 -9
  2. readme.txt +14 -30
insert-post-ads.php CHANGED
@@ -1,15 +1,15 @@
1
  <?php
2
  /**
3
  * Plugin Name: Insert Post Ads
4
- * Plugin URI: http://www.wpbeginner.com/
5
- * Version: 1.1.1
6
- * Author: WPBeginner
7
- * Author URI: http://www.wpbeginner.com/
8
  * Description: Allows you to insert ads after paragraphs of your post content
9
  * License: GPL2
10
  */
11
 
12
- /* Copyright 2014 WPBeginner
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License, version 2, as
@@ -226,12 +226,22 @@ class InsertPostAds {
226
  </p>
227
  <p>
228
  <label for="ad_position"><?php _e( 'Display the advert:', $this->plugin->name ); ?></label>
229
- <select name="ad_position" size="1">
230
  <option value="top"<?php echo ( ( $adPosition == 'top' ) ? ' selected' : '' ); ?>><?php _e( 'Before Content', $this->plugin->name ); ?></option>
231
  <option value=""<?php echo ( ( $adPosition == '' ) ? ' selected' : '' ); ?>><?php _e( 'After Paragraph Number', $this->plugin->name ); ?></option>
232
  <option value="bottom"<?php echo ( ( $adPosition == 'bottom' ) ? ' selected' : '' ); ?>><?php _e( 'After Content', $this->plugin->name ); ?></option>
233
  </select>
234
- <input type="number" name="paragraph_number" value="<?php echo $paragraphNumber; ?>" min="1" max="999" step="1" id="paragraph_number" />
 
 
 
 
 
 
 
 
 
 
235
  </p>
236
  <?php
237
  }
@@ -343,6 +353,17 @@ class InsertPostAds {
343
  * Checks if the current screen on the frontend needs advert(s) adding to it
344
  */
345
  function checkAdvertsRequired( $content ) {
 
 
 
 
 
 
 
 
 
 
 
346
  global $post;
347
 
348
  // Settings
@@ -429,7 +450,7 @@ class InsertPostAds {
429
 
430
  // + 1 allows for considering the first paragraph as #1, not #0.
431
  if ( $paragraph_id == $index + 1 ) {
432
- $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>';
433
  }
434
  }
435
  return implode( '', $paragraphs );
@@ -497,6 +518,19 @@ class InsertPostAds {
497
  $feed->set_feed_url( $urls );
498
  }
499
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  }
501
 
502
- $insertPostAds = new InsertPostAds();
1
  <?php
2
  /**
3
  * Plugin Name: Insert Post Ads
4
+ * Plugin URI: http://www.insertpostads.com/
5
+ * Version: 1.1.2
6
+ * Author: InsertPostAds
7
+ * Author URI: http://www.insertpostads.com/
8
  * Description: Allows you to insert ads after paragraphs of your post content
9
  * License: GPL2
10
  */
11
 
12
+ /* Copyright 2017 WPBeginner
13
 
14
  This program is free software; you can redistribute it and/or modify
15
  it under the terms of the GNU General Public License, version 2, as
226
  </p>
227
  <p>
228
  <label for="ad_position"><?php _e( 'Display the advert:', $this->plugin->name ); ?></label>
229
+ <select onChange="javascript:handleIpaAdOptionChange( this.value )" name="ad_position" size="1">
230
  <option value="top"<?php echo ( ( $adPosition == 'top' ) ? ' selected' : '' ); ?>><?php _e( 'Before Content', $this->plugin->name ); ?></option>
231
  <option value=""<?php echo ( ( $adPosition == '' ) ? ' selected' : '' ); ?>><?php _e( 'After Paragraph Number', $this->plugin->name ); ?></option>
232
  <option value="bottom"<?php echo ( ( $adPosition == 'bottom' ) ? ' selected' : '' ); ?>><?php _e( 'After Content', $this->plugin->name ); ?></option>
233
  </select>
234
+ <input type="number" name="paragraph_number" value="<?php echo $paragraphNumber; ?>" min="1" max="999" step="1" id="paragraph_number" <?php if ( $adPosition != '' ) { echo ' style="display: none;"'; } ?> />
235
+ <script type="text/javascript">
236
+ var ipaParaNumberElem = document.getElementById( 'paragraph_number' );
237
+ var handleIpaAdOptionChange = function( value ) {
238
+ if ( value != "" ) {
239
+ ipaParaNumberElem.style.display = 'none';
240
+ } else {
241
+ ipaParaNumberElem.style.display = 'inline-block';
242
+ }
243
+ }
244
+ </script>
245
  </p>
246
  <?php
247
  }
353
  * Checks if the current screen on the frontend needs advert(s) adding to it
354
  */
355
  function checkAdvertsRequired( $content ) {
356
+ /**
357
+ * Filter insert_post_ads_enabled Whether ads should be printed.
358
+ * This filter can be used to temporarily stop ads from printing,
359
+ * say, for AMP pages
360
+ *
361
+ * @param bool $enabled Whether ads should be printed
362
+ */
363
+ if ( ! apply_filters( 'insert_post_ads_enabled', true ) ) {
364
+ return $content;
365
+ }
366
+
367
  global $post;
368
 
369
  // Settings
450
 
451
  // + 1 allows for considering the first paragraph as #1, not #0.
452
  if ( $paragraph_id == $index + 1 ) {
453
+ $paragraphs[$index] .= '<div class="' . $this->generateRandomString( 8 ) . '"' . ( isset( $this->settings['css'] ) ? '' : ' style="clear:both;float:left;width:100%;margin:0 0 20px 0;"' ) . '>' . $insertion . '</div>';
454
  }
455
  }
456
  return implode( '', $paragraphs );
518
  $feed->set_feed_url( $urls );
519
  }
520
  }
521
+
522
+ /**
523
+ * Generate a random string of length N
524
+ */
525
+ function generateRandomString( $length = 10 ) {
526
+ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
527
+ $charactersLength = strlen( $characters );
528
+ $randomString = '';
529
+ for ( $i = 0; $i < $length; $i++ ) {
530
+ $randomString .= $characters[rand( 0, $charactersLength - 1 )];
531
+ }
532
+ return $randomString;
533
+ }
534
  }
535
 
536
+ $insertPostAds = new InsertPostAds();
readme.txt CHANGED
@@ -1,10 +1,9 @@
1
  === Insert Post Ads ===
2
- Contributors: WPbeginner, smub, deb255
3
- Donate link:http://www.wpbeginner.com/wpbeginner-needs-your-help/
4
  Tags: ad injection, ads, ads plugin, adsense, adsense injection, google adsense, insert ads in post, insert post ads, wordpress ads plugin, advertising plugin, banners plugin, post ads
5
  Requires at least: 3.6
6
  Tested up to: 4.8
7
- Stable tag: 1.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -20,8 +19,6 @@ In-post ads get the best click through rate. If you want to increase your CTR an
20
 
21
  Insert Post Ads allows you to automatically insert post ads after a specified number of paragraphs. This saves you the hassle of manually inserting post ads for every post.
22
 
23
- This ads plugin is based on our article about <a href="http://www.wpbeginner.com/wp-tutorials/how-to-insert-ads-within-your-post-content-in-wordpress/" title="How to Insert Ads within your Post Content in WordPress" rel="friend">how to insert ads within your post content in WordPress</a>.
24
-
25
  We created this plugin to make it as easy as possible to insert ads in posts.
26
 
27
  = Insert Post Ads Features =
@@ -34,33 +31,13 @@ We created this plugin to make it as easy as possible to insert ads in posts.
34
 
35
  Insert Post Ads makes monetizing your blog easy.
36
 
37
- = Credits =
38
-
39
- This plugin is created by <a href="https://syedbalkhi.com/" rel="friend" title="Syed Balkhi">Syed Balkhi</a> and the <a href="http://www.wpbeginner.com/" rel="friend" title="WPBeginner">WPBeginner</a> team.
40
-
41
- = What's Next =
42
-
43
- If you like this plugin, please leave a good rating and consider checking out our other projects:
44
-
45
- * <a href="http://optinmonster.com/" rel="friend" title="OptinMonster">OptinMonster</a> - Get More Email Subscribers
46
- * <a href="http://wpforms.com/" rel="friend" title="WPForms">WPForms</a> - Best Contact Form Builder Plugin
47
- * <a href="http://soliloquywp.com/" rel="friend" title="Soliloquy">Soliloquy</a> - Best WordPress Slider Plugin
48
- * <a href="http://enviragallery.com/" rel="friend" title="Envira Gallery">Envira Gallery</a> - Best WordPress Gallery Plugin
49
- * <a href="http://monsterinsights.com/" rel="friend" title="MonsterInsights">MonsterInsights</a> - Best Google Analytics Plugin
50
-
51
- Visit <a href="http://www.wpbeginner.com/" rel="friend" title="WPBeginner">WPBeginner</a> to learn from our <a href="http://www.wpbeginner.com/category/wp-tutorials/" rel="friend" title="WordPress Tutorials">WordPress Tutorials</a> and find out about other <a href="http://www.wpbeginner.com/category/plugins/" rel="friend" title="Best WordPress Plugins">best WordPress plugins</a>.
52
-
53
- This plugin should work with most <a href="http://www.wpbeginner.com/wordpress-hosting/" title="Best WordPress Hosting" rel="friend">good WordPress hosting</a> providers, but if you need help to insert post ads, you can ask your questions here.
54
-
55
  == Installation ==
56
 
57
- 1. Install Insert Post Ads by uploading the `insert-post-ads` folder to the `/wp-content/plugins/` directory. (See instructions on <a href="http://www.wpbeginner.com/beginners-guide/step-by-step-guide-to-install-a-wordpress-plugin-for-beginners/" rel="friend">how to install a WordPress plugin</a>.)
58
  2. Active the Insert Post Ads plugin through the `Plugins` menu in WordPress
59
  3. Add your adverts by navigating to the `Post Adverts` in the WordPress Administration menu.
60
  4. Choose where to insert your newly created Post Adverts by navigating to `Post Adverts > Settings` in the WordPress Administration menu.
61
 
62
- [youtube https://www.youtube.com/watch?v=AXM1QgMODW0]
63
-
64
  == Screenshots ==
65
 
66
  1. Post Advert Screen
@@ -76,20 +53,27 @@ When you insert post ads, your theme will determine whether or not your post ads
76
 
77
  Yes, you can choose to insert post ads in custom post types in the `Post Adverts > Settings` menu.
78
 
 
 
 
 
79
  == Notes ==
80
 
81
  Insert Post Ads is the easiest ad injection plugin, for Google AdSense or any advertising code.
82
 
83
- Our goal is to make using WordPress easy for beginners, both with our <a href="http://www.wpbeginner.com/wordpress-plugins/" rel="friend" title="WordPress Plugins">WordPress plugins</a> and resources like <a href="http://www.wpbeginner.com/" rel="friend">WPBeginner</a>, the largest WordPress resource site for beginners.
84
 
85
  I feel that we have done that here. I hope you enjoy using Insert Post Ads.
86
 
87
  Thank you
88
 
89
- Syed Balkhi
90
-
91
  == Changelog ==
92
 
 
 
 
 
 
93
  = 1.1.1 =
94
  * Code cleanups
95
  * Permissions for ads access
@@ -119,4 +103,4 @@ Syed Balkhi
119
  * Added Simplified Chinese language translations (props: Changmeng Hu)
120
 
121
  = 1.0 =
122
- * First release
1
  === Insert Post Ads ===
2
+ Contributors: insertpostads
 
3
  Tags: ad injection, ads, ads plugin, adsense, adsense injection, google adsense, insert ads in post, insert post ads, wordpress ads plugin, advertising plugin, banners plugin, post ads
4
  Requires at least: 3.6
5
  Tested up to: 4.8
6
+ Stable tag: 1.1.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
19
 
20
  Insert Post Ads allows you to automatically insert post ads after a specified number of paragraphs. This saves you the hassle of manually inserting post ads for every post.
21
 
 
 
22
  We created this plugin to make it as easy as possible to insert ads in posts.
23
 
24
  = Insert Post Ads Features =
31
 
32
  Insert Post Ads makes monetizing your blog easy.
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  == Installation ==
35
 
36
+ 1. Install Insert Post Ads by uploading the `insert-post-ads` folder to the `/wp-content/plugins/` directory.
37
  2. Active the Insert Post Ads plugin through the `Plugins` menu in WordPress
38
  3. Add your adverts by navigating to the `Post Adverts` in the WordPress Administration menu.
39
  4. Choose where to insert your newly created Post Adverts by navigating to `Post Adverts > Settings` in the WordPress Administration menu.
40
 
 
 
41
  == Screenshots ==
42
 
43
  1. Post Advert Screen
53
 
54
  Yes, you can choose to insert post ads in custom post types in the `Post Adverts > Settings` menu.
55
 
56
+ = What about AMP pages? =
57
+
58
+ You can disable ads created using this plugin from being printed on your AMP pages by using the filter 'insert_post_ads_enabled' and setting it to boolean false.
59
+
60
  == Notes ==
61
 
62
  Insert Post Ads is the easiest ad injection plugin, for Google AdSense or any advertising code.
63
 
64
+ Our goal is to make using WordPress easy for beginners.
65
 
66
  I feel that we have done that here. I hope you enjoy using Insert Post Ads.
67
 
68
  Thank you
69
 
 
 
70
  == Changelog ==
71
 
72
+ = 1.1.2 =
73
+ * Change the insert 'ad after para# N' container to a random classname to prevent adblockers from blocking it
74
+ * In the ad creation page, hide the paragraph# input field when the position in the dropdown are top or bottom
75
+ * Add a new filter 'insert_post_ads_enabled' - that can be used to temporarily stop ads from printing, say for AMP pages
76
+
77
  = 1.1.1 =
78
  * Code cleanups
79
  * Permissions for ads access
103
  * Added Simplified Chinese language translations (props: Changmeng Hu)
104
 
105
  = 1.0 =
106
+ * First release