Version Description
- Support to Custom Post Type (CPT).
- Improved ReadMe
Download this release
Release Info
Developer | anand_kumar |
Plugin | Header and Footer Scripts |
Version | 2.1.0 |
Comparing to | |
See all releases |
Code changes from version 2.0.0 to 2.1.0
- inc/meta.php +11 -1
- inc/options.php +11 -1
- inc/sidebar.php +21 -10
- readme.txt +59 -42
- shfs.php +50 -76
inc/meta.php
CHANGED
@@ -1,4 +1,14 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 - 20168, 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="
|
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 - 20168, 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 |
-
*
|
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
|
14 |
-
<p><strong><a href="http://digitalliberation.org/plugins/header-and-footer-scripts
|
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 |
-
|
22 |
-
<p><a href="http://digitalliberation.org/contribute
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
</div>
|
24 |
</div>
|
25 |
|
26 |
<div class="postbox">
|
27 |
-
<h3 class="hndle"><?php _e( '
|
28 |
<div class="inside">
|
29 |
-
|
30 |
-
<p><a href="http://digitalliberation.org/?utm_source=
|
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 - 20168, 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,96 @@
|
|
1 |
=== Header and Footer Scripts ===
|
2 |
|
3 |
Contributors: digitalliberation, anand_kumar
|
4 |
-
Donate link: http://
|
5 |
Tags: head, header, footer, scripts, post, admin
|
6 |
-
Requires at least:
|
7 |
Tested up to: 4.9.1
|
8 |
-
Stable tag: 2.
|
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
|
14 |
|
15 |
== Description ==
|
|
|
16 |
|
17 |
-
|
18 |
|
19 |
-
|
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 |
-
|
|
|
|
|
25 |
|
26 |
-
|
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 |
-
|
|
|
|
|
44 |
|
45 |
-
|
|
|
|
|
|
|
46 |
|
47 |
-
|
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 |
-
|
|
|
52 |
|
53 |
-
|
54 |
|
55 |
-
|
|
|
56 |
|
57 |
-
**
|
|
|
|
|
|
|
|
|
58 |
|
59 |
-
|
|
|
|
|
|
|
|
|
60 |
|
61 |
-
|
|
|
62 |
|
63 |
-
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
|
69 |
**Q: Is there any paid version of the plugin available?**
|
70 |
|
71 |
-
A.
|
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: http://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: 4.9.1
|
8 |
+
Stable tag: 2.1.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 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]: http://digitalliberation.org/docs/header-and-footer-scripts/?utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wp_hfs
|
54 |
+
[2]: http://digitalliberation.org/support/?utm_source=wporg&utm_medium=wppluginpage&utm_campaign=wp_hfs
|
55 |
+
[3]: https://github.com/anandkumar/header-and-footer-scripts
|
56 |
+
[4]: http://digitalliberation.org/contribute/?utm_source=wporg&utm_medium=donation_link&utm_campaign=wp_hfs
|
57 |
+
[5]: http://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.0 =
|
83 |
+
* Support to Custom Post Type (CPT).
|
84 |
+
* Improved ReadMe
|
85 |
+
|
86 |
+
= 2.0.1 =
|
87 |
+
* Uniform Coding style.
|
88 |
+
* Improved Translatable strings.
|
89 |
+
* Fixed Links
|
90 |
+
* Code Cleanup
|
91 |
+
|
92 |
= 2.0.0 =
|
93 |
+
* Visual Improvements.
|
94 |
* better directory structure.
|
95 |
|
96 |
= 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
|
6 |
-
* Version: 2.
|
7 |
-
* Author:
|
8 |
-
* Author URI: http://
|
9 |
* Text Domain: header-and-footer-scripts
|
10 |
* Domain Path: /lang
|
11 |
* License: GPLv2 or later
|
@@ -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
|
60 |
-
foreach (
|
61 |
-
{
|
62 |
add_meta_box('shfs_all_post_meta', esc_html__('Insert Script to <head>', '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 |
-
|
76 |
-
|
77 |
-
|
78 |
|
79 |
$shfs_post_meta = get_post_meta( get_the_ID(), '_inpost_head_script' , TRUE );
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
|
84 |
}
|
85 |
|
@@ -89,33 +88,10 @@ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
|
|
89 |
$text = convert_smilies( $text );
|
90 |
$text = do_shortcode( $text );
|
91 |
|
92 |
-
|
93 |
-
|
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))
|
154 |
-
|
155 |
-
|
156 |
-
{
|
157 |
-
|
|
|
|
|
|
|
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.0
|
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
|
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 <head>', '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 ( $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 |
}
|