Ad Inserter – WordPress Ads Management with AdSense Header Integration - Version 2.2.1

Version Description

  • Fix for header/footer scripts on AMP pages
Download this release

Release Info

Developer spacetime
Plugin Icon 128x128 Ad Inserter – WordPress Ads Management with AdSense Header Integration
Version 2.2.1
Comparing to
See all releases

Code changes from version 2.2.0 to 2.2.1

Files changed (6) hide show
  1. ad-inserter.php +133 -27
  2. class.php +3 -0
  3. constants.php +1 -1
  4. css/ad-inserter.css +1 -1
  5. js/ad-inserter.js +1 -1
  6. readme.txt +8 -1
ad-inserter.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  Plugin Name: Ad Inserter
4
- Version: 2.2.0
5
  Description: Ad management plugin with advanced advertising options to automatically insert ad codes into your website.
6
  Author: Igor Funa
7
  Author URI: http://igorfuna.com/
@@ -12,6 +12,9 @@ Plugin URI: http://adinserter.pro/documentation
12
 
13
  Change Log
14
 
 
 
 
15
  Ad Inserter 2.2.0 - 2017-08-27
16
  - Added support for ad blocking detection (experimental)
17
  - Added support for [ADINSERTER AMP] shortcode to separate code for AMP pages
@@ -1043,12 +1046,12 @@ function ai_wp_hook () {
1043
 
1044
 
1045
  if ($ai_wp_data [AI_WP_AMP_PAGE] && has_action ('amp_post_template_head')) {
1046
- add_action ('amp_post_template_head', 'ai_wp_head_hook');
1047
  } else
1048
  add_action ('wp_head', 'ai_wp_head_hook');
1049
 
1050
  if ($ai_wp_data [AI_WP_AMP_PAGE] && has_action ('amp_post_template_head')) {
1051
- add_action ('amp_post_template_footer', 'ai_wp_footer_hook');
1052
  } else
1053
  add_action ('wp_footer', 'ai_wp_footer_hook');
1054
 
@@ -1728,16 +1731,17 @@ function ai_wp_head_hook () {
1728
  if (!$obj->check_server_side_detection ()) return;
1729
 
1730
  if ($obj->get_enable_manual ()) {
1731
- if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_404 && !$obj->get_enable_404()) return;
 
1732
 
1733
- $processed_code = do_shortcode ($obj->ai_getCode ());
 
 
 
 
1734
 
1735
- if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
1736
- $codes = explode (AD_AMP_SEPARATOR, $processed_code);
1737
- $processed_code = trim ($codes [$ai_wp_data [AI_WP_AMP_PAGE] ? 1 : 0]);
1738
  }
1739
-
1740
- echo $processed_code;
1741
  }
1742
 
1743
  if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
@@ -1766,6 +1770,62 @@ function ai_wp_head_hook () {
1766
  }
1767
  }
1768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1769
  function ai_wp_footer_hook () {
1770
  global $block_object, $ai_wp_data, $ai_total_plugin_time;
1771
 
@@ -1786,16 +1846,17 @@ function ai_wp_footer_hook () {
1786
  if (!$obj->check_server_side_detection ()) return;
1787
 
1788
  if ($obj->get_enable_manual ()) {
1789
- if ($ai_wp_data [AI_WP_PAGE_TYPE] == AI_PT_404 && !$obj->get_enable_404()) return;
 
1790
 
1791
- $processed_code = do_shortcode ($obj->ai_getCode ());
 
 
 
 
1792
 
1793
- if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
1794
- $codes = explode (AD_AMP_SEPARATOR, $processed_code);
1795
- $processed_code = trim ($codes [$ai_wp_data [AI_WP_AMP_PAGE] ? 1 : 0]);
1796
  }
1797
-
1798
- echo $processed_code;
1799
  }
1800
 
1801
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
@@ -1808,6 +1869,47 @@ function ai_wp_footer_hook () {
1808
  }
1809
  }
