Insert Headers and Footers - Version 1.2

Version Description

  • cleaned up code
Download this release

Release Info

Developer iamdpegg
Plugin Icon 128x128 Insert Headers and Footers
Version 1.2
Comparing to
See all releases

Code changes from version 1.1 to 1.2

Files changed (2) hide show
  1. ihaf.php +139 -151
  2. readme.txt +6 -3
ihaf.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: Insert Headers and Footers
4
  Plugin URI:
5
  Description: Allows you to insert code or text in the header or footer of your WordPress blog
6
- Version: 1.1
7
  Author: iamdpegg
8
  Author URI:
9
  License: This software is distributed in the hope that it will be useful,
@@ -14,193 +14,181 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 
15
  if ( !class_exists( 'InsertHeadersAndFooters' ) ) {
16
 
17
- define('IHAFURL', plugins_url('', __FILE__));
18
- wp_register_style('IHAFStyleSheet', IHAFURL . '/ihaf.css');
19
- wp_enqueue_style( 'IHAFStyleSheet');
 
 
20
 
21
  class InsertHeadersAndFooters {
22
 
23
- function InsertHeadersAndFooters() {
24
 
25
- add_action( 'init', array( &$this, 'init' ) );
26
- add_action( 'admin_init', array( &$this, 'admin_init' ) );
27
- add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
28
- add_action( 'wp_head', array( &$this, 'wp_head' ) );
29
- add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
30
 
31
- }
32
 
33
- function init() {
34
- load_plugin_textdomain( 'insert-headers-and-footers', false, dirname( plugin_basename ( __FILE__ ) ).'/lang' );
35
- }
36
 
37
- function admin_init() {
38
- register_setting( 'insert-headers-and-footers', 'ihaf_insert_header', 'trim' );
39
- register_setting( 'insert-headers-and-footers', 'ihaf_insert_footer', 'trim' );
40
  }
41
 
42
- function admin_menu() {
43
- add_submenu_page( 'options-general.php', 'Insert Headers and Footers',
44
- 'Insert Headers and Footers', 'manage_options', __FILE__, array( &$this, 'options_panel' ) );
45
- }
46
 
47
- function wp_head() {
48
- $meta = get_option( 'ihaf_insert_header', '' );
49
- if ( $meta != '' ) {
50
- echo $meta, "\n";
 
51
  }
52
- }
53
 
54
- function wp_footer() {
55
- if ( !is_admin() && !is_feed() && !is_robots() && !is_trackback() ) {
56
- $text = get_option( 'ihaf_insert_footer', '' );
57
-
58
- $text = convert_smilies( $text );
59
- $text = do_shortcode( $text );
60
 
61
  if ( $text != '' ) {
62
  echo $text, "\n";
63
  }
 
64
  }
65
- }
66
 
67
- function fetch_rss_items( $num, $feed ) {
68
- include_once( ABSPATH . WPINC . '/feed.php' );
69
- $rss = fetch_feed( $feed );
70
 
71
- // Bail if feed doesn't work
72
- if ( !$rss || is_wp_error( $rss ) )
73
  return false;
74
 
75
- $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
76
-
77
- // If the feed was erroneous
78
- if ( !$rss_items ) {
79
- $md5 = md5( $feed );
80
- delete_transient( 'feed_' . $md5 );
81
- delete_transient( 'feed_mod_' . $md5 );
82
- $rss = fetch_feed( $feed );
83
  $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
84
- }
85
 
86
- return $rss_items;
87
- }
 
 
 
 
 
 
 
 
 
88
 
89
 
90
- function options_panel() {
91
- ?>
92
- <div id="ihaf-wrap">
93
- <div class="wrap">
94
- <?php screen_icon(); ?>
95
- <h2>Insert Headers and Footers - Options</h2>
96
- <div class="ihaf-wrap">
97
- <form name="dofollow" action="options.php" method="post">
98
- <?php settings_fields( 'insert-headers-and-footers' ); ?>
99
-
100
- <label class="ihaf-labels" for="ihaf_insert_header">Scripts in header:</label>
101
-
102
- <textarea rows="5" cols="57" id="insert_header" name="ihaf_insert_header"><?php echo esc_html( get_option( 'ihaf_insert_header' ) ); ?></textarea><br />
103
- These scripts will be printed to the <code>&lt;head&gt;</code> section.
104
-
105
- <label class="ihaf-labels footerlabel" for="ihaf_insert_footer">Scripts in footer:</label>
106
-
107
- <textarea rows="5" cols="57" id="ihaf_insert_footer" name="ihaf_insert_footer"><?php echo esc_html( get_option( 'ihaf_insert_footer' ) ); ?></textarea><br />
108
- These scripts will be printed to the <code>&lt;footer&gt;</code> section.
109
-
110
- <p class="submit">
111
- <input type="submit" name="Submit" value="Save settings" />
112
- </p>
113
-
114
- </form>
115
- </div>
116
-
117
- <div class="ihaf-sidebar">
118
- <div class="ihaf-improve-site">
119
- <h2>Improve Your Site!</h2>
120
- <p>Want to take your site to the next level? Look behind the scenes of WPBeginner to see what you can do!</p>
121
- <p><a href="http://www.wpbeginner.com/blueprint/" target="_blank">WPBeginner's Blueprint &raquo;</a></p>
122
- </div>
123
- <div class="ihaf-support">
124
- <h2>Need Support?</h2>
125
- <p>If you are having problems with this plugin, please talk about them in the</p>
126
- <p><a href="http://www.wpbeginner.com/contact/" target="_blank">Support Forums</a></p>
127
- </div>
128
- <div class="ihaf-donate">
129
- <h2>Spread the Word!</h2>
130
- <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>
131
- <p><a href="http://www.wpbeginner.com/wpbeginner-needs-your-help/" target="_blank">Donate!</a></p>
132
- </div>
133
- <div class="ihaf-wpb-recent">
134
- <h2>Latest News From WPBeginner</h2>
135
- <?php
136
- $rss_items = $this->fetch_rss_items( 3, 'http://wpbeginner.com/feed/' );
137
-
138
- $content = '<ul>';
139
- if ( !$rss_items ) {
140
- $content .= '<li class="ihaf-list">No news items, feed might be broken...</li>';
141
- } else {
142
- foreach ( $rss_items as $item ) {
143
- $url = preg_replace( '/#.*/', '', esc_url( $item->get_permalink(), null, 'display' ) );
144
- $content .= '<li class="ihaf-list">';
145
- $content .= '<a href="' . $url . '#utm_source=wpadmin&utm_medium=sidebarwidget&utm_term=newsitem&utm_campaign=ihaf">' . esc_html( $item->get_title() ) . '</a> ';
146
- $content .= '</li>';
147
- }
 
 
 
 
 
 
148
  }
149
- $content .= '<li class="facebook"><a href="https://www.facebook.com/wpbeginner" target="_blank">Like WPBeginner on Facebook</a></li>';
150
- $content .= '<li class="twitter"><a href="http://twitter.com/wpbeginner"target="_blank">Follow WPBeginner on Twitter</a></li>';
151
- $content .= '<li class="googleplus"><a href="https://plus.google.com/101634180904808003404/posts" target="_blank">Circle WPBeginner on Google+</a></li>';
152
- $content .= '<li class="email"><a href="http://wpbeginner.us1.list-manage.com/subscribe?u=549b83cc29ff23c36e5796c38&id=4c340fd3aa" target="_blank">Subscribe by email</a></li>';
153
- $content .= '</ul>';
154
- echo $content;
155
- ?>
156
- </div>
157
- </div>
158
-
159
- </div>
160
- </div>
161
- <?php
162
  }
163
- }
164
 
165
 
166
- add_action('wp_dashboard_setup', 'ihaf_dashboard_widgets');
167
 
168
- function ihaf_dashboard_widgets() {
169
- global $wp_meta_boxes;
170
-
171
- wp_add_dashboard_widget('wpbeginnerihafwidget', 'Latest from WPBeginner', 'ihaf_widget');
172
  }
173
 
174
  function ihaf_widget() {
175
  require_once(ABSPATH.WPINC.'/rss.php');
176
  if ( $rss = fetch_rss( 'http://wpbeginner.com/feed/' ) ) { ?>
177
  <div class="rss-widget">
178
-
179
- <a href="http://www.wpbeginner.com/" title="WPBeginner - Beginner's guide to WordPress"><img src="http://cdn.wpbeginner.com/pluginimages/wpbeginner.gif" class="alignright" alt="WPBeginner"/></a>
180
- <ul>
181
- <?php
182
- $rss->items = array_slice( $rss->items, 0, 5 );
183
- foreach ( (array) $rss->items as $item ) {
184
- echo '<li>';
185
- echo '<a class="rsswidget" href="'.clean_url( $item['link'], $protocolls=null, 'display' ).'">'. ($item['title']) .'</a> ';
186
- echo '<span class="rss-date">'. date('F j, Y', strtotime($item['pubdate'])) .'</span>';
187
-
188
- echo '</li>';
189
- }
190
- ?>
191
- </ul>
192
- <div style="border-top: 1px solid #ddd; padding-top: 10px; text-align:center;">
193
- <a href="http://feeds2.feedburner.com/wpbeginner"><img src="http://cdn.wpbeginner.com/pluginimages/feed.png" alt="Subscribe to our Blog" style="margin: 0 5px 0 0; vertical-align: top; line-height: 18px;"/> Subscribe with RSS</a>
194
- &nbsp; &nbsp; &nbsp;
195
- <a href="http://wpbeginner.us1.list-manage.com/subscribe?u=549b83cc29ff23c36e5796c38&id=4c340fd3aa"><img src="http://cdn.wpbeginner.com/pluginimages/email.gif" alt="Subscribe via Email"/> Subscribe by email</a>
196
- &nbsp; &nbsp; &nbsp;
197
- <a href="http://facebook.com/wpbeginner/"><img src="http://cdn.wpbeginner.com/pluginimages/facebook.png" alt="Join us on Facebook" style="margin: 0 5px 0 0; vertical-align: middle; line-height: 18px;" />Join us on Facebook</a>
198
  </div>
199
- </div>
200
- <?php }
201
- }
202
-
203
-
204
 
205
  $wp_insert_headers_and_footers = new InsertHeadersAndFooters();
206
 
3
  Plugin Name: Insert Headers and Footers
4
  Plugin URI:
5
  Description: Allows you to insert code or text in the header or footer of your WordPress blog
6
+ Version: 1.2
7
  Author: iamdpegg
8
  Author URI:
9
  License: This software is distributed in the hope that it will be useful,
14
 
15
  if ( !class_exists( 'InsertHeadersAndFooters' ) ) {
16
 
17
+ define('IHAFURL', plugins_url('', __FILE__));
18
+ if (is_admin()) {
19
+ wp_register_style('IHAFStyleSheet', IHAFURL . '/ihaf.css');
20
+ wp_enqueue_style( 'IHAFStyleSheet');
21
+ }
22
 
23
  class InsertHeadersAndFooters {
24
 
25
+ function InsertHeadersAndFooters() {
26
 
27
+ add_action( 'init', array( &$this, 'init' ) );
28
+ add_action( 'admin_init', array( &$this, 'admin_init' ) );
29
+ add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
30
+ add_action( 'wp_head', array( &$this, 'wp_head' ) );
31
+ add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
32
 
33
+ }
34
 
35
+ function init() {
36
+ load_plugin_textdomain( 'insert-headers-and-footers', false, dirname( plugin_basename ( __FILE__ ) ).'/lang' );
37
+ }
38
 
39
+ function admin_init() {
40
+ register_setting( 'insert-headers-and-footers', 'ihaf_insert_header', 'trim' );
41
+ register_setting( 'insert-headers-and-footers', 'ihaf_insert_footer', 'trim' );
42
  }
43
 
44
+ function admin_menu() {
45
+ add_submenu_page( 'options-general.php', 'Insert Headers and Footers', 'Insert Headers and Footers', 'manage_options', __FILE__, array( &$this, 'options_panel' ) );
46
+ }
 
47
 
48
+ function wp_head() {
49
+ $meta = get_option( 'ihaf_insert_header', '' );
50
+ if ( $meta != '' ) {
51
+ echo $meta, "\n";
52
+ }
53
  }
 
54
 
55
+ function wp_footer() {
56
+ if ( !is_admin() && !is_feed() && !is_robots() && !is_trackback() ) {
57
+ $text = get_option( 'ihaf_insert_footer', '' );
58
+ $text = convert_smilies( $text );
59
+ $text = do_shortcode( $text );
 
60
 
61
  if ( $text != '' ) {
62
  echo $text, "\n";
63
  }
64
+ }
65
  }
 
66
 
67
+ function fetch_rss_items( $num, $feed ) {
68
+ include_once( ABSPATH . WPINC . '/feed.php' );
69
+ $rss = fetch_feed( $feed );
70
 
71
+ // Bail if feed doesn't work
72
+ if ( !$rss || is_wp_error( $rss ) )
73
  return false;
74
 
 
 
 
 
 
 
 
 
75
  $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
 
76
 
77
+ // If the feed was erroneous
78
+ if ( !$rss_items ) {
79
+ $md5 = md5( $feed );
80
+ delete_transient( 'feed_' . $md5 );
81
+ delete_transient( 'feed_mod_' . $md5 );
82
+ $rss = fetch_feed( $feed );
83
+ $rss_items = $rss->get_items( 0, $rss->get_item_quantity( $num ) );
84
+ }
85
+
86
+ return $rss_items;
87
+ }
88
 
89
 
90
+ function options_panel() { ?>
91
+ <div id="ihaf-wrap">
92
+ <div class="wrap">
93
+ <?php screen_icon(); ?>
94
+ <h2>Insert Headers and Footers - Options</h2>
95
+ <div class="ihaf-wrap">
96
+ <form name="dofollow" action="options.php" method="post">
97
+ <?php settings_fields( 'insert-headers-and-footers' ); ?>
98
+ <label class="ihaf-labels" for="ihaf_insert_header">Scripts in header:</label>
99
+ <textarea rows="5" cols="57" id="insert_header" name="ihaf_insert_header"><?php echo esc_html( get_option( 'ihaf_insert_header' ) ); ?></textarea><br />
100
+ These scripts will be printed to the <code>&lt;head&gt;</code> section.
101
+ <label class="ihaf-labels footerlabel" for="ihaf_insert_footer">Scripts in footer:</label>
102
+ <textarea rows="5" cols="57" id="ihaf_insert_footer" name="ihaf_insert_footer"><?php echo esc_html( get_option( 'ihaf_insert_footer' ) ); ?></textarea><br />
103
+ These scripts will be printed to the <code>&lt;footer&gt;</code> section.
104
+
105
+ <p class="submit">
106
+ <input type="submit" name="Submit" value="Save settings" />
107
+ </p>
108
+
109
+ </form>
110
+ </div>
111
+
112
+ <div class="ihaf-sidebar">
113
+ <div class="ihaf-improve-site">
114
+ <h2>Improve Your Site!</h2>
115
+ <p>Want to take your site to the next level? Look behind the scenes of WPBeginner to see what you can do!</p>
116
+ <p><a href="http://www.wpbeginner.com/blueprint/" target="_blank">WPBeginner's Blueprint &raquo;</a></p>
117
+ </div>
118
+ <div class="ihaf-support">
119
+ <h2>Need Support?</h2>
120
+ <p>If you are having problems with this plugin, please talk about them in the</p>
121
+ <p><a href="http://www.wpbeginner.com/contact/" target="_blank">Support Forums</a></p>
122
+ </div>
123
+ <div class="ihaf-donate">
124
+ <h2>Spread the Word!</h2>
125
+ <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>
126
+ <p><a href="http://www.wpbeginner.com/wpbeginner-needs-your-help/" target="_blank">Donate!</a></p>
127
+ </div>
128
+ <div class="ihaf-wpb-recent">
129
+ <h2>Latest News From WPBeginner</h2>
130
+ <?php
131
+ $rss_items = $this->fetch_rss_items( 3, 'http://wpbeginner.com/feed/' );
132
+ $content = '<ul>';
133
+ if ( !$rss_items ) {
134
+ $content .= '<li class="ihaf-list">No news items, feed might be broken...</li>';
135
+ } else {
136
+ foreach ( $rss_items as $item ) {
137
+ $url = preg_replace( '/#.*/', '', esc_url( $item->get_permalink(), null, 'display' ) );
138
+ $content .= '<li class="ihaf-list">';
139
+ $content .= '<a href="' . $url . '#utm_source=wpadmin&utm_medium=sidebarwidget&utm_term=newsitem&utm_campaign=ihaf">' . esc_html( $item->get_title() ) . '</a> ';
140
+ $content .= '</li>';
141
+ }}
142
+ $content .= '<li class="facebook"><a href="https://www.facebook.com/wpbeginner" target="_blank">Like WPBeginner on Facebook</a></li>';
143
+ $content .= '<li class="twitter"><a href="http://twitter.com/wpbeginner"target="_blank">Follow WPBeginner on Twitter</a></li>';
144
+ $content .= '<li class="googleplus"><a href="https://plus.google.com/101634180904808003404/posts" target="_blank">Circle WPBeginner on Google+</a></li>';
145
+ $content .= '<li class="email"><a href="http://wpbeginner.us1.list-manage.com/subscribe?u=549b83cc29ff23c36e5796c38&id=4c340fd3aa" target="_blank">Subscribe by email</a></li>';
146
+ $content .= '</ul>';
147
+ echo $content;
148
+ ?>
149
+ </div>
150
+ </div>
151
+ </div>
152
+ </div>
153
+ <?php
154
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
155
  }
 
156
 
157
 
158
+ add_action('wp_dashboard_setup', 'ihaf_dashboard_widgets');
159
 
160
+ function ihaf_dashboard_widgets() {
161
+ global $wp_meta_boxes;
162
+ wp_add_dashboard_widget('wpbeginnerihafwidget', 'Latest from WPBeginner', 'ihaf_widget');
 
163
  }
164
 
165
  function ihaf_widget() {
166
  require_once(ABSPATH.WPINC.'/rss.php');
167
  if ( $rss = fetch_rss( 'http://wpbeginner.com/feed/' ) ) { ?>
168
  <div class="rss-widget">
169
+ <a href="http://www.wpbeginner.com/" title="WPBeginner - Beginner's guide to WordPress"><img src="http://cdn.wpbeginner.com/pluginimages/wpbeginner.gif" class="alignright" alt="WPBeginner"/></a>
170
+ <ul>
171
+ <?php
172
+ $rss->items = array_slice( $rss->items, 0, 5 );
173
+ foreach ( (array) $rss->items as $item ) {
174
+ echo '<li>';
175
+ echo '<a class="rsswidget" href="'.clean_url( $item['link'], $protocolls=null, 'display' ).'">'. ($item['title']) .'</a> ';
176
+ echo '<span class="rss-date">'. date('F j, Y', strtotime($item['pubdate'])) .'</span>';
177
+ echo '</li>';
178
+ }
179
+ ?>
180
+ </ul>
181
+ <div style="border-top: 1px solid #ddd; padding-top: 10px; text-align:center;">
182
+ <a href="http://feeds2.feedburner.com/wpbeginner"><img src="http://cdn.wpbeginner.com/pluginimages/feed.png" alt="Subscribe to our Blog" style="margin: 0 5px 0 0; vertical-align: top; line-height: 18px;"/> Subscribe with RSS</a>
183
+ &nbsp; &nbsp; &nbsp;
184
+ <a href="http://wpbeginner.us1.list-manage.com/subscribe?u=549b83cc29ff23c36e5796c38&id=4c340fd3aa"><img src="http://cdn.wpbeginner.com/pluginimages/email.gif" alt="Subscribe via Email"/> Subscribe by email</a>
185
+ &nbsp; &nbsp; &nbsp;
186
+ <a href="http://facebook.com/wpbeginner/"><img src="http://cdn.wpbeginner.com/pluginimages/facebook.png" alt="Join us on Facebook" style="margin: 0 5px 0 0; vertical-align: middle; line-height: 18px;" />Join us on Facebook</a>
187
+ </div>
 
188
  </div>
189
+ <?php }
190
+
191
+ }
 
 
192
 
193
  $wp_insert_headers_and_footers = new InsertHeadersAndFooters();
194
 
readme.txt CHANGED
@@ -1,9 +1,9 @@
1
- === Plugin Name ===
2
  Contributors: iamdpegg, smub
3
  Tags: header, footer, headers, footers, content, wpmu, meta, meta tags
4
  Requires at least: 2.7
5
  Tested up to: 3.4.1
6
- Stable tag: 1.1
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -39,4 +39,7 @@ Insert Headers and Footers is a simple plugin that lets you add scripts like Goo
39
  * Initial version
40
 
41
  = 1.1 =
42
- * fixed unecessary CSS loading
 
 
 
1
+ === Plugin Name ===
2
  Contributors: iamdpegg, smub
3
  Tags: header, footer, headers, footers, content, wpmu, meta, meta tags
4
  Requires at least: 2.7
5
  Tested up to: 3.4.1
6
+ Stable tag: 1.2
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
39
  * Initial version
40
 
41
  = 1.1 =
42
+ * fixed unecessary CSS loading
43
+
44
+ = 1.2 =
45
+ * cleaned up code