Header and Footer Scripts - Version 2.1.1

Version Description

  • Fixed a bug causing singular post type scripts to appear in archives.
  • Compatibility checked upto WordPress 5.2.2
  • Now require PHP v7.0 at least.
Download this release

Release Info

Developer anand_kumar
Plugin Icon 128x128 Header and Footer Scripts
Version 2.1.1
Comparing to
See all releases

Code changes from version 2.0.0 to 2.1.1

Files changed (5) hide show
  1. inc/meta.php +11 -1
  2. inc/options.php +11 -1
  3. inc/sidebar.php +21 -10
  4. readme.txt +66 -44
  5. shfs.php +51 -77
inc/meta.php CHANGED
@@ -1,4 +1,14 @@
1
- <div class="shfs_meta_control">
 
 
 
 
 
 
 
 
 
 
2
 
3
  <p>
4
  <textarea name="_inpost_head_script[synth_header_script]" rows="5" style="width:98%;"><?php if(!empty($meta['synth_header_script'])) echo $meta['synth_header_script']; ?></textarea>
1
+ <?php
2
+ /**
3
+ * Plugin meta for single post or page type.
4
+ *
5
+ * @package Header and Footer Scripts
6
+ * @author Anand Kumar <anand@anandkumar.net>
7
+ * @copyright Copyright (c) 2013 - 2019, Anand Kumar
8
+ * @link http://digitalliberation.org/plugins/header-and-footer-scripts
9
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
+ */?>
11
+ <div class="shfs_meta_control">
12
 
13
  <p>
14
  <textarea name="_inpost_head_script[synth_header_script]" rows="5" style="width:98%;"><?php if(!empty($meta['synth_header_script'])) echo $meta['synth_header_script']; ?></textarea>
inc/options.php CHANGED
@@ -1,5 +1,15 @@
 
 
 
 
 
 
 
 
 
 
1
  <div class="wrap">
2
- <h2><?php _e( 'Header and Footer Scripts - Options', 'header-and-footer-scripts'); ?> <a class="add-new-h2" target="_blank" href="#"><?php _e( 'Read Tutorial', 'header-and-footer-scripts'); ?></a></h2>
3
 
4
  <hr />
5
  <div id="poststuff">
1
+ <?php
2
+ /**
3
+ * Plugin Options page
4
+ *
5
+ * @package Header and Footer Scripts
6
+ * @author Anand Kumar <anand@anandkumar.net>
7
+ * @copyright Copyright (c) 2013 - 2019, Anand Kumar
8
+ * @link http://digitalliberation.org/plugins/header-and-footer-scripts
9
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
+ */?>
11
  <div class="wrap">
12
+ <h2><?php _e( 'Header and Footer Scripts - Options', 'header-and-footer-scripts'); ?> <a class="add-new-h2" target="_blank" href="<?php echo esc_url( "http://digitalliberation.org/docs/header-and-footer-scripts/?utm_source=wpdash_hfs" ); ?>"><?php _e( 'Read Tutorial', 'header-and-footer-scripts'); ?></a></h2>
13
 
14
  <hr />
15
  <div id="poststuff">
inc/sidebar.php CHANGED
@@ -1,33 +1,44 @@
1
  <?php
2
  /**
3
- * Sidebar for admin info and selfpromotion purposes.
4
- * It incudes links to help docs and support site.
5
- *
6
  *
 
 
 
 
 
7
  */?>
8
  <div id="postbox-container-1" class="postbox-container">
9
 
10
  <div class="postbox">
11
  <h3 class="hndle"><?php _e( 'Need Help?', 'header-and-footer-scripts'); ?></h3>
12
  <div class="inside">
13
- <p><?php _e( 'Read plugin documentation for clarification or how to use the plugin. OR ask your query:', 'header-and-footer-scripts'); ?></p>
14
- <p><strong><a href="http://digitalliberation.org/plugins/header-and-footer-scripts/" target="_blank" class="button"><?php _e('Explore Docs and Support', 'header-and-footer-scripts'); ?></a></strong></p>
15
  </div>
16
  </div>
17
 
18
  <div class="postbox">
19
  <h3 class="hndle"><?php _e( 'Contribute or Donate!', 'header-and-footer-scripts'); ?></h3>
20
  <div class="inside">
21
- <p><?php _e( 'Help us to make this plugin even better. Contribution doesn\'t always mean donation. Please follow the link to know more and contribute.', 'header-and-footer-scripts'); ?></p>
22
- <p><a href="http://digitalliberation.org/contribute?utm_source=wpdash" target="_blank" class="button"><?php _e( 'Contribute', 'header-and-footer-scripts'); ?></a></p>
 
 
 
 
 
 
 
 
23
  </div>
24
  </div>
25
 
26
  <div class="postbox">
27
- <h3 class="hndle"><?php _e( 'More', 'header-and-footer-scripts'); ?></h3>
28
  <div class="inside">
29
- <p><?php _e( 'You may find more plugins and themes here.', 'header-and-footer-scripts'); ?></p>
30
- <p><a href="http://digitalliberation.org/?utm_source=wpdash" target="_blank" class="button"><?php _e( 'Contribute', 'header-and-footer-scripts'); ?></a></p>
31
  </div>
32
  </div>
33
 
1
  <?php
2
  /**
3
+ * Plugin info and self promotion.
 
 
4
  *
5
+ * @package Header and Footer Scripts
6
+ * @author Anand Kumar <anand@anandkumar.net>
7
+ * @copyright Copyright (c) 2013 - 2019, Anand Kumar
8
+ * @link http://digitalliberation.org/plugins/header-and-footer-scripts
9
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10
  */?>
11
  <div id="postbox-container-1" class="postbox-container">
12
 
13
  <div class="postbox">
14
  <h3 class="hndle"><?php _e( 'Need Help?', 'header-and-footer-scripts'); ?></h3>
15
  <div class="inside">
16
+ <p><?php _e( 'Read plugin documentation for clarification or how to use it. OR just ask your query.', 'header-and-footer-scripts'); ?></p>
17
+ <p><strong><a href="<?php echo esc_url( "http://digitalliberation.org/plugins/header-and-footer-scripts/?utm_source=wpdash_hfs" ); ?>" class="button"><?php _e('Explore Docs and Support', 'header-and-footer-scripts'); ?></a></strong></p>
18
  </div>
19
  </div>
20
 
21
  <div class="postbox">
22
  <h3 class="hndle"><?php _e( 'Contribute or Donate!', 'header-and-footer-scripts'); ?></h3>
23
  <div class="inside">
24
+ <p><?php _e( 'Help us to make this plugin even better. Contributions not necessarily be monetary. Please follow the link to know more and contribute.', 'header-and-footer-scripts'); ?></p>
25
+ <p><a href="<?php echo esc_url( "http://digitalliberation.org/contribute/?utm_source=wpdash_hfs" ); ?>" class="button"><?php _e( 'Contribute', 'header-and-footer-scripts'); ?></a></p>
26
+ </div>
27
+ </div>
28
+
29
+ <div class="postbox">
30
+ <h3 class="hndle"><?php _e( 'Rate 5 Stars', 'header-and-footer-scripts'); ?></h3>
31
+ <div class="inside">
32
+ <p><?php _e( 'Find this plugin useful rate it 5 stars and leave a nice little comment at wordpress.org. I would really appreciate that.', 'header-and-footer-scripts'); ?></p>
33
+ <p><a href="<?php echo esc_url( "https://wordpress.org/support/plugin/header-and-footer-scripts/reviews/?filter=5#new-post" ); ?>" class="button"><?php _e( 'Rate 5 Stars', 'header-and-footer-scripts'); ?></a></p>
34
  </div>
35
  </div>
36
 
37
  <div class="postbox">
38
+ <h3 class="hndle"><?php _e( 'Join Our Community', 'header-and-footer-scripts'); ?></h3>
39
  <div class="inside">
40
+ <p><?php _e( 'We are small WordPress community who welcomes you to join us. Here you will find and share more plugins and themes or even ideas. Ideas are not limited to WordPress. It could be vague or liberal. This is why we are "Digital Liberation .ORG', 'header-and-footer-scripts'); ?></p>
41
+ <p><a href="<?php echo esc_url( "http://digitalliberation.org/?utm_source=wpdash_hfs" ); ?>" class="button"><?php _e( 'Join Digital Liberation', 'header-and-footer-scripts'); ?></a></p>
42
  </div>
43
  </div>
44
 
readme.txt CHANGED
@@ -1,79 +1,101 @@
1
  === Header and Footer Scripts ===
2
 
3
  Contributors: digitalliberation, anand_kumar
4
- Donate link: http://www.blogsynthesis.com/donate/
5
  Tags: head, header, footer, scripts, post, admin
6
- Requires at least: 3.6
7
- Tested up to: 4.9.1
8
- Stable tag: 2.0.0
9
- Requires PHP: 5.3
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
13
- Header and Footer Scripts plugin enables you to add scripts to WordPress header and footer.
14
 
15
  == Description ==
 
16
 
17
- Many WordPress Themes do not have any options to insert header and footer scripts in your site `<head>` or `<footer>`. It helps you to keep yourself from theme lock. But, sometimes it also causes some pain for many. like where should I insert Google Analytics code (or any other web-analytics codes). This plugin is one stop and lightweight solution for that. With this "Header and Footer Script" plugin will be able to inject HTML tags, JS and CSS codes to `<head>` and `<footer>` easily.
18
 
19
- = Benefits of the plugin: =
20
- * You will be able to [insert Google Analytics][1] or other Web-analytics code, meta-informations, CSS and JS codes to `<head>`
21
- * You will be able to insert html and/or JavaScript codes to footer of your site. Good place for [Clicky Web Analytics][2], Twitter, Facebook or any other social media script.
22
- * Easily insert codes to single post and page headers, in addition to default codes.
23
 
24
- Please note, If the plugin is not working check for `wp_head` and `wp_footer` hooks. [more information][3] or [ask for support][7].
 
 
25
 
26
- = Important Links =
27
- * **[Latest FAQs and Help Article][4]**
28
- * **[GitHub Repo][8]**
29
- * **[Support][5]**
30
- * **[Donate][6]**
31
-
32
- PS: For any troubleshooting ask your question in the BlogSynthesis Forums. I can't check WordPress forums regularly.
33
-
34
- [1]: http://www.blogsynthesis.com/google-analytics-to-wordpress/#utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wpshfs
35
- [2]: http://bit.ly/ClickyWebAnalytics
36
- [3]: http://www.blogsynthesis.com/plugins/header-and-footer-scripts/#FAQs
37
- [4]: http://www.blogsynthesis.com/plugins/header-and-footer-scripts/#utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wpshfs
38
- [5]: http://www.blogsynthesis.com/support/#utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wpshfs
39
- [6]: http://www.blogsynthesis.com/donate/
40
- [7]: http://www.blogsynthesis.com/support/#utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wpshfs
41
- [8]: https://github.com/anandkumar/header-and-footer-scripts
42
 
43
- == Installation ==
 
 
44
 
45
- Upload the plugin to `/wp-content/plugins` and activate. OR Search "Header and Footer Scripts" from `WP Dashbard --> Plugins --> Add New` then hit Install
 
 
 
46
 
47
- == Screenshots ==
48
- 1. Access this page from `Dashboard --> Settings --> Header and Footer Scripts`
49
- 2. This box will appear below somewhere below on compose window on posts and pages.
50
 
51
- == Frequently Asked Questions ==
 
 
 
 
 
 
52
 
53
- **Q. I need plugin support. Where should I ask questions?**
 
 
 
 
54
 
55
- A. You may ask support related questions at (http://digitalliberation.org/wordpress/#utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wpshfs). Meanwhile, you should take a look on [this FAQ](http://www.blogsynthesis.com/plugins/header-and-footer-scripts/#utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wpshfs) This page will have most latest FAQs (that depends upon what user asks.) Read that article before asking any questions. It may solve your questions and save time.
 
 
 
 
56
 
57
- **How do I disable the site-wide header and footer injection or the post specific header injection?**
 
 
 
58
 
59
- A. To keep this plugin simple we have not added any such options. You may try another plugin for more or less functionality.
60
 
61
- **Q: I need more functionality. What should I do?**
 
 
62
 
63
- A. If you want more functionality then check [Enhanced Header/Footer Scripts](http://bit.ly/wp-ehfi).
64
 
65
- **Q: I need less functionality. What should I do?**
66
 
67
- A. If you are looking for less functionality then check [Insert Header and Footers](http://bit.ly/wpb-ihf) plugin.
68
 
69
  **Q: Is there any paid version of the plugin available?**
70
 
71
- A. No, There is no paid version of this plugin is available.
72
 
73
  == Changelog ==
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  = 2.0.0 =
76
- * Visual Improvements
77
  * better directory structure.
78
 
79
  = 1.3.4 =
1
  === Header and Footer Scripts ===
2
 
3
  Contributors: digitalliberation, anand_kumar
4
+ Donate link: https://www.digitalliberation.org/contribute/?utm_source=wphfs_donate_link
5
  Tags: head, header, footer, scripts, post, admin
6
+ Requires at least: 4.0
7
+ Tested up to: 5.0
8
+ Stable tag: 2.1.1
9
+ Requires PHP: 7.0
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
13
+ Header and Footer Scripts plugin allows you to add scripts to WordPress site's <head> and just before closing <body> tag.
14
 
15
  == Description ==
16
+ If you are running a WordPress site then sooner or later you need to insert some kind of code to your website. It is most likley a web analytics code like Google Analytics or may be social media script or some CSS stylesheet or may be Custom fonts. This plugin will do all the magic. Even if you want to insert those codes in a custom post type.
17
 
18
+ All you have to do is adding appropriate html code.
19
 
20
+ Don't forget to wrap your code with proper tags.
 
 
 
21
 
22
+ <script type="text/javascript">
23
+ YOUR JS CODE HERE
24
+ </script>
25
 
26
+ Or for CSS:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ <style type="text/css">
29
+ YOUR CSS CODE HERE
30
+ </style>
31
 
32
+ = Why use this plugin: =
33
+ * To insert CSS and JavaScript codes to `<head>` or before `</body>`.
34
+ * To insert code to `<head>` of any single page or post.
35
+ * To insert code to Custom Post Type [New Feature].
36
 
37
+ The plugin should be compatible with WooCommerce.
 
 
38
 
39
+ = What it does not offer =
40
+ * You can't insert/execute PHP codes.
41
+
42
+ Almost all WordPress theme do support this "Header and Footer Scripts" plugin. If the codes are not appearing in your site [ask for support] or look at your theme file if they have standard `wp_head` and `wp_footer` hooks.
43
+
44
+ = Important Links =
45
+ For furhter information you are welcomed to follow these links:
46
 
47
+ * **[Read Documentation][1]**
48
+ * **[Get Support][2]**
49
+ * **[GitHub Repository][3]**
50
+ * **[Contribute][4]**
51
+ * **[Digital Liberation - Blog][5]**
52
 
53
+ [1]: https://www.digitalliberation.org/docs/header-and-footer-scripts/?utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wp_hfs
54
+ [2]: https://forums.digitalliberation.org/?utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wp_hfs
55
+ [3]: https://github.com/anandkumar/header-and-footer-scripts
56
+ [4]: https://www.digitalliberation.org/contribute/?utm_source=wporg&utm_medium=donation_link&utm_campaign=wp_hfs
57
+ [5]: https://www.digitalliberation.org/blog/?utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wp_hfs
58
 
59
+ == Installation ==
60
+ There is nothing special about installation of this plugin. It is as simple as uploading the plugin files to your plugins directory.
61
+
62
+ Upload the plugin to `/wp-content/plugins` and activate. OR Search "Header and Footer Scripts" from `WP Dashbard --> Plugins --> Add New` then hit Install and then activate.
63
 
64
+ Once the plugin is activated you will see "Header and Footer Scripts" menu item under setting of WordPress dashboard. Also a meta box on Post and Page edit page.
65
 
66
+ == Screenshots ==
67
+ 1. Access this page from `Dashboard --> Settings --> Header and Footer Scripts`
68
+ 2. This box will appear below the compose box on posts and pages. If not please refer to [our docs][4] if it's not there.
69
 
70
+ == Frequently Asked Questions ==
71
 
72
+ **Q. How could I access support and troubleshoot problem?**
73
 
74
+ A. I couldn't handle wp.org forums on regular basis. You are suggested to visit [Digital Liberation](https://digitalliberation.org/) for more updated plugin documentation and troubleshoot your problem.
75
 
76
  **Q: Is there any paid version of the plugin available?**
77
 
78
+ A. Nope, There is none. If you need more feature send us feedback or feature request.
79
 
80
  == Changelog ==
81
 
82
+ = 2.1.1 =
83
+ * Fixed a bug causing singular post type scripts to appear in archives.
84
+ * Compatibility checked upto WordPress 5.2.2
85
+ * Now require PHP v7.0 at least.
86
+
87
+ = 2.1.0 =
88
+ * Support to Custom Post Type (CPT).
89
+ * Improved ReadMe
90
+
91
+ = 2.0.1 =
92
+ * Uniform Coding style.
93
+ * Improved Translatable strings.
94
+ * Fixed Links
95
+ * Code Cleanup
96
+
97
  = 2.0.0 =
98
+ * Visual Improvements.
99
  * better directory structure.
100
 
101
  = 1.3.4 =
shfs.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /**
3
  * Plugin Name: Header and Footer Scripts
4
- * Plugin URI: http://digitalliberation.org/plugins/header-and-footer-scripts
5
- * Description: Allows you to insert code or text in the header or footer of your WordPress blog
6
- * Version: 2.0.0
7
- * Author: Anand Kumar
8
- * Author URI: http://www.anandkumar.net
9
  * Text Domain: header-and-footer-scripts
10
  * Domain Path: /lang
11
  * License: GPLv2 or later
@@ -13,7 +13,7 @@
13
 
14
  /*
15
  Header and Footer Scripts
16
- Copyright (C) 2013 - 2018, Anand Kumar <anand@anandkumar.net>
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License, version 2, as
@@ -45,8 +45,8 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
45
 
46
  }
47
 
48
-
49
  function init() {
 
50
  load_plugin_textdomain( 'header-and-footer-scripts', false, dirname( plugin_basename ( __FILE__ ) ).'/lang' );
51
  }
52
 
@@ -56,9 +56,8 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
56
  register_setting( 'header-and-footer-scripts', 'shfs_insert_header', 'trim' );
57
  register_setting( 'header-and-footer-scripts', 'shfs_insert_footer', 'trim' );
58
 
59
- // add meta box to singgular post types
60
- foreach (array('post','page') as $type)
61
- {
62
  add_meta_box('shfs_all_post_meta', esc_html__('Insert Script to &lt;head&gt;', 'header-and-footer-scripts'), 'shfs_meta_setup', $type, 'normal', 'high');
63
  }
64
 
@@ -72,14 +71,14 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
72
 
73
  function wp_head() {
74
  $meta = get_option( 'shfs_insert_header', '' );
75
- if ( $meta != '' ) {
76
- echo $meta, "\n";
77
- }
78
 
79
  $shfs_post_meta = get_post_meta( get_the_ID(), '_inpost_head_script' , TRUE );
80
- if ( $shfs_post_meta != '' ) {
81
- echo $shfs_post_meta['synth_header_script'], "\n";
82
- }
83
 
84
  }
85
 
@@ -89,33 +88,10 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
89
  $text = convert_smilies( $text );
90
  $text = do_shortcode( $text );
91
 
92
- if ( $text != '' ) {
93
- echo $text, "\n";
94
- }
95
- }
96
- }
97
-
98
-
99
- function fetch_rss_items( $num, $feed ) {
100
- include_once( ABSPATH . WPINC . '/feed.php' );
101
- $rss = fetch_feed( $feed );
102
-
103
- // Bail if feed doesn't work
104
- if ( !$rss || is_wp_error( $rss ) )
105
- return false;
106
-
107
- $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
108
-
109
- // If the feed was erroneous
110
- if ( !$rss_items ) {
111
- $md5 = md5( $feed );
112
- delete_transient( 'feed_' . $md5 );
113
- delete_transient( 'feed_mod_' . $md5 );
114
- $rss = fetch_feed( $feed );
115
- $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
116
  }
117
-
118
- return $rss_items;
119
  }
120
 
121
  function shfs_options_panel() {
@@ -124,8 +100,7 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
124
  }
125
  }
126
 
127
- function shfs_meta_setup()
128
- {
129
  global $post;
130
 
131
  // using an underscore, prevents the meta variable
@@ -139,8 +114,7 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
139
  echo '<input type="hidden" name="shfs_post_meta_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
140
  }
141
 
142
- function shfs_post_meta_save($post_id)
143
- {
144
  // authentication checks
145
 
146
  // make sure data came from our meta box
@@ -148,13 +122,16 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
148
  || !wp_verify_nonce($_POST['shfs_post_meta_noncename'],__FILE__)) return $post_id;
149
 
150
  // check user permissions
151
- if ($_POST['post_type'] == 'page')
152
- {
153
- if (!current_user_can('edit_page', $post_id)) return $post_id;
154
- }
155
- else
156
- {
157
- if (!current_user_can('edit_post', $post_id)) return $post_id;
 
 
 
158
  }
159
 
160
  $current_data = get_post_meta($post_id, '_inpost_head_script', TRUE);
@@ -163,50 +140,47 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
163
 
164
  shfs_post_meta_clean($new_data);
165
 
166
- if ($current_data)
167
- {
168
  if (is_null($new_data)) delete_post_meta($post_id,'_inpost_head_script');
 
169
  else update_post_meta($post_id,'_inpost_head_script',$new_data);
170
- }
171
- elseif (!is_null($new_data))
172
- {
173
  add_post_meta($post_id,'_inpost_head_script',$new_data,TRUE);
 
174
  }
175
 
176
  return $post_id;
177
  }
178
 
179
- function shfs_post_meta_clean(&$arr)
180
- {
181
- if (is_array($arr))
182
- {
183
- foreach ($arr as $i => $v)
184
- {
185
- if (is_array($arr[$i]))
186
- {
187
  shfs_post_meta_clean($arr[$i]);
188
 
189
- if (!count($arr[$i]))
190
- {
191
  unset($arr[$i]);
192
  }
193
- }
194
- else
195
- {
196
- if (trim($arr[$i]) == '')
197
- {
198
  unset($arr[$i]);
199
  }
200
  }
201
  }
202
 
203
- if (!count($arr))
204
- {
205
  $arr = NULL;
206
  }
207
  }
208
  }
209
 
210
- $shfs_header_and_footer_scripts = new HeaderAndFooterScripts();
211
-
212
  }
1
  <?php
2
  /**
3
  * Plugin Name: Header and Footer Scripts
4
+ * Plugin URI: http://digitalliberation.org/plugins/header-and-footer-scripts/?utm_source=wphfs_plugin_uri
5
+ * Description: Allows you to insert code or text in the header or footer of your WordPress site
6
+ * Version: 2.1.1
7
+ * Author: Digital Liberation
8
+ * Author URI: http://digitalliberation.org/?utm_source=wphfs_author_uri
9
  * Text Domain: header-and-footer-scripts
10
  * Domain Path: /lang
11
  * License: GPLv2 or later
13
 
14
  /*
15
  Header and Footer Scripts
16
+ Copyright (C) 2013 - 2019, Anand Kumar <anand@anandkumar.net>
17
 
18
  This program is free software; you can redistribute it and/or modify
19
  it under the terms of the GNU General Public License, version 2, as
45
 
46
  }
47
 
 
48
  function init() {
49
+
50
  load_plugin_textdomain( 'header-and-footer-scripts', false, dirname( plugin_basename ( __FILE__ ) ).'/lang' );
51
  }
52
 
56
  register_setting( 'header-and-footer-scripts', 'shfs_insert_header', 'trim' );
57
  register_setting( 'header-and-footer-scripts', 'shfs_insert_footer', 'trim' );
58
 
59
+ // add meta box to all post types
60
+ foreach ( get_post_types( '', 'names' ) as $type ) {
 
61
  add_meta_box('shfs_all_post_meta', esc_html__('Insert Script to &lt;head&gt;', 'header-and-footer-scripts'), 'shfs_meta_setup', $type, 'normal', 'high');
62
  }
63
 
71
 
72
  function wp_head() {
73
  $meta = get_option( 'shfs_insert_header', '' );
74
+ if ( $meta != '' ) {
75
+ echo $meta, "\n";
76
+ }
77
 
78
  $shfs_post_meta = get_post_meta( get_the_ID(), '_inpost_head_script' , TRUE );
79
+ if ( is_singular() && $shfs_post_meta != '' ) {
80
+ echo $shfs_post_meta['synth_header_script'], "\n";
81
+ }
82
 
83
  }
84
 
88
  $text = convert_smilies( $text );
89
  $text = do_shortcode( $text );
90
 
91
+ if ( $text != '' ) {
92
+ echo $text, "\n";
93
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  }
 
 
95
  }
96
 
97
  function shfs_options_panel() {
100
  }
101
  }
102
 
103
+ function shfs_meta_setup() {
 
104
  global $post;
105
 
106
  // using an underscore, prevents the meta variable
114
  echo '<input type="hidden" name="shfs_post_meta_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
115
  }
116
 
117
+ function shfs_post_meta_save($post_id) {
 
118
  // authentication checks
119
 
120
  // make sure data came from our meta box
122
  || !wp_verify_nonce($_POST['shfs_post_meta_noncename'],__FILE__)) return $post_id;
123
 
124
  // check user permissions
125
+ if ( $_POST['post_type'] == 'page' ) {
126
+
127
+ if (!current_user_can('edit_page', $post_id))
128
+ return $post_id;
129
+
130
+ } else {
131
+
132
+ if (!current_user_can('edit_post', $post_id))
133
+ return $post_id;
134
+
135
  }
136
 
137
  $current_data = get_post_meta($post_id, '_inpost_head_script', TRUE);
140
 
141
  shfs_post_meta_clean($new_data);
142
 
143
+ if ($current_data) {
144
+
145
  if (is_null($new_data)) delete_post_meta($post_id,'_inpost_head_script');
146
+
147
  else update_post_meta($post_id,'_inpost_head_script',$new_data);
148
+
149
+ } elseif (!is_null($new_data)) {
150
+
151
  add_post_meta($post_id,'_inpost_head_script',$new_data,TRUE);
152
+
153
  }
154
 
155
  return $post_id;
156
  }
157
 
158
+ function shfs_post_meta_clean(&$arr) {
159
+
160
+ if (is_array($arr)) {
161
+
162
+ foreach ($arr as $i => $v) {
163
+
164
+ if (is_array($arr[$i])) {
 
165
  shfs_post_meta_clean($arr[$i]);
166
 
167
+ if (!count($arr[$i])) {
 
168
  unset($arr[$i]);
169
  }
170
+
171
+ } else {
172
+
173
+ if (trim($arr[$i]) == '') {
 
174
  unset($arr[$i]);
175
  }
176
  }
177
  }
178
 
179
+ if (!count($arr)) {
 
180
  $arr = NULL;
181
  }
182
  }
183
  }
184
 
185
+ $shfs_header_and_footer_scripts = new HeaderAndFooterScripts();
 
186
  }