1810
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1811
  function ai_write_debug_info ($write_processing_log = false) {
1812
  global $block_object, $ai_last_time, $ai_total_plugin_time, $ai_total_php_time, $ai_processing_log, $ai_db_options_extract, $ai_wp_data, $ai_db_options, $block_insertion_log;
1813
 
@@ -2356,11 +2458,13 @@ function ai_check_plugin_options ($plugin_options = array ()) {
2356
  }
2357
 
2358
  function option_stripslashes (&$options) {
2359
- if (is_array ($options)) {
2360
- foreach ($options as $key => $option) {
2361
- option_stripslashes ($options [$key]);
2362
- }
2363
- } else if (is_string ($options)) $options = stripslashes ($options);
 
 
2364
  }
2365
 
2366
  // Deprecated
@@ -3092,12 +3196,13 @@ function ai_settings () {
3092
  $import_switch_name = AI_OPTION_IMPORT . WP_FORM_FIELD_POSTFIX . '0';
3093
  if (isset ($_POST [$import_switch_name]) && $_POST [$import_switch_name] == "1") {
3094
  // Import Ad Inserter settings
3095
- $saved_settings = $ai_db_options;
3096
  $ai_options = @unserialize (base64_decode (str_replace (array ("\\\""), array ("\""), $_POST ["export_settings_0"])));
 
3097
  if ($ai_options === false) {
3098
- $ai_options = $saved_settings;
 
3099
  $invalid_blocks []= 0;
3100
- }
3101
  } else {
3102
  // Try to import individual settings
3103
  $ai_options = array ();
@@ -3105,8 +3210,8 @@ function ai_settings () {
3105
  for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
3106
  $ad = new ai_Block ($block);
3107
 
3108
- if (isset ($ai_db_options [$block])) $saved_settings = $ai_db_options [$block]; else
3109
- $saved_settings = $ad->wp_options;
3110
 
3111
  if ($block < $start || $block > $end) {
3112
  $ai_options [$block] = $saved_settings;
@@ -3121,6 +3226,7 @@ function ai_settings () {
3121
  $exported_settings = @unserialize (base64_decode (str_replace (array ("\\\""), array ("\""), $_POST ["export_settings_" . $block])));
3122
 
3123
  if ($exported_settings !== false) {
 
3124
  foreach (array_keys ($ad->wp_options) as $key){
3125
  if ($key == AI_OPTION_BLOCK_NAME && isset ($_POST [$import_name_switch_name]) && $_POST [$import_name_switch_name] != "1") {
3126
  $form_field_name = $key . WP_FORM_FIELD_POSTFIX . $block;
1
  <?php
2
  /*
3
  Plugin Name: Ad Inserter
4
+ Version: 2.2.1
5
  Description: Ad management plugin with advanced advertising options to automatically insert ad codes into your website.
6
  Author: Igor Funa
7
  Author URI: http://igorfuna.com/
12
 
13
  Change Log
14
 
15
+ Ad Inserter 2.2.1 - 2017-08-27
16
+ - Fix for header/footer scripts on AMP pages
17
+
18
  Ad Inserter 2.2.0 - 2017-08-27
19
  - Added support for ad blocking detection (experimental)
20
  - Added support for [ADINSERTER AMP] shortcode to separate code for AMP pages
1046
 
1047
 
1048
  if ($ai_wp_data [AI_WP_AMP_PAGE] && has_action ('amp_post_template_head')) {
1049
+ add_action ('amp_post_template_head', 'ai_amp_head_hook');
1050
  } else
1051
  add_action ('wp_head', 'ai_wp_head_hook');
1052
 
1053
  if ($ai_wp_data [AI_WP_AMP_PAGE] && has_action ('amp_post_template_head')) {
1054
+ add_action ('amp_post_template_footer', 'ai_amp_footer_hook');
1055
  } else
1056
  add_action ('wp_footer', 'ai_wp_footer_hook');
1057
 
1731
  if (!$obj->check_server_side_detection ()) return;
1732
 
1733
  if ($obj->get_enable_manual ()) {
1734
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $obj->get_enable_404()) {
1735
+ $processed_code = do_shortcode ($obj->ai_getCode ());
1736
 
1737
+ if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
1738
+ $codes = explode (AD_AMP_SEPARATOR, $processed_code);
1739
+ // $processed_code = trim ($codes [$ai_wp_data [AI_WP_AMP_PAGE] ? 1 : 0]);
1740
+ $processed_code = trim ($codes [0]);
1741
+ } elseif ($ai_wp_data [AI_WP_AMP_PAGE]) $processed_code = '';
1742
 
1743
+ echo $processed_code;
 
 
1744
  }
 
 
1745
  }
1746
 
1747
  if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
1770
  }
1771
  }
1772
 
1773
+ function ai_amp_head_hook () {
1774
+ global $block_object, $ai_wp_data, $ai_total_plugin_time;
1775
+
1776
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
1777
+ // ai_log ("HEAD HOOK START");
1778
+ // $start_time = microtime (true);
1779
+ // }
1780
+
1781
+ // add_head_inline_styles_and_scripts ();
1782
+
1783
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_NONE;
1784
+
1785
+ $obj = $block_object [AI_HEADER_OPTION_NAME];
1786
+ $obj->clear_code_cache ();
1787
+
1788
+ if (!$obj->check_server_side_detection ()) return;
1789
+
1790
+ if ($obj->get_enable_manual ()) {
1791
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $obj->get_enable_404()) {
1792
+ $processed_code = do_shortcode ($obj->ai_getCode ());
1793
+
1794
+ if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
1795
+ $codes = explode (AD_AMP_SEPARATOR, $processed_code);
1796
+ $processed_code = trim ($codes [1]);
1797
+ echo $processed_code;
1798
+ }
1799
+ }
1800
+ }
1801
+
1802
+ // if (defined ('AI_ADBLOCKING_DETECTION') && AI_ADBLOCKING_DETECTION) {
1803
+ // // No scripts on AMP pages
1804
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_AD_BLOCKING_STATUS) != 0 && $ai_wp_data [AI_ADB_DETECTION] && !$ai_wp_data [AI_WP_AMP_PAGE]) {
1805
+ // echo "<script>
1806
+ // jQuery(document).ready(function($) {
1807
+ // $('body').prepend (\"", get_adb_status_debug_info () , "\");
1808
+ // });
1809
+ //</script>\n";
1810
+ // }
1811
+ // }
1812
+
1813
+ // // No scripts on AMP pages
1814
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0 & !$ai_wp_data [AI_WP_AMP_PAGE]) {
1815
+ // echo "<script>
1816
+ // jQuery(document).ready(function($) {
1817
+ // $('body').prepend (\"", get_page_type_debug_info () , "\");
1818
+ // });
1819
+ //</script>\n";
1820
+ // }
1821
+
1822
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
1823
+ // $ai_total_plugin_time += microtime (true) - $start_time;
1824
+ // ai_log ("HEAD HOOK END\n");
1825
+ // }
1826
+ }
1827
+
1828
+
1829
  function ai_wp_footer_hook () {
1830
  global $block_object, $ai_wp_data, $ai_total_plugin_time;
1831
 
1846
  if (!$obj->check_server_side_detection ()) return;
1847
 
1848
  if ($obj->get_enable_manual ()) {
1849
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $obj->get_enable_404()) {
1850
+ $processed_code = do_shortcode ($obj->ai_getCode ());
1851
 
1852
+ if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
1853
+ $codes = explode (AD_AMP_SEPARATOR, $processed_code);
1854
+ // $processed_code = trim ($codes [$ai_wp_data [AI_WP_AMP_PAGE] ? 1 : 0]);
1855
+ $processed_code = trim ($codes [0]);
1856
+ } elseif ($ai_wp_data [AI_WP_AMP_PAGE]) $processed_code = '';
1857
 
1858
+ echo $processed_code;
 
 
1859
  }
 
 
1860
  }
1861
 
1862
  if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
1869
  }
1870
  }
1871
 
1872
+ function ai_amp_footer_hook () {
1873
+ global $block_object, $ai_wp_data, $ai_total_plugin_time;
1874
+
1875
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
1876
+ // ai_log ("FOOTER HOOK START");
1877
+ // $start_time = microtime (true);
1878
+ // }
1879
+
1880
+ // if (!(defined ('DOING_AJAX') && DOING_AJAX) && !$ai_wp_data [AI_WP_AMP_PAGE]) {
1881
+ // add_footer_inline_scripts ();
1882
+ // }
1883
+
1884
+ $ai_wp_data [AI_CONTEXT] = AI_CONTEXT_FOOTER;
1885
+
1886
+ $obj = $block_object [AI_FOOTER_OPTION_NAME];
1887
+ $obj->clear_code_cache ();
1888
+
1889
+ if (!$obj->check_server_side_detection ()) return;
1890
+
1891
+ if ($obj->get_enable_manual ()) {
1892
+ if ($ai_wp_data [AI_WP_PAGE_TYPE] != AI_PT_404 || $obj->get_enable_404()) {
1893
+ $processed_code = do_shortcode ($obj->ai_getCode ());
1894
+
1895
+ if (strpos ($processed_code, AD_AMP_SEPARATOR) !== false) {
1896
+ $codes = explode (AD_AMP_SEPARATOR, $processed_code);
1897
+ $processed_code = trim ($codes [1]);
1898
+ echo $processed_code;
1899
+ }
1900
+ }
1901
+ }
1902
+
1903
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_POSITIONS) != 0) {
1904
+ // echo get_page_type_debug_info () , "\n";
1905
+ // }
1906
+
1907
+ // if (($ai_wp_data [AI_WP_DEBUGGING] & AI_DEBUG_PROCESSING) != 0) {
1908
+ // $ai_total_plugin_time += microtime (true) - $start_time;
1909
+ // ai_log ("FOOTER HOOK END\n");
1910
+ // }
1911
+ }
1912
+
1913
  function ai_write_debug_info ($write_processing_log = false) {
1914
  global $block_object, $ai_last_time, $ai_total_plugin_time, $ai_total_php_time, $ai_processing_log, $ai_db_options_extract, $ai_wp_data, $ai_db_options, $block_insertion_log;
1915
 
2458
  }
2459
 
2460
  function option_stripslashes (&$options) {
2461
+ $options = wp_unslash ($options);
2462
+
2463
+ // if (is_array ($options)) {
2464
+ // foreach ($options as $key => $option) {
2465
+ // option_stripslashes ($options [$key]);
2466
+ // }
2467
+ // } else if (is_string ($options)) $options = stripslashes ($options);
2468
  }
2469
 
2470
  // Deprecated
3196
  $import_switch_name = AI_OPTION_IMPORT . WP_FORM_FIELD_POSTFIX . '0';
3197
  if (isset ($_POST [$import_switch_name]) && $_POST [$import_switch_name] == "1") {
3198
  // Import Ad Inserter settings
 
3199
  $ai_options = @unserialize (base64_decode (str_replace (array ("\\\""), array ("\""), $_POST ["export_settings_0"])));
3200
+
3201
  if ($ai_options === false) {
3202
+ // Use saved settings
3203
+ $ai_options = wp_slash ($ai_db_options);
3204
  $invalid_blocks []= 0;
3205
+ } else $ai_options = wp_slash ($ai_options);
3206
  } else {
3207
  // Try to import individual settings
3208
  $ai_options = array ();
3210
  for ($block = 1; $block <= AD_INSERTER_BLOCKS; $block ++) {
3211
  $ad = new ai_Block ($block);
3212
 
3213
+ if (isset ($ai_db_options [$block])) $saved_settings = wp_slash ($ai_db_options [$block]); else
3214
+ $saved_settings = wp_slash ($ad->wp_options);
3215
 
3216
  if ($block < $start || $block > $end) {
3217
  $ai_options [$block] = $saved_settings;
3226
  $exported_settings = @unserialize (base64_decode (str_replace (array ("\\\""), array ("\""), $_POST ["export_settings_" . $block])));
3227
 
3228
  if ($exported_settings !== false) {
3229
+ $exported_settings = wp_slash ($exported_settings);
3230
  foreach (array_keys ($ad->wp_options) as $key){
3231
  if ($key == AI_OPTION_BLOCK_NAME && isset ($_POST [$import_name_switch_name]) && $_POST [$import_name_switch_name] != "1") {
3232
  $form_field_name = $key . WP_FORM_FIELD_POSTFIX . $block;
class.php CHANGED
@@ -1280,6 +1280,9 @@ abstract class ai_CodeBlock extends ai_BaseCodeBlock {
1280
  $code = "<div style='border: 1px solid " . $this->color . ";'>".$visible_viewports . $processed_code.'</div>';
1281
  } else $code = $this->ai_getProcessedCode ();
1282
 
 
 
 
1283
  $block_class_name = get_block_class_name ();
1284
  if ($block_class_name == '' && $this->needs_class) $block_class_name = DEFAULT_BLOCK_CLASS_NAME;
1285
  $viewport_classes = $include_viewport_classes ? $this->get_viewport_classes () : "";
1280
  $code = "<div style='border: 1px solid " . $this->color . ";'>".$visible_viewports . $processed_code.'</div>';
1281
  } else $code = $this->ai_getProcessedCode ();
1282
 
1283
+ // Prevent empty wrapping div on AMP pages
1284
+ if ($ai_wp_data [AI_WP_AMP_PAGE] && $code == '') return '';
1285
+
1286
  $block_class_name = get_block_class_name ();
1287
  if ($block_class_name == '' && $this->needs_class) $block_class_name = DEFAULT_BLOCK_CLASS_NAME;
1288
  $viewport_classes = $include_viewport_classes ? $this->get_viewport_classes () : "";
constants.php CHANGED
@@ -18,7 +18,7 @@ if (!defined( 'AD_INSERTER_NAME'))
18
  define ('AD_INSERTER_NAME', 'Ad Inserter');
19
 
20
  if (!defined( 'AD_INSERTER_VERSION'))
21
- define ('AD_INSERTER_VERSION', '2.2.0');
22
 
23
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
24
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
18
  define ('AD_INSERTER_NAME', 'Ad Inserter');
19
 
20
  if (!defined( 'AD_INSERTER_VERSION'))
21
+ define ('AD_INSERTER_VERSION', '2.2.1');
22
 
23
  if (!defined ('AD_INSERTER_PLUGIN_BASENAME'))
24
  define ('AD_INSERTER_PLUGIN_BASENAME', plugin_basename (__FILE__));
css/ad-inserter.css CHANGED
@@ -1,5 +1,5 @@
1
  #ai-data {
2
- font-family: "2.2.0"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
1
  #ai-data {
2
+ font-family: "2.2.1"; /* Used for version number of the file */
3
  }
4
 
5
  #blocked-warning {
js/ad-inserter.js CHANGED
@@ -1,4 +1,4 @@
1
- var javascript_version = "2.2.0";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
1
+ var javascript_version = "2.2.1";
2
  var ignore_key = true;
3
  var start = 1;
4
  var end = 16;
readme.txt CHANGED
@@ -5,7 +5,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
5
  Tags: ads, adsense, ad management, advertising manager, advanced contextual ads, ad rotation, ad injection, adverts, sticky widgets, amazon, banners, automatic insertion, amp, geo targeting, multisite, shortcodes, PHP, Javascript, HTML, header, footer, tracking
6
  Requires at least: 4.0
7
  Tested up to: 4.8
8
- Stable tag: 2.1.14
9
  License: GPLv3
10
 
11
  Insert and manage ads: AdSense, Amazon, banners, ad rotation, sticky ad widgets, shortcodes, AMP, PHP, HTML, CSS, form, tracking, header, footer code
@@ -715,6 +715,10 @@ AD CODE RIGHT
715
 
716
  == Changelog ==
717
 
 
 
 
 
718
  = 2.2.0 =
719
  - Added support for ad blocking detection (experimental)
720
  - Added support for [ADINSERTER AMP] shortcode to separate code for AMP pages
@@ -917,6 +921,9 @@ AD CODE RIGHT
917
 
918
  == Upgrade Notice ==
919
 
 
 
 
920
  = 2.2.0 =
921
  Added support for ad blocking detection (experimental);
922
  Added support for [ADINSERTER AMP] shortcode to separate code for AMP pages;
5
  Tags: ads, adsense, ad management, advertising manager, advanced contextual ads, ad rotation, ad injection, adverts, sticky widgets, amazon, banners, automatic insertion, amp, geo targeting, multisite, shortcodes, PHP, Javascript, HTML, header, footer, tracking
6
  Requires at least: 4.0
7
  Tested up to: 4.8
8
+ Stable tag: 2.2.0
9
  License: GPLv3
10
 
11
  Insert and manage ads: AdSense, Amazon, banners, ad rotation, sticky ad widgets, shortcodes, AMP, PHP, HTML, CSS, form, tracking, header, footer code
715
 
716
  == Changelog ==
717
 
718
+
719
+ = 2.2.1 =
720
+ - Fix for header/footer scripts on AMP pages
721
+
722
  = 2.2.0 =
723
  - Added support for ad blocking detection (experimental)
724
  - Added support for [ADINSERTER AMP] shortcode to separate code for AMP pages
921
 
922
  == Upgrade Notice ==
923
 
924
+ = 2.2.1 =
925
+ Fix for header/footer scripts on AMP pages
926
+
927
  = 2.2.0 =
928
  Added support for ad blocking detection (experimental);
929
  Added support for [ADINSERTER AMP] shortcode to separate code for AMP pages;