Head, Footer and Post Injections - Version 3.1.4

Version Description

  • Performance optimization
  • Removed obsolete code
  • Improved AMP support
  • (Temporary) removed metaboxes (they were not working anyway)
Download this release

Release Info

Developer satollo
Plugin Icon wp plugin Head, Footer and Post Injections
Version 3.1.4
Comparing to
See all releases

Code changes from version 3.1.3 to 3.1.4

admin.css → admin/admin.css RENAMED
File without changes
admin/admin.php ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ defined('ABSPATH') || exit;
3
+
4
+ add_action('admin_init', 'hefo_admin_init');
5
+
6
+ function hefo_admin_init() {
7
+ global $hefo_options;
8
+ if (isset($_GET['page']) && strpos($_GET['page'], 'header-footer/') === 0) {
9
+ header('X-XSS-Protection: 0');
10
+ wp_enqueue_script('jquery-ui-tabs');
11
+ wp_enqueue_style('header-footer', plugins_url('header-footer') . '/admin/admin.css', array(), time());
12
+ wp_enqueue_style('header-footer-tabs', plugins_url('header-footer') . '/lib/easytabs/tabs.css', array(), time());
13
+ wp_enqueue_script('header-footer-tabs', plugins_url('header-footer') . '/lib/easytabs/jquery.easytabs.min.js', array(), time());
14
+ }
15
+
16
+ if (isset($hefo_options['page_add_tags'])) {
17
+ register_taxonomy_for_object_type('post_tag', 'page');
18
+ }
19
+
20
+ if (isset($hefo_options['page_add_categories'])) {
21
+ register_taxonomy_for_object_type('category', 'page');
22
+ }
23
+ }
24
+
25
+ add_action('admin_menu', function() {
26
+ add_options_page('Header and Footer', 'Header and Footer', 'manage_options', 'header-footer/admin/options.php');
27
+ });
admin.php → admin/metaboxes.php RENAMED
@@ -1,42 +1,11 @@
1
  <?php
 
2
 
3
- delete_option('hefo_version');
4
 
5
- add_action('admin_init', 'hefo_admin_init');
6
-
7
- function hefo_admin_init() {
8
- global $hefo_options;
9
- if (isset($_GET['page']) && strpos($_GET['page'], 'header-footer/') === 0) {
10
- header('X-XSS-Protection: 0');
11
- wp_enqueue_script('jquery-ui-tabs');
12
- wp_enqueue_script('media-upload');
13
- wp_enqueue_script('thickbox');
14
- wp_enqueue_style('thickbox');
15
- wp_enqueue_style('header-footer', plugins_url('header-footer') . '/admin.css', array(), time());
16
- wp_enqueue_style('header-footer-tabs', plugins_url('header-footer') . '/lib/easytabs/tabs.css', array(), time());
17
- wp_enqueue_script('header-footer-tabs', plugins_url('header-footer') . '/lib/easytabs/jquery.easytabs.min.js', array(), time());
18
- }
19
-
20
- if (isset($hefo_options['page_add_tags'])) {
21
- register_taxonomy_for_object_type('post_tag', 'page');
22
- }
23
-
24
- if (isset($hefo_options['page_add_categories'])) {
25
- register_taxonomy_for_object_type('category', 'page');
26
- }
27
- }
28
-
29
- add_action('admin_menu', 'hefo_admin_menu');
30
-
31
- function hefo_admin_menu() {
32
- add_options_page('Header and Footer', 'Header and Footer', 'manage_options', 'header-footer/options.php');
33
-
34
- }
35
-
36
- add_action('add_meta_boxes', 'hefo_add_meta_boxes');
37
-
38
- add_action('save_post', 'hefo_save_post');
39
 
 
40
  function hefo_add_meta_boxes() {
41
  foreach (array('post', 'page') as $screen) {
42
  add_meta_box(
@@ -44,7 +13,9 @@ function hefo_add_meta_boxes() {
44
  );
45
  }
46
  }
 
47
 
 
48
  function hefo_add_meta_boxes_callback($post) {
49
 
50
  // Use nonce for verification
@@ -64,7 +35,9 @@ function hefo_add_meta_boxes_callback($post) {
64
  _e("Disable bottom injection", 'header-footer');
65
  echo '</label> ';
66
  }
 
67
 
 
68
  function hefo_save_post($post_id) {
69
 
70
  // First we need to check if the current user is authorised to do this action.
@@ -83,3 +56,4 @@ function hefo_save_post($post_id) {
83
  update_post_meta($post_id, 'hefo_before', isset($_REQUEST['hefo_before']) ? 1 : 0);
84
  update_post_meta($post_id, 'hefo_after', isset($_REQUEST['hefo_after']) ? 1 : 0);
85
  }
 
1
  <?php
2
+ defined('ABSPATH') || exit;
3
 
4
+ //add_action('add_meta_boxes', 'hefo_add_meta_boxes');
5
 
6
+ //add_action('save_post', 'hefo_save_post');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
+ /*
9
  function hefo_add_meta_boxes() {
10
  foreach (array('post', 'page') as $screen) {
11
  add_meta_box(
13
  );
14
  }
15
  }
16
+ */
17
 
18
+ /*
19
  function hefo_add_meta_boxes_callback($post) {
20
 
21
  // Use nonce for verification
35
  _e("Disable bottom injection", 'header-footer');
36
  echo '</label> ';
37
  }
38
+ */
39
 
40
+ /*
41
  function hefo_save_post($post_id) {
42
 
43
  // First we need to check if the current user is authorised to do this action.
56
  update_post_meta($post_id, 'hefo_before', isset($_REQUEST['hefo_before']) ? 1 : 0);
57
  update_post_meta($post_id, 'hefo_after', isset($_REQUEST['hefo_after']) ? 1 : 0);
58
  }
59
+ */
options.php → admin/options.php RENAMED
@@ -223,47 +223,17 @@ if (isset($_POST['save'])) {
223
  else {
224
  $options = get_option('hefo');
225
  }
226
- ?>
227
 
228
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/codemirror.css" type="text/css">
229
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/addon/hint/show-hint.css">
230
- <style>
231
- .CodeMirror {
232
- border: 1px solid #ddd;
233
- }
234
- </style>
235
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/codemirror.js"></script>
236
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/mode/xml/xml.js"></script>
237
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/mode/javascript/javascript.js"></script>
238
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/mode/css/css.js"></script>
239
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/mode/htmlmixed/htmlmixed.js"></script>
240
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/mode/clike/clike.js"></script>
241
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/mode/php/php.js"></script>
242
-
243
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/addon/hint/show-hint.js"></script>
244
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/addon/hint/css-hint.js"></script>
245
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/addon/hint/xml-hint.js"></script>
246
- <script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.20.2/addon/hint/html-hint.js"></script>
247
 
248
  <script>
249
  var templateEditor;
250
  jQuery(document).ready(function () {
251
  jQuery("textarea.hefo-cm").each(function () {
252
- var cmOptions = {
253
- lineNumbers: true,
254
- mode: "php",
255
- extraKeys: {"Ctrl-Space": "autocomplete"}
256
- }
257
- CodeMirror.fromTextArea(this, cmOptions);
258
- });
259
- jQuery("textarea.hefo-cm-css").each(function () {
260
- var cmOptions = {
261
- lineNumbers: true,
262
- mode: "css",
263
- extraKeys: {"Ctrl-Space": "autocomplete"}
264
- }
265
- CodeMirror.fromTextArea(this, cmOptions);
266
  });
 
267
  });
268
  </script>
269
 
@@ -272,19 +242,6 @@ else {
272
 
273
  var hefo_tabs;
274
  jQuery(document).ready(function () {
275
-
276
- jQuery('#upload-image').click(function () {
277
- tb_show('', 'media-upload.php?type=image&amp;TB_iframe=true');
278
- return false;
279
- });
280
-
281
- window.send_to_editor = function (html) {
282
- var imgurl = jQuery('img', html).attr('src');
283
- jQuery('#og_image_default').val(imgurl);
284
- tb_remove();
285
- jQuery("#tabs").tabs();
286
- }
287
-
288
  jQuery("#tab-container").easytabs();
289
  });
290
  </script>
@@ -353,12 +310,12 @@ else {
353
  <li class='tab'><a href="#tabs-post"><?php _e('Posts', 'header-footer'); ?></a></li>
354
  <li class='tab'><a href="#tabs-post-inner"><?php _e('Inside posts', 'header-footer'); ?></a></li>
355
  <li class='tab'><a href="#tabs-page"><?php _e('Pages', 'header-footer'); ?></a></li>
 
356
  <li class='tab'><a href="#tabs-5"><?php _e('Snippets', 'header-footer'); ?></a></li>
357
  <li class='tab'><a href="#tabs-amp"><?php _e('AMP', 'header-footer'); ?></a></li>
358
  <li class='tab'><a href="#tabs-generics"><?php _e('Generics', 'header-footer'); ?></a></li>
359
  <li class='tab'><a href="#tabs-8"><?php _e('Advanced', 'header-footer'); ?></a></li>
360
  <li class='tab'><a href="#tabs-7"><?php _e('Notes and...', 'header-footer'); ?></a></li>
361
- <li class='tab'><a href="#tabs-thankyou"><?php _e('Thank you', 'header-footer'); ?></a></li>
362
  </ul>
363
 
364
  <div class="panel-container">
@@ -470,12 +427,7 @@ else {
470
  <tr valign="top"><?php //hefo_field_textarea('after', __('Code to be inserted after each post', 'header-footer'), '', 'rows="10"'); ?></tr>
471
  </table>
472
 
473
- <h3><?php _e('Injection on excerpts', 'header-footer'); ?></h3>
474
- <p><?php _e('It works only on category and tag pages.', 'header-footer'); ?></p>
475
- <table class="form-table">
476
- <tr valign="top"><?php hefo_field_textarea('excerpt_before', __('Code to be inserted before each post excerpt', 'header-footer'), '', 'rows="10"'); ?></tr>
477
- <tr valign="top"><?php hefo_field_textarea('excerpt_after', __('Code to be inserted after each post excerpt', 'header-footer'), '', 'rows="10"'); ?></tr>
478
- </table>
479
  <div class="clearfix"></div>
480
  </div>
481
 
@@ -537,7 +489,15 @@ else {
537
  <div class="clearfix"></div>
538
 
539
  </div>
540
-
 
 
 
 
 
 
 
 
541
 
542
  <!-- AMP -->
543
 
@@ -559,9 +519,19 @@ else {
559
  <h3><?php esc_html_e('Extra CSS', 'header-footer')?></h3>
560
  <div class="row">
561
  <div class="col-1">
562
- <?php hefo_base_textarea_cm('amp_css', 'css'); ?>
563
  </div>
564
  </div>
 
 
 
 
 
 
 
 
 
 
565
 
566
  <div class="clearfix"></div>
567
 
@@ -672,13 +642,7 @@ else {
672
  <div class="clearfix"></div>
673
  </div>
674
 
675
- <div id="tabs-thankyou">
676
-
677
- <ul>
678
- <li><a href="https://plus.google.com/u/0/118278852301653300773">Евгений Жуков (Eugene Zhukov)</a> - Russian translation</li>
679
- </ul>
680
- <div class="clearfix"></div>
681
- </div>
682
  </div>
683
 
684
  </div>
223
  else {
224
  $options = get_option('hefo');
225
  }
 
226
 
227
+ wp_enqueue_code_editor(['type'=>'php']);
228
+ ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
 
230
  <script>
231
  var templateEditor;
232
  jQuery(document).ready(function () {
233
  jQuery("textarea.hefo-cm").each(function () {
234
+ wp.codeEditor.initialize(this);
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  });
236
+
237
  });
238
  </script>
239
 
242
 
243
  var hefo_tabs;
244
  jQuery(document).ready(function () {
 
 
 
 
 
 
 
 
 
 
 
 
 
245
  jQuery("#tab-container").easytabs();
246
  });
247
  </script>
310
  <li class='tab'><a href="#tabs-post"><?php _e('Posts', 'header-footer'); ?></a></li>
311
  <li class='tab'><a href="#tabs-post-inner"><?php _e('Inside posts', 'header-footer'); ?></a></li>
312
  <li class='tab'><a href="#tabs-page"><?php _e('Pages', 'header-footer'); ?></a></li>
313
+ <li class='tab'><a href="#tabs-excerpt"><?php _e('Excerpts', 'header-footer'); ?></a></li>
314
  <li class='tab'><a href="#tabs-5"><?php _e('Snippets', 'header-footer'); ?></a></li>
315
  <li class='tab'><a href="#tabs-amp"><?php _e('AMP', 'header-footer'); ?></a></li>
316
  <li class='tab'><a href="#tabs-generics"><?php _e('Generics', 'header-footer'); ?></a></li>
317
  <li class='tab'><a href="#tabs-8"><?php _e('Advanced', 'header-footer'); ?></a></li>
318
  <li class='tab'><a href="#tabs-7"><?php _e('Notes and...', 'header-footer'); ?></a></li>
 
319
  </ul>
320
 
321
  <div class="panel-container">
427
  <tr valign="top"><?php //hefo_field_textarea('after', __('Code to be inserted after each post', 'header-footer'), '', 'rows="10"'); ?></tr>
428
  </table>
429
 
430
+
 
 
 
 
 
431
  <div class="clearfix"></div>
432
  </div>
433
 
489
  <div class="clearfix"></div>
490
 
491
  </div>
492
+
493
+ <div id="tabs-excerpt">
494
+
495
+ <p><?php _e('It works only on category and tag pages.', 'header-footer'); ?></p>
496
+ <table class="form-table">
497
+ <tr valign="top"><?php hefo_field_textarea('excerpt_before', __('Code to be inserted before each post excerpt', 'header-footer'), '', 'rows="10"'); ?></tr>
498
+ <tr valign="top"><?php hefo_field_textarea('excerpt_after', __('Code to be inserted after each post excerpt', 'header-footer'), '', 'rows="10"'); ?></tr>
499
+ </table>
500
+ </div>
501
 
502
  <!-- AMP -->
503
 
519
  <h3><?php esc_html_e('Extra CSS', 'header-footer')?></h3>
520
  <div class="row">
521
  <div class="col-1">
522
+ <?php hefo_base_textarea_cm('amp_css'); ?>
523
  </div>
524
  </div>
525
+
526
+ <div class="clearfix"></div>
527
+
528
+ <h3><?php esc_html_e('Just after the <BODY> tag', 'header-footer')?></h3>
529
+ <div class="row">
530
+ <div class="col-1">
531
+ <?php hefo_base_textarea_cm('amp_body'); ?>
532
+ </div>
533
+ </div>
534
+
535
 
536
  <div class="clearfix"></div>
537
 
642
  <div class="clearfix"></div>
643
  </div>
644
 
645
+
 
 
 
 
 
 
646
  </div>
647
 
648
  </div>
plugin.php CHANGED
@@ -4,14 +4,14 @@
4
  Plugin Name: Head, Footer and Post Injections
5
  Plugin URI: http://www.satollo.net/plugins/header-footer
6
  Description: Header and Footer lets to add html/javascript code to the head and footer and posts of your blog. Some examples are provided on the <a href="http://www.satollo.net/plugins/header-footer">official page</a>.
7
- Version: 3.1.3
8
  Author: Stefano Lissa
9
  Author URI: http://www.satollo.net
10
  Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
11
  */
12
 
13
  /*
14
- Copyright 2008-2019 Stefano Lissa (stefano@satollo.net)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
@@ -28,6 +28,8 @@
28
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
  */
30
 
 
 
31
  $hefo_options = get_option('hefo', array());
32
 
33
  $hefo_is_mobile = false;
@@ -38,7 +40,7 @@ if (defined('IS_PHONE') && IS_PHONE) {
38
  }
39
 
40
  if (is_admin()) {
41
- include dirname(__FILE__) . '/admin.php';
42
  }
43
 
44
  if (isset($hefo_options['disable_css_id'])) {
@@ -57,7 +59,29 @@ if (isset($hefo_options['disable_css_id'])) {
57
  add_filter('style_loader_tag', 'hefo_style_loader_tag');
58
  }
59
 
60
- add_action('template_redirect', 'hefo_template_redirect', 99);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
  $hefo_body_block = '';
63
  $hefo_generic_block = array();
@@ -65,20 +89,21 @@ $hefo_generic_block = array();
65
  function hefo_template_redirect() {
66
  global $hefo_body_block, $hefo_generic_block, $hefo_options, $hefo_is_mobile;
67
 
 
68
  if ($hefo_is_mobile && isset($hefo_options['mobile_body_enabled'])) {
69
- $hefo_body_block = hefo_execute($hefo_options['mobile_body']);
70
  } else {
71
- $hefo_body_block = hefo_execute($hefo_options['body']);
72
  }
 
73
  for ($i = 1; $i <= 5; $i++) {
74
  if ($hefo_is_mobile && isset($hefo_options['mobile_generic_enabled_' . $i])) {
75
- if (isset($hefo_options['mobile_generic_' . $i]))
76
- $hefo_generic_block[$i] = hefo_execute($hefo_options['mobile_generic_' . $i]);
77
  } else {
78
- if (isset($hefo_options['generic_' . $i]))
79
- $hefo_generic_block[$i] = hefo_execute($hefo_options['generic_' . $i]);
80
  }
81
  }
 
82
  ob_start('hefo_callback');
83
  }
84
 
@@ -125,263 +150,119 @@ function hefo_wp_head_pre() {
125
  if (isset($hefo_options['disable_wp_shortlink_wp_head'])) {
126
  remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
127
  }
128
-
129
- if (is_home() && is_paged() && isset($hefo_options['seo_home_paged_noindex'])) {
130
- echo '<meta name="robots" content="noindex">';
131
- }
132
-
133
- if (is_home() && !is_paged() && isset($hefo_options['seo_home_canonical'])) {
134
- echo '<meta name="canonical" content="' . get_option('home') . '">';
135
- }
136
-
137
- if (is_archive() && is_paged() && isset($hefo_options['seo_archives_paged_noindex'])) {
138
- echo '<meta name="robots" content="noindex">';
139
- }
140
-
141
- if (is_search() && isset($hefo_options['seo_search_noindex'])) {
142
- echo '<meta name="robots" content="noindex">';
143
- }
144
  }
145
 
146
  add_action('wp_head', 'hefo_wp_head_post', 11);
147
 
148
  function hefo_wp_head_post() {
149
- global $hefo_options, $wp_query, $wpdb;
150
- $buffer = '';
151
  if (is_front_page()) {
152
- $buffer .= hefo_replace($hefo_options['head_home']);
153
  }
154
 
155
- $buffer .= hefo_replace($hefo_options['head']);
156
-
157
- if (apply_filters('hefo_php_exec', true)) {
158
- ob_start();
159
- eval('?>' . $buffer);
160
- ob_end_flush();
161
- } else {
162
- echo $buffer;
163
- }
164
  }
165
 
166
- add_action('amp_post_template_head', 'hefo_amp_post_template_head', 100);
 
 
167
 
168
- function hefo_amp_post_template_head() {
169
- global $hefo_options;
170
- echo hefo_execute($hefo_options['amp_head']);
171
- }
172
-
173
- add_action('amp_post_template_css', 'hefo_amp_post_template_css', 100);
174
 
175
- function hefo_amp_post_template_css() {
176
- global $hefo_options;
177
- echo "\n";
178
- echo hefo_execute($hefo_options['amp_css']);
179
- echo "\n";
180
- }
181
 
182
- add_action('amp_post_template_footer', 'hefo_amp_post_template_footer', 100);
 
 
183
 
184
- function hefo_amp_post_template_footer() {
185
- global $hefo_options;
186
- echo "\n";
187
- echo hefo_execute($hefo_options['amp_footer']);
188
- echo "\n";
189
- }
190
 
191
  add_action('wp_footer', 'hefo_wp_footer');
192
 
193
  function hefo_wp_footer() {
194
- global $hefo_options, $hefo_is_mobile;
195
 
196
  if ($hefo_is_mobile && isset($hefo_options['mobile_footer_enabled'])) {
197
- $buffer = $hefo_options['mobile_footer'];
198
- } else {
199
- $buffer = $hefo_options['footer'];
200
- }
201
-
202
- $buffer = hefo_replace($buffer);
203
-
204
- if (apply_filters('hefo_php_exec', true)) {
205
- ob_start();
206
- eval('?>' . $buffer);
207
- ob_end_flush();
208
  } else {
209
- echo $buffer;
210
  }
211
  }
212
 
213
- // BBPRESS
214
- $bbp_reply_count = 0;
215
-
216
- add_action('bbp_theme_before_reply_content', 'hefo_bbp_theme_before_reply_content');
217
-
218
- function hefo_bbp_theme_before_reply_content() {
219
- global $hefo_options, $hefo_is_mobile, $wpdb, $post, $bbp_reply_count;
220
- $bbp_reply_count++;
221
- if ($hefo_is_mobile && isset($hefo_options['mobile_bbp_theme_before_reply_content_enabled'])) {
222
- echo hefo_execute(hefo_replace($hefo_options['mobile_bbp_theme_before_reply_content']));
223
- } else {
224
- echo hefo_execute(hefo_replace($hefo_options['bbp_theme_before_reply_content']));
225
- }
226
- }
227
 
228
- add_action('bbp_theme_after_reply_content', 'hefo_bbp_theme_after_reply_content');
 
229
 
230
- function hefo_bbp_theme_after_reply_content() {
231
- global $hefo_options, $hefo_is_mobile, $wpdb, $post, $bbp_reply_count;
232
 
233
- if ($hefo_is_mobile && isset($hefo_options['mobile_bbp_theme_after_reply_content_enabled'])) {
234
- echo hefo_execute(hefo_replace($hefo_options['mobile_bbp_theme_after_reply_content']));
235
- } else {
236
- echo hefo_execute(hefo_replace($hefo_options['bbp_theme_after_reply_content']));
 
237
  }
238
- }
239
-
240
- add_action('bbp_template_before_single_forum', 'hefo_bbp_template_before_single_forum');
241
-
242
- function hefo_bbp_template_before_single_forum() {
243
- global $hefo_options, $hefo_is_mobile, $wpdb, $post;
244
 
245
- if ($hefo_is_mobile && isset($hefo_options['mobile_bbp_template_before_single_forum_enabled'])) {
246
- echo hefo_execute(hefo_replace($hefo_options['mobile_bbp_template_before_single_forum']));
247
- } else {
248
- echo hefo_execute(hefo_replace($hefo_options['bbp_template_before_single_forum']));
249
  }
250
- }
251
 
252
- add_action('bbp_template_before_single_topic', 'hefo_bbp_template_before_single_topic');
253
-
254
- function hefo_bbp_template_before_single_topic() {
255
- global $hefo_options, $hefo_is_mobile, $wpdb, $post;
256
 
257
- if ($hefo_is_mobile && isset($hefo_options['mobile_bbp_template_after_before_topic_enabled'])) {
258
- echo hefo_execute(hefo_replace($hefo_options['mobile_bbp_template_before_single_topic']));
259
  } else {
260
- echo hefo_execute(hefo_replace($hefo_options['bbp_template_after_before_topic']));
261
  }
262
- }
263
-
264
- add_action('bbp_template_after_single_topic', 'hefo_bbp_template_after_single_topic');
265
 
266
- function hefo_bbp_template_after_single_topic() {
267
- global $hefo_options, $hefo_is_mobile, $wpdb, $post;
268
-
269
- if ($hefo_is_mobile && isset($hefo_options['mobile_bbp_template_after_single_topic_enabled'])) {
270
- echo hefo_execute(hefo_replace($hefo_options['mobile_bbp_template_after_single_topic']));
271
  } else {
272
- echo hefo_execute(hefo_replace($hefo_options['bbp_template_after_single_topic']));
273
  }
274
- }
275
-
276
- add_action('the_content', 'hefo_the_content');
277
 
278
- global $hefo_page_top, $hefo_page_bottom, $hefo_post_top, $hefo_post_bottom;
279
- $hefo_page_top = true;
280
- $hefo_page_bottom = true;
281
- $hefo_post_top = true;
282
- $hefo_post_bottom = true;
283
 
284
- function hefo_the_content($content) {
285
- global $hefo_options, $wpdb, $post, $hefo_page_top, $hefo_page_bottom, $hefo_post_top, $hefo_post_bottom, $hefo_is_mobile;
286
 
287
- $before = '';
288
- $after = '';
289
 
290
- // AMP detection
291
- if (function_exists('is_amp_endpoint') && is_amp_endpoint()) {
292
- $before = hefo_execute($hefo_options['amp_post_before']);
293
- $after = hefo_execute($hefo_options['amp_post_after']);
294
- return $before . $content . $after;
295
- }
 
 
 
 
 
 
 
 
296
 
297
- //if (is_singular() || ($hefo_options['category'] && (is_category() || is_tag()))) {
298
- if (is_singular()) {
299
- //if (!empty($hefo_options[$post->post_type . '_before'])) {
300
- // echo $hefo_options[$post->post_type . '_before'];
301
- //}
302
- if (is_page() && !isset($hefo_options['page_use_post'])) {
303
- if ($hefo_page_top) {
304
- $value = get_post_meta($post->ID, 'hefo_before', true);
305
- if ($value != '1') {
306
- if (isset($hefo_options['mobile_page_before_enabled']) && $hefo_is_mobile) {
307
- $before = hefo_execute(hefo_replace($hefo_options['mobile_page_before']));
308
- } else {
309
- $before = hefo_execute(hefo_replace($hefo_options['page_before']));
310
- }
311
- }
312
- }
313
- if ($hefo_page_bottom) {
314
- $value = get_post_meta($post->ID, 'hefo_after', true);
315
- if ($value != '1') {
316
- if (isset($hefo_options['mobile_page_after_enabled']) && $hefo_is_mobile) {
317
- $after = hefo_execute(hefo_replace($hefo_options['mobile_page_after']));
318
- } else {
319
- $after = hefo_execute(hefo_replace($hefo_options['page_after']));
320
- }
321
- }
322
- }
323
  } else {
324
- if ($hefo_post_top) {
325
- $value = get_post_meta($post->ID, 'hefo_before', true);
326
- if ($value != '1') {
327
- if (isset($hefo_options['mobile_before_enabled']) && $hefo_is_mobile) {
328
- $before = hefo_execute(hefo_replace($hefo_options['mobile_before']));
329
- } else {
330
- $before = hefo_execute(hefo_replace($hefo_options['before']));
331
- }
332
- }
333
- }
334
- if ($hefo_post_bottom) {
335
- $value = get_post_meta($post->ID, 'hefo_after', true);
336
- if ($value != '1') {
337
- if (isset($hefo_options['mobile_after_enabled']) && $hefo_is_mobile) {
338
- $after = hefo_execute(hefo_replace($hefo_options['mobile_after']));
339
- } else {
340
- $after = hefo_execute(hefo_replace($hefo_options['after']));
341
- }
342
- }
343
- }
344
  }
345
-
346
- // Rules
347
-
348
-
349
-
350
- for ($i = 1; $i <= 5; $i++) {
351
- if (empty($hefo_options['inner_tag_' . $i])) {
352
- continue;
353
- }
354
- $prefix = '';
355
- if ($hefo_is_mobile && isset($hefo_options['mobile_inner_enabled_' . $i])) {
356
- $prefix = 'mobile_';
357
- }
358
- $skip = trim($hefo_options['inner_skip_' . $i]);
359
- if (empty($skip)) {
360
- $skip = 0;
361
- } else if (substr($skip, -1) == '%') {
362
- $skip = (intval($skip) * strlen($content) / 100);
363
- }
364
-
365
- if ($hefo_options['inner_pos_' . $i] == 'after') {
366
- $res = hefo_insert_after($content, hefo_execute($hefo_options[$prefix . 'inner_' . $i]), $hefo_options['inner_tag_' . $i], $skip);
367
- } else {
368
- $res = hefo_insert_before($content, hefo_execute($hefo_options[$prefix . 'inner_' . $i]), $hefo_options['inner_tag_' . $i], $skip);
369
- }
370
- if (!$res) {
371
- switch ($hefo_options['inner_alt_' . $i]) {
372
- case 'after':
373
- $content = $content . hefo_execute($hefo_options[$prefix . 'inner_' . $i]);
374
- break;
375
- case 'before':
376
- $content = hefo_execute($hefo_options[$prefix . 'inner_' . $i]) . $content;
377
- }
378
  }
379
  }
380
-
381
- return $before . $content . $after;
382
- } else {
383
- return $content;
384
  }
 
 
385
  }
386
 
387
  function hefo_insert_before(&$content, $what, $marker, $starting_from = 0) {
@@ -427,8 +308,8 @@ function hefo_the_excerpt($content) {
427
  global $hefo_options, $post, $wpdb, $hefo_count;
428
  $hefo_count++;
429
  if (is_category() || is_tag()) {
430
- $before = hefo_execute(hefo_replace($hefo_options['excerpt_before']));
431
- $after = hefo_execute(hefo_replace($hefo_options['excerpt_after']));
432
 
433
  return $before . $content . $after;
434
  } else {
@@ -439,61 +320,18 @@ function hefo_the_excerpt($content) {
439
  function hefo_replace($buffer) {
440
  global $hefo_options, $post;
441
 
442
- if (empty($buffer)) {
443
- return '';
444
- }
445
-
446
  for ($i = 1; $i <= 5; $i++) {
447
- if (!isset($hefo_options['snippet_' . $i])) {
448
- $hefo_options['snippet_' . $i] = '';
449
- }
450
  $buffer = str_replace('[snippet_' . $i . ']', $hefo_options['snippet_' . $i], $buffer);
451
  }
452
 
453
- // For 404 pages and maybe others...
454
- if (!is_object($post)) {
455
- return $buffer;
456
- }
457
-
458
- $images_url = plugins_url('images', 'header-footer/plugin.php');
459
- $permalink = urlencode(get_permalink());
460
- $title = urlencode($post->post_title);
461
- $buffer = str_replace('[images_url]', $images_url, $buffer);
462
-
463
- $facebook_url = 'https://www.facebook.com/sharer/sharer.php?u=' . $permalink;
464
- $buffer = str_replace('[facebook_share_url]', $facebook_url, $buffer);
465
-
466
- // Twitter
467
- $twitter_url = 'http://twitter.com/intent/tweet?text=' . $title;
468
- $twitter_url .= '&url=' . $permalink;
469
- $buffer = str_replace('[twitter_share_url]', $twitter_url, $buffer);
470
-
471
- // Google
472
- $google_url = 'https://plus.google.com/share?url=' . $permalink;
473
- $buffer = str_replace('[google_share_url]', $google_url, $buffer);
474
-
475
- // Pinterest
476
- $pinterest_url = 'http://www.pinterest.com/pin/create/button/?url=' . $permalink;
477
- $image_id = function_exists('get_post_thumbnail_id') ? get_post_thumbnail_id($post->ID) : false;
478
- if ($image_id) {
479
- $image = wp_get_attachment_image_src($image_id, 'full');
480
- $pinterest_url .= '&media=' . urlencode($image[0]);
481
- }
482
- $pinterest_url .= '&description=' . $title;
483
- $buffer = str_replace('[pinterest_share_url]', $pinterest_url, $buffer);
484
-
485
- $linkedin_url = 'http://www.linkedin.com/shareArticle?mini=true&url=' . $permalink;
486
- $linkedin_url .= '&title=' . $title . '&source=' . urlencode(get_option('blogname'));
487
- $buffer = str_replace('[linkedin_share_url]', $linkedin_url, $buffer);
488
-
489
  return $buffer;
490
  }
491
 
492
  function hefo_execute($buffer) {
493
  global $post;
494
- if (empty($buffer)) {
495
- return '';
496
- }
497
  if (apply_filters('hefo_php_exec', true)) {
498
  ob_start();
499
  eval('?>' . $buffer);
@@ -501,3 +339,14 @@ function hefo_execute($buffer) {
501
  }
502
  return $buffer;
503
  }
 
 
 
 
 
 
 
 
 
 
 
4
  Plugin Name: Head, Footer and Post Injections
5
  Plugin URI: http://www.satollo.net/plugins/header-footer
6
  Description: Header and Footer lets to add html/javascript code to the head and footer and posts of your blog. Some examples are provided on the <a href="http://www.satollo.net/plugins/header-footer">official page</a>.
7
+ Version: 3.1.4
8
  Author: Stefano Lissa
9
  Author URI: http://www.satollo.net
10
  Disclaimer: Use at your own risk. No warranty expressed or implied is provided.
11
  */
12
 
13
  /*
14
+ Copyright 2008-2020 Stefano Lissa (stefano@satollo.net)
15
 
16
  This program is free software; you can redistribute it and/or modify
17
  it under the terms of the GNU General Public License as published by
28
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
  */
30
 
31
+ defined('ABSPATH') || exit;
32
+
33
  $hefo_options = get_option('hefo', array());
34
 
35
  $hefo_is_mobile = false;
40
  }
41
 
42
  if (is_admin()) {
43
+ require_once dirname(__FILE__) . '/admin/admin.php';
44
  }
45
 
46
  if (isset($hefo_options['disable_css_id'])) {
59
  add_filter('style_loader_tag', 'hefo_style_loader_tag');
60
  }
61
 
62
+ register_activation_hook(__FILE__, function () {
63
+ $options = get_option('hefo');
64
+ if (!is_array($options)) {
65
+ $options = array();
66
+ }
67
+ $options = array_merge(array('after' => '', 'before' => '', 'head' => '', 'body' => '', 'head_home' => '', 'footer' => ''), $options);
68
+ for ($i = 1; $i <= 5; $i++) {
69
+ $options['snippet_' . $i] = '';
70
+ $options['generic_' . $i] = '';
71
+ }
72
+ $options['updated'] = time(); // Force an update if the old options match (otherwise the autoload is not saved)
73
+ update_option('hefo', $options, true);
74
+ });
75
+
76
+ register_deactivation_hook(__FILE__, function () {
77
+ $options = get_option('hefo');
78
+ if ($options) {
79
+ $options['updated'] = time();
80
+ update_option('hefo', $options, false);
81
+ }
82
+ });
83
+
84
+ add_action('template_redirect', 'hefo_template_redirect', 1);
85
 
86
  $hefo_body_block = '';
87
  $hefo_generic_block = array();
89
  function hefo_template_redirect() {
90
  global $hefo_body_block, $hefo_generic_block, $hefo_options, $hefo_is_mobile;
91
 
92
+
93
  if ($hefo_is_mobile && isset($hefo_options['mobile_body_enabled'])) {
94
+ $hefo_body_block = hefo_execute_option('mobile_body');
95
  } else {
96
+ $hefo_body_block = hefo_execute_option('body');
97
  }
98
+
99
  for ($i = 1; $i <= 5; $i++) {
100
  if ($hefo_is_mobile && isset($hefo_options['mobile_generic_enabled_' . $i])) {
101
+ $hefo_generic_block[$i] = hefo_execute_option('mobile_generic_' . $i);
 
102
  } else {
103
+ $hefo_generic_block[$i] = hefo_execute_option('generic_' . $i);
 
104
  }
105
  }
106
+
107
  ob_start('hefo_callback');
108
  }
109
 
150
  if (isset($hefo_options['disable_wp_shortlink_wp_head'])) {
151
  remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
152
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  }
154
 
155
  add_action('wp_head', 'hefo_wp_head_post', 11);
156
 
157
  function hefo_wp_head_post() {
 
 
158
  if (is_front_page()) {
159
+ hefo_execute_option('head_home', true);
160
  }
161
 
162
+ hefo_execute_option('head', true);
 
 
 
 
 
 
 
 
163
  }
164
 
165
+ add_action('amp_post_template_head', function () {
166
+ echo hefo_execute_option('amp_head', true);
167
+ }, 100);
168
 
 
 
 
 
 
 
169
 
170
+ add_action('amp_post_template_css', function () {
171
+ hefo_execute_option('amp_css', true);
172
+ }, 100);
 
 
 
173
 
174
+ add_action('amp_post_template_body_open', function () {
175
+ hefo_execute_option('amp_body', true);
176
+ }, 100);
177
 
178
+ add_action('amp_post_template_footer', function () {
179
+ hefo_execute_option('amp_footer', true);
180
+ }, 100);
 
 
 
181
 
182
  add_action('wp_footer', 'hefo_wp_footer');
183
 
184
  function hefo_wp_footer() {
185
+ global $hefo_is_mobile;
186
 
187
  if ($hefo_is_mobile && isset($hefo_options['mobile_footer_enabled'])) {
188
+ hefo_execute_option('mobile_footer', true);
 
 
 
 
 
 
 
 
 
 
189
  } else {
190
+ hefo_execute_option('footer', true);
191
  }
192
  }
193
 
194
+ add_action('the_content', 'hefo_the_content');
 
 
 
 
 
 
 
 
 
 
 
 
 
195
 
196
+ function hefo_the_content($content) {
197
+ global $hefo_options, $wpdb, $post, $hefo_is_mobile;
198
 
199
+ $before = '';
200
+ $after = '';
201
 
202
+ // AMP detection
203
+ if (function_exists('is_amp_endpoint') && is_amp_endpoint()) {
204
+ $before = hefo_execute_option('amp_post_before');
205
+ $after = hefo_execute_option('amp_post_after');
206
+ return $before . $content . $after;
207
  }
 
 
 
 
 
 
208
 
209
+ if (!is_singular()) {
210
+ return $content;
 
 
211
  }
212
+ $type = '';
213
 
214
+ if (is_page() && !isset($hefo_options['page_use_post'])) {
215
+ $type = 'page_';
216
+ }
 
217
 
218
+ if ($hefo_is_mobile && isset($hefo_options['mobile_' . $type . 'before_enabled'])) {
219
+ $before = hefo_execute_option('mobile_' . $type . 'before');
220
  } else {
221
+ $before = hefo_execute_option($type . 'before');
222
  }
 
 
 
223
 
224
+ if ($hefo_is_mobile && isset($hefo_options['mobile_' . $type . 'after_enabled'])) {
225
+ $after = hefo_execute_option('mobile_' . $type . 'after');
 
 
 
226
  } else {
227
+ $after = hefo_execute_option($type . 'after');
228
  }
 
 
 
229
 
230
+ // Rules
 
 
 
 
231
 
 
 
232
 
 
 
233
 
234
+ for ($i = 1; $i <= 5; $i++) {
235
+ if (empty($hefo_options['inner_tag_' . $i])) {
236
+ continue;
237
+ }
238
+ $prefix = '';
239
+ if ($hefo_is_mobile && isset($hefo_options['mobile_inner_enabled_' . $i])) {
240
+ $prefix = 'mobile_';
241
+ }
242
+ $skip = trim($hefo_options['inner_skip_' . $i]);
243
+ if (empty($skip)) {
244
+ $skip = 0;
245
+ } else if (substr($skip, -1) == '%') {
246
+ $skip = (intval($skip) * strlen($content) / 100);
247
+ }
248
 
249
+ if ($hefo_options['inner_pos_' . $i] == 'after') {
250
+ $res = hefo_insert_after($content, hefo_execute_option($prefix . 'inner_' . $i), $hefo_options['inner_tag_' . $i], $skip);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251
  } else {
252
+ $res = hefo_insert_before($content, hefo_execute_option($prefix . 'inner_' . $i), $hefo_options['inner_tag_' . $i], $skip);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  }
254
+ if (!$res) {
255
+ switch ($hefo_options['inner_alt_' . $i]) {
256
+ case 'after':
257
+ $content = $content . hefo_execute_option($prefix . 'inner_' . $i);
258
+ break;
259
+ case 'before':
260
+ $content = hefo_execute_option($prefix . 'inner_' . $i) . $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
261
  }
262
  }
 
 
 
 
263
  }
264
+
265
+ return $before . $content . $after;
266
  }
267
 
268
  function hefo_insert_before(&$content, $what, $marker, $starting_from = 0) {
308
  global $hefo_options, $post, $wpdb, $hefo_count;
309
  $hefo_count++;
310
  if (is_category() || is_tag()) {
311
+ $before = hefo_execute_option('excerpt_before');
312
+ $after = hefo_execute_option('excerpt_after');
313
 
314
  return $before . $content . $after;
315
  } else {
320
  function hefo_replace($buffer) {
321
  global $hefo_options, $post;
322
 
 
 
 
 
323
  for ($i = 1; $i <= 5; $i++) {
324
+ if (empty($hefo_options['snippet_' . $i]))
325
+ continue;
 
326
  $buffer = str_replace('[snippet_' . $i . ']', $hefo_options['snippet_' . $i], $buffer);
327
  }
328
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
  return $buffer;
330
  }
331
 
332
  function hefo_execute($buffer) {
333
  global $post;
334
+
 
 
335
  if (apply_filters('hefo_php_exec', true)) {
336
  ob_start();
337
  eval('?>' . $buffer);
339
  }
340
  return $buffer;
341
  }
342
+
343
+ function hefo_execute_option($key, $echo = false) {
344
+ global $hefo_options, $wpdb, $post;
345
+ if (empty($hefo_options[$key]))
346
+ return '';
347
+ $buffer = hefo_replace($hefo_options[$key]);
348
+ if ($echo)
349
+ echo hefo_execute($buffer);
350
+ else
351
+ return hefo_execute($buffer);
352
+ }
readme.txt CHANGED
@@ -1,8 +1,8 @@
1
  === Head, Footer and Post Injections ===
2
  Tags: header, footer, blog, page, single, post, head, tracking, facebook, og meta tag, open graph, ads, adsense, injections, analytics, amp, pixel
3
  Requires at least: 3.0
4
- Tested up to: 5.2
5
- Stable tag: 3.1.3
6
  Donate link: http://www.satollo.net/donations
7
  Contributors: satollo
8
 
@@ -34,7 +34,7 @@ without loosing the code injected!
34
  = AMP =
35
 
36
  A new AMP dedicated section compatible with [AMP plugin](https://wordpress.org/plugins/amp) lets you to inject specific codes in
37
- AMP pages.
38
 
39
  = Post Top and Bottom Codes =
40
 
@@ -69,10 +69,13 @@ Other plugins by Stefano Lissa:
69
  * [Hyper Cache](http://www.satollo.net/plugins/hyper-cache)
70
  * [Newsletter](http://www.thenewsletterplugin.com)
71
  * [Include Me](http://www.satollo.net/plugins/include-me)
72
- * [Comment Plus](http://www.satollo.net/plugins/comment-plus)
73
  * [Thumbnails](http://www.satollo.net/plugins/thumbnails)
74
  * [Ads for bbPress](http://www.satollo.net/plugins/ads-bbpress)
75
 
 
 
 
 
76
  == Installation ==
77
 
78
  1. Put the plugin folder into [wordpress_dir]/wp-content/plugins/
@@ -92,6 +95,13 @@ FAQs are answered on [Header and Footer](http://www.satollo.net/plugins/header-f
92
 
93
  == Changelog ==
94
 
 
 
 
 
 
 
 
95
  = 3.1.3 =
96
 
97
  * General compatibility check with latest WP
1
  === Head, Footer and Post Injections ===
2
  Tags: header, footer, blog, page, single, post, head, tracking, facebook, og meta tag, open graph, ads, adsense, injections, analytics, amp, pixel
3
  Requires at least: 3.0
4
+ Tested up to: 5.3.2
5
+ Stable tag: 3.1.4
6
  Donate link: http://www.satollo.net/donations
7
  Contributors: satollo
8
 
34
  = AMP =
35
 
36
  A new AMP dedicated section compatible with [AMP plugin](https://wordpress.org/plugins/amp) lets you to inject specific codes in
37
+ AMP pages. Should be ok even with other AMP plugins.
38
 
39
  = Post Top and Bottom Codes =
40
 
69
  * [Hyper Cache](http://www.satollo.net/plugins/hyper-cache)
70
  * [Newsletter](http://www.thenewsletterplugin.com)
71
  * [Include Me](http://www.satollo.net/plugins/include-me)
 
72
  * [Thumbnails](http://www.satollo.net/plugins/thumbnails)
73
  * [Ads for bbPress](http://www.satollo.net/plugins/ads-bbpress)
74
 
75
+ = Translation =
76
+
77
+ You can contribute to translate this plugin in your language on [WordPress Translate](https://translate.wordpress.org)
78
+
79
  == Installation ==
80
 
81
  1. Put the plugin folder into [wordpress_dir]/wp-content/plugins/
95
 
96
  == Changelog ==
97
 
98
+ = 3.1.4 =
99
+
100
+ * Performance optimization
101
+ * Removed obsolete code
102
+ * Improved AMP support
103
+ * (Temporary) removed metaboxes (they were not working anyway)
104
+
105
  = 3.1.3 =
106
 
107
  * General compatibility check with latest WP