Header and Footer Scripts - Version 2.0.0

Version Description

  • Visual Improvements
  • better directory structure.
Download this release

Release Info

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

Code changes from version 1.3.4 to 2.0.0

images/blogsynthesis-100px.png DELETED
Binary file
images/email-16px.png DELETED
Binary file
meta.php → inc/meta.php RENAMED
@@ -1,8 +1,8 @@
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>
5
- </p>
6
-
7
- <p>Add some code to <code>&lt;head&gt;</code>.</p>
8
- </div>
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>
5
+ </p>
6
+
7
+ <p><?php _e('Add some code to <code>&lt;head&gt;</code>', 'header-and-footer-scripts'); ?>.</p>
8
+ </div>
inc/options.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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">
6
+ <div id="post-body" class="metabox-holder columns-2">
7
+ <div id="post-body-content">
8
+ <div class="postbox">
9
+ <div class="inside">
10
+ <form name="dofollow" action="options.php" method="post">
11
+
12
+ <?php settings_fields( 'header-and-footer-scripts' ); ?>
13
+
14
+ <h3 class="shfs-labels" for="shfs_insert_header"><?php _e( 'Scripts in header:', 'header-and-footer-scripts'); ?></h3>
15
+ <textarea style="width:98%;" rows="10" cols="57" id="insert_header" name="shfs_insert_header"><?php echo esc_html( get_option( 'shfs_insert_header' ) ); ?></textarea>
16
+ <p><?php _e( 'Above script will be inserted into the <code>&lt;head&gt;</code> section.', 'header-and-footer-scripts'); ?></p><hr />
17
+
18
+ <h3 class="shfs-labels footerlabel" for="shfs_insert_footer"><?php _e( 'Scripts in footer:', 'header-and-footer-scripts'); ?></h3>
19
+ <textarea style="width:98%;" rows="10" cols="57" id="shfs_insert_footer" name="shfs_insert_footer"><?php echo esc_html( get_option( 'shfs_insert_footer' ) ); ?></textarea>
20
+ <p><?php _e( 'Above script will be inserted just before <code>&lt;/body&gt;</code> tag using <code>wp_footer</code> hook.', 'header-and-footer-scripts'); ?></p>
21
+
22
+ <p class="submit">
23
+ <input class="button button-primary" type="submit" name="Submit" value="<?php _e( 'Save settings', 'header-and-footer-scripts'); ?>" />
24
+ </p>
25
+
26
+ </form>
27
+ </div>
28
+ </div>
29
+ </div>
30
+
31
+ <?php require_once(SHFS_PLUGIN_DIR . '/inc/sidebar.php'); ?>
32
+ </div>
33
+ </div>
34
+ </div>
inc/sidebar.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
34
+ </div>
readme.txt CHANGED
@@ -1,85 +1,97 @@
1
- === Header and Footer Scripts ===
2
-
3
- Contributors: digitalliberation, anand_kumar, BlogSynthesis
4
- Donate link: https://digitalliberation.org
5
- Tags: head, header, footer, scripts, post, admin
6
- Requires at least: 4.0
7
- Tested up to: 4.9.1
8
- Stable tag: 1.3.4
9
- Requires PHP: 5.2.4
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, 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]: https://digitalliberation.org
39
- [6]: http://www.blogsynthesis.com/donate/
40
- [7]: https://digitalliberation.org/?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 [Digital Liberation](https://digitalliberation.org). 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: Is there any paid version of the plugin available?**
62
-
63
- A. No, There is no paid version of this plugin is available.
64
-
65
- == Changelog ==
66
-
67
- = 1.3.4 =
68
- * Fixed variable undefined notice
69
-
70
- = 1.3.3 =
71
- * Started using PHP5 style construct
72
-
73
- = 1.3.2 =
74
- * Fixed https issue
75
-
76
- = 1.1.0 =
77
- * Made for official WordPress Repo.
78
- * Added Single post Header script metabox
79
- * Minor Bug Fixes
80
-
81
- = 1.0.0 =
82
- * Initial Public Release
83
-
84
- == Upgrade Notice ==
85
- Upgrade for more functionality and bug fixes.
 
 
 
 
 
 
 
 
 
 
 
 
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 =
80
+ * Fixed variable undefined notice
81
+
82
+ = 1.3.3 =
83
+ * Started using PHP5 style construct
84
+
85
+ = 1.3.2 =
86
+ * Fixed https issue
87
+
88
+ = 1.1.0 =
89
+ * Made for official WordPress Repo.
90
+ * Added Single post Header script metabox
91
+ * Minor Bug Fixes
92
+
93
+ = 1.0.0 =
94
+ * Initial Public Release
95
+
96
+ == Upgrade Notice ==
97
+ Upgrade for more functionality and bug fixes.
shfs.php CHANGED
@@ -1,364 +1,212 @@
1
- <?php
2
- /*
3
- Plugin Name: Header and Footer Scripts
4
- Plugin URI: http://www.blogsynthesis.com/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: 1.3.4
7
- Author: Anand Kumar
8
- Author URI: http://www.blogsynthesis.com
9
- License: GPLv2 or later
10
-
11
- jQuery Smooth Scroll
12
- Copyright (C) 2013-16, Anand Kumar <anand@anandkumar.net>
13
- */
14
-
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, version 2, as
18
- published by the Free Software Foundation.
19
-
20
- This program is distributed in the hope that it will be useful,
21
- but WITHOUT ANY WARRANTY; without even the implied warranty of
22
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
- GNU General Public License for more details.
24
-
25
- You should have received a copy of the GNU General Public License
26
- along with this program; if not, write to the Free Software
27
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28
-
29
- Credits: WPBeginner (http://bit.ly/wpb-ihf) and Farinspace (http://bit.ly/1m9NzM9)
30
- */
31
-
32
- define('SHFS_PLUGIN_DIR',str_replace('\\','/',dirname(__FILE__)));
33
-
34
- if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
35
-
36
- class HeaderAndFooterScripts {
37
-
38
- function __construct() {
39
-
40
- add_action( 'init', array( &$this, 'init' ) );
41
- add_action( 'admin_init', array( &$this, 'admin_init' ) );
42
- add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
43
- add_action( 'wp_head', array( &$this, 'wp_head' ) );
44
- add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
45
-
46
- }
47
-
48
-
49
- function init() {
50
- load_plugin_textdomain( 'insert-headers-and-footers', false, dirname( plugin_basename ( __FILE__ ) ).'/lang' );
51
- }
52
-
53
- function admin_init() {
54
- register_setting( 'insert-headers-and-footers', 'shfs_insert_header', 'trim' );
55
- register_setting( 'insert-headers-and-footers', 'shfs_insert_footer', 'trim' );
56
-
57
- foreach (array('post','page') as $type)
58
- {
59
- add_meta_box('shfs_all_post_meta', 'Insert Script to &lt;head&gt;', 'shfs_meta_setup', $type, 'normal', 'high');
60
- }
61
-
62
- add_action('save_post','shfs_post_meta_save');
63
- }
64
-
65
- function admin_menu() {
66
- $page = add_submenu_page( 'options-general.php', 'Header and Footer Scripts', 'Header and Footer Scripts', 'manage_options', __FILE__, array( &$this, 'shfs_options_panel' ) );
67
- }
68
-
69
- function wp_head() {
70
- $meta = get_option( 'shfs_insert_header', '' );
71
- if ( $meta != '' ) {
72
- echo $meta, "\n";
73
- }
74
-
75
- $shfs_post_meta = get_post_meta( get_the_ID(), '_inpost_head_script' , TRUE );
76
- if ( $shfs_post_meta != '' ) {
77
- echo $shfs_post_meta['synth_header_script'], "\n";
78
- }
79
-
80
- }
81
-
82
- function wp_footer() {
83
- if ( !is_admin() && !is_feed() && !is_robots() && !is_trackback() ) {
84
- $text = get_option( 'shfs_insert_footer', '' );
85
- $text = convert_smilies( $text );
86
- $text = do_shortcode( $text );
87
-
88
- if ( $text != '' ) {
89
- echo $text, "\n";
90
- }
91
- }
92
- }
93
-
94
-
95
- function fetch_rss_items( $num, $feed ) {
96
- include_once( ABSPATH . WPINC . '/feed.php' );
97
- $rss = fetch_feed( $feed );
98
-
99
- // Bail if feed doesn't work
100
- if ( !$rss || is_wp_error( $rss ) )
101
- return false;
102
-
103
- $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
104
-
105
- // If the feed was erroneous
106
- if ( !$rss_items ) {
107
- $md5 = md5( $feed );
108
- delete_transient( 'feed_' . $md5 );
109
- delete_transient( 'feed_mod_' . $md5 );
110
- $rss = fetch_feed( $feed );
111
- $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
112
- }
113
-
114
- return $rss_items;
115
- }
116
-
117
-
118
- function shfs_options_panel() { ?>
119
- <div id="fb-root"></div>
120
- <div id="shfs-wrap">
121
- <div class="wrap">
122
- <?php screen_icon(); ?>
123
- <h2>Header and Footer Scripts - Options</h2>
124
- <hr />
125
- <div class="shfs-wrap" style="width: auto;float: left;margin-right: 2rem;">
126
-
127
- <div class="shfs-follow">
128
- <strong style="line-height:3;">Follow:</strong>&nbsp; &nbsp; &nbsp;
129
- <!-- Place this tag where you want the widget to render. -->
130
- <div class="g-follow" data-annotation="none" data-height="20" data-href="//plus.google.com/106432349913858405478" data-rel="author"></div>
131
-
132
- <div class="fb-like" data-href="https://www.facebook.com/BlogSynthesis" data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>
133
- </div><hr />
134
-
135
- <form name="dofollow" action="options.php" method="post">
136
-
137
- <?php settings_fields( 'insert-headers-and-footers' ); ?>
138
-
139
- <h3 class="shfs-labels" for="shfs_insert_header">Scripts in header:</h3>
140
- <textarea rows="5" cols="57" id="insert_header" name="shfs_insert_header"><?php echo esc_html( get_option( 'shfs_insert_header' ) ); ?></textarea><br />
141
- These scripts will be printed to the <code>&lt;head&gt;</code> section.
142
-
143
- <h3 class="shfs-labels footerlabel" for="shfs_insert_footer">Scripts in footer:</h3>
144
- <textarea rows="5" cols="57" id="shfs_insert_footer" name="shfs_insert_footer"><?php echo esc_html( get_option( 'shfs_insert_footer' ) ); ?></textarea><br />
145
- These scripts will be printed to the <code>&lt;footer&gt;</code> section.
146
-
147
- <p class="submit">
148
- <input class="button button-primary" type="submit" name="Submit" value="Save settings" />
149
- </p>
150
-
151
- </form>
152
- </div>
153
-
154
-
155
- <div class="shfs-sidebar" style="max-width: 270px;float: left;">
156
- <div class="shfs-improve-site" style="padding: 1rem; background: rgba(0, 0, 0, .02);">
157
- <h2>Improve Your Site!</h2>
158
- <p>Want to take your site to the next level? Look behind the scenes of BlogSynthesis to see what you can do!</p>
159
- <p><a href="http://www.blogsynthesis.com/go/shfs-plugin/" class="button" target="_blank">BlogSynthesis's Blueprint &raquo;</a></p>
160
- </div>
161
- <div class="shfs-support" style="padding: 1rem; background: rgba(0, 0, 0, .02);">
162
- <h2>Need Support?</h2>
163
- <p>For any help visit our <br /><strong><a href="http://www.blogsynthesis.com/plugins/header-and-footer-scripts/" target="_blank">Plugin Page</a></strong> or<br /><strong><a href="http://www.blogsynthesis.com/support/" target="_blank">Support Page</a></strong></p>
164
- </div>
165
- <div class="shfs-donate" style="padding: 1rem; background: rgba(0, 0, 0, .02);">
166
- <h3>Contribute or Donate!</h3>
167
- <p>Want to help make this plugin even better? All donations are used to improve this plugin, so donate $10, $20 or $50 now!</p>
168
- <p><a href="http://www.blogsynthesis.com/go/donate" target="_blank"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>images/paypal-donate.gif" alt="Subscribe to our Blog" style="margin: 0 5px 0 0; vertical-align: top; line-height: 18px;"/> Donate!</a></p>
169
- </div>
170
- <div class="shfs-wpb-recent" style="padding: 1rem; background: rgba(0, 0, 0, .02);">
171
- <h2>Latest From BlogSynthesis</h2>
172
- <?php
173
- $rss_items = $this->fetch_rss_items( 3, 'http://feeds.feedburner.com/blogsynthesis' );
174
- $content = '<ul>';
175
- if ( !$rss_items ) {
176
- $content .= '<li class="shfs-list">No news items, feed might be broken...</li>';
177
- } else {
178
- foreach ( $rss_items as $item ) {
179
- $url = preg_replace( '/#.*/', '', esc_url( $item->get_permalink(), null, 'display' ) );
180
- $content .= '<li class="shfs-list">';
181
- $content .= '<a href="' . $url . '#utm_source=wpadmin&utm_medium=sidebarwidget&utm_term=newsitem&utm_campaign=shfs" target="_blank">' . esc_html( $item->get_title() ) . '</a> ';
182
- $content .= '</li>';
183
- }}
184
- $content .= '<li class="facebook"><a href="https://www.facebook.com/blogsynthesis" target="_blank">Like BlogSynthesis on Facebook</a></li>';
185
- $content .= '<li class="twitter"><a href="http://twitter.com/blogsynthesis"target="_blank">Follow BlogSynthesis on Twitter</a></li>';
186
- $content .= '<li class="googleplus"><a href="https://plus.google.com/+BlogSynthesis/posts" target="_blank">Circle BlogSynthesis on Google+</a></li>';
187
- $content .= '<li class="email"><a href="http://www.blogsynthesis.com/newsletter/" target="_blank">Subscribe by email</a></li>';
188
- $content .= '</ul>';
189
- echo $content;
190
- ?>
191
- </div>
192
- </div>
193
-
194
- </div>
195
- </div>
196
-
197
- <!-- Place this tag after the last widget tag. -->
198
- <script type="text/javascript">
199
- (function() {
200
- var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
201
- po.src = 'https://apis.google.com/js/platform.js';
202
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
203
- })();
204
- </script>
205
-
206
-
207
- <script>(function(d, s, id) {
208
- var js, fjs = d.getElementsByTagName(s)[0];
209
- if (d.getElementById(id)) return;
210
- js = d.createElement(s); js.id = id;
211
- js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=383137358414970";
212
- fjs.parentNode.insertBefore(js, fjs);
213
- }(document, 'script', 'facebook-jssdk'));</script>
214
-
215
- <?php
216
- }
217
- }
218
-
219
- function shfs_meta_setup()
220
- {
221
- global $post;
222
-
223
- // using an underscore, prevents the meta variable
224
- // from showing up in the custom fields section
225
- $meta = get_post_meta($post->ID,'_inpost_head_script',TRUE);
226
-
227
- // instead of writing HTML here, lets do an include
228
- include(SHFS_PLUGIN_DIR . '/meta.php');
229
-
230
- // create a custom nonce for submit verification later
231
- echo '<input type="hidden" name="shfs_post_meta_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
232
- }
233
-
234
- function shfs_post_meta_save($post_id)
235
- {
236
- // authentication checks
237
-
238
- // make sure data came from our meta box
239
- if ( ! isset( $_POST['shfs_post_meta_noncename'] )
240
- || !wp_verify_nonce($_POST['shfs_post_meta_noncename'],__FILE__)) return $post_id;
241
-
242
- // check user permissions
243
- if ($_POST['post_type'] == 'page')
244
- {
245
- if (!current_user_can('edit_page', $post_id)) return $post_id;
246
- }
247
- else
248
- {
249
- if (!current_user_can('edit_post', $post_id)) return $post_id;
250
- }
251
-
252
- $current_data = get_post_meta($post_id, '_inpost_head_script', TRUE);
253
-
254
- $new_data = $_POST['_inpost_head_script'];
255
-
256
- shfs_post_meta_clean($new_data);
257
-
258
- if ($current_data)
259
- {
260
- if (is_null($new_data)) delete_post_meta($post_id,'_inpost_head_script');
261
- else update_post_meta($post_id,'_inpost_head_script',$new_data);
262
- }
263
- elseif (!is_null($new_data))
264
- {
265
- add_post_meta($post_id,'_inpost_head_script',$new_data,TRUE);
266
- }
267
-
268
- return $post_id;
269
- }
270
-
271
- function shfs_post_meta_clean(&$arr)
272
- {
273
- if (is_array($arr))
274
- {
275
- foreach ($arr as $i => $v)
276
- {
277
- if (is_array($arr[$i]))
278
- {
279
- shfs_post_meta_clean($arr[$i]);
280
-
281
- if (!count($arr[$i]))
282
- {
283
- unset($arr[$i]);
284
- }
285
- }
286
- else
287
- {
288
- if (trim($arr[$i]) == '')
289
- {
290
- unset($arr[$i]);
291
- }
292
- }
293
- }
294
-
295
- if (!count($arr))
296
- {
297
- $arr = NULL;
298
- }
299
- }
300
- }
301
-
302
-
303
- add_action('wp_dashboard_setup', 'shfs_dashboard_widgets');
304
-
305
- function shfs_dashboard_widgets() {
306
- global $wp_meta_boxes;
307
- wp_add_dashboard_widget('blogsynthesisshfswidget', 'Latest from BlogSynthesis', 'shfs_widget');
308
- }
309
-
310
- function shfs_widget() {
311
- include_once( ABSPATH . WPINC . '/feed.php' );
312
-
313
- $rss = fetch_feed( 'http://feeds2.feedburner.com/blogsynthesis' );
314
-
315
- if ( ! is_wp_error( $rss ) ) :
316
-
317
- // Figure out how many total items there are, but limit it to 10.
318
- $maxitems = $rss->get_item_quantity( 10 );
319
-
320
- // Build an array of all the items, starting with element 0 (first element).
321
- $rss_items = $rss->get_items( 0, $maxitems );
322
-
323
- endif;
324
-
325
- { ?>
326
- <div class="rss-widget">
327
- <a href="http://www.blogsynthesis.com/#utm_source=wpadmin&utm_medium=dashboardwidget&utm_term=newsitemlogo&utm_campaign=shfs" title="BlogSynthesis - For Bloggers" target="_blank"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>images/blogsynthesis-100px.png" class="alignright" alt="BlogSynthesis"/></a>
328
- <ul>
329
- <?php if ( $maxitems == 0 ) : ?>
330
- <li><?php _e( 'No items', 'shfs-text-domain' ); ?></li>
331
- <?php else : ?>
332
- <?php // Loop through each feed item and display each item as a hyperlink. ?>
333
- <?php foreach ( $rss_items as $item ) : ?>
334
- <li>
335
- <a href="<?php echo esc_url( $item->get_permalink() ); ?>#utm_source=wpadmin&utm_medium=dashboardwidget&utm_term=newsitem&utm_campaign=shfs"
336
- title="<?php printf( __( 'Posted %s', 'shfs-text-domain' ), $item->get_date('j F Y | g:i a') ); ?>" target="_blank">
337
- <?php echo esc_html( $item->get_title() ); ?>
338
- </a>
339
- </li>
340
- <?php endforeach; ?>
341
- <?php endif; ?>
342
- </ul>
343
- <div style="border-top: 1px solid #ddd; padding-top: 10px; text-align:center;">
344
- <span class="addthis_toolbox addthis_default_style" style="float:left;">
345
- <a class="addthis_button_facebook_follow" addthis:userid="blogsynthesis"></a>
346
- <a class="addthis_button_twitter_follow" addthis:userid="blogsynthesis"></a>
347
- <a class="addthis_button_google_follow" addthis:userid="+BlogSynthesis"></a>
348
- <a class="addthis_button_rss_follow" addthis:userid="http://feeds2.feedburner.com/blogsynthesis"></a>
349
- </span>
350
- &nbsp; &nbsp; &nbsp;
351
- <a href="http://www.blogsynthesis.com/newsletter/"><img src="<?php echo plugin_dir_url( __FILE__ ); ?>images/email-16px.png" alt="Subscribe via Email"/> Subscribe by email</a>
352
- &nbsp; &nbsp; &nbsp;
353
- <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-525ab1d176544441"></script>
354
- </div>
355
- </div>
356
- <?php }
357
-
358
- }
359
-
360
- $shfs_header_and_footer_scripts = new HeaderAndFooterScripts();
361
-
362
- }
363
-
364
-
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
12
+ */
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
20
+ published by the Free Software Foundation.
21
+
22
+ This program is distributed in the hope that it will be useful,
23
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ GNU General Public License for more details.
26
+
27
+ You should have received a copy of the GNU General Public License
28
+ along with this program; if not, write to the Free Software
29
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
+ */
31
+
32
+ define('SHFS_PLUGIN_DIR',str_replace('\\','/',dirname(__FILE__)));
33
+
34
+ if ( !class_exists( 'HeaderAndFooterScripts' ) ) {
35
+
36
+ class HeaderAndFooterScripts {
37
+
38
+ function __construct() {
39
+
40
+ add_action( 'init', array( &$this, 'init' ) );
41
+ add_action( 'admin_init', array( &$this, 'admin_init' ) );
42
+ add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
43
+ add_action( 'wp_head', array( &$this, 'wp_head' ) );
44
+ add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
45
+
46
+ }
47
+
48
+
49
+ function init() {
50
+ load_plugin_textdomain( 'header-and-footer-scripts', false, dirname( plugin_basename ( __FILE__ ) ).'/lang' );
51
+ }
52
+
53
+ function admin_init() {
54
+
55
+ // register settings for sitewide script
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
+
65
+ add_action('save_post','shfs_post_meta_save');
66
+ }
67
+
68
+ // adds menu item to wordpress admin dashboard
69
+ function admin_menu() {
70
+ $page = add_submenu_page( 'options-general.php', __('Header and Footer Scripts', 'header-and-footer-scripts'), __('Header and Footer Scripts', 'header-and-footer-scripts'), 'manage_options', __FILE__, array( &$this, 'shfs_options_panel' ) );
71
+ }
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
+
86
+ function wp_footer() {
87
+ if ( !is_admin() && !is_feed() && !is_robots() && !is_trackback() ) {
88
+ $text = get_option( 'shfs_insert_footer', '' );
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() {
122
+ // Load options page
123
+ require_once(SHFS_PLUGIN_DIR . '/inc/options.php');
124
+ }
125
+ }
126
+
127
+ function shfs_meta_setup()
128
+ {
129
+ global $post;
130
+
131
+ // using an underscore, prevents the meta variable
132
+ // from showing up in the custom fields section
133
+ $meta = get_post_meta($post->ID,'_inpost_head_script',TRUE);
134
+
135
+ // instead of writing HTML here, lets do an include
136
+ include_once(SHFS_PLUGIN_DIR . '/inc/meta.php');
137
+
138
+ // create a custom nonce for submit verification later
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
147
+ if ( ! isset( $_POST['shfs_post_meta_noncename'] )
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);
161
+
162
+ $new_data = $_POST['_inpost_head_script'];
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
+ }