AddFunc Head & Footer Code - Version 1.1

Version Description

28-Nov-2014

  • Fixes meta box nounce
  • Changes all references to Average (including but not limited to "avrg", "average", etc.) to relate to AddFunc (changing project name)
  • Changes a few other function and variable names for namespacing purposes
  • Submitted to WordPress under the name AddFunc
Download this release

Release Info

Developer joerhoney
Plugin Icon AddFunc Head & Footer Code
Version 1.1
Comparing to
See all releases

Version 1.1

Files changed (4) hide show
  1. addfunc-head-footer-code.php +135 -0
  2. index.php +2 -0
  3. options.php +55 -0
  4. readme.txt +111 -0
addfunc-head-footer-code.php ADDED
@@ -0,0 +1,135 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: AddFunc Head & Footer Code
4
+ Plugin URI:
5
+ Description: Allows admins to add code to the &lt;head&gt; and/or &lt;footer&gt; of an individual post and/or site-wide. Ideal for scripts such as Google Analytics conversion tracking code and any other general or page-specific JavaScript.
6
+ Version: 1.1
7
+ Author: AddFunc
8
+ Author URI: http://profiles.wordpress.org/addfunc
9
+ License: Public Domain
10
+ @since 3.0.1
11
+ ______
12
+ _ | ___/ _ _ __ ____
13
+ _| |_| |__| | | | '_ \ / __/™
14
+ |_ Add| _/| |_| | | | | (__
15
+ |_| |_| \__,_|_| |_|\___\
16
+ by Joe Rhoney
17
+ */
18
+
19
+
20
+
21
+ /*
22
+ S E T T I N G S P A G E
23
+ =========================
24
+ For site-wide head and footer code
25
+ */
26
+
27
+ if(!class_exists('aFhfc_class')) :
28
+ define('AFHDFTRCD_ID', 'aFhfc');
29
+ define('AFHDFTRCD_NICK', 'Head & Footer Code');
30
+ class aFhfc_class
31
+ {
32
+ public static function file_path($file)
33
+ {
34
+ return ABSPATH.'wp-content/plugins/'.str_replace(basename( __FILE__),"",plugin_basename(__FILE__)).$file;
35
+ }
36
+ public static function register()
37
+ {
38
+ register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_site_wide_head_code');
39
+ register_setting(AFHDFTRCD_ID.'_options', 'aFhfc_site_wide_footer_code');
40
+ }
41
+ public static function menu()
42
+ {
43
+ add_options_page(AFHDFTRCD_NICK.' Plugin Options', AFHDFTRCD_NICK, 'manage_options', AFHDFTRCD_ID.'_options', array('aFhfc_class', 'options_page'));
44
+ }
45
+ public static function options_page()
46
+ {
47
+ if (!current_user_can('manage_options'))
48
+ {
49
+ wp_die(__('You do not have sufficient permissions to access this page.'));
50
+ }
51
+ $plugin_id = AFHDFTRCD_ID;
52
+ include(self::file_path('options.php'));
53
+ }
54
+ public static function output_head_code($head)
55
+ {
56
+ $code = get_option('aFhfc_site_wide_head_code');
57
+ echo $head . $code;
58
+ }
59
+ public static function output_footer_code($footer)
60
+ {
61
+ $code = get_option('aFhfc_site_wide_footer_code');
62
+ echo $footer . $code;
63
+ }
64
+ }
65
+ if (is_admin())
66
+ {
67
+ add_action('admin_init', array('aFhfc_class', 'register'));
68
+ add_action('admin_menu', array('aFhfc_class', 'menu'));
69
+ }
70
+ add_action('wp_head', array('aFhfc_class', 'output_head_code'));
71
+ add_action('wp_footer', array('aFhfc_class', 'output_footer_code'));
72
+ endif;
73
+
74
+
75
+
76
+ /*
77
+ M E T A B O X F O R P O S T S
78
+ =================================
79
+ Metabox w/head & footer fields for all post types (including custom)
80
+ */
81
+
82
+ add_action( 'add_meta_boxes', 'aFhfc_add' );
83
+ function aFhfc_add()
84
+ {
85
+ if (current_user_can( 'manage_options' )) {
86
+ add_meta_box( 'aFhfcMetaBox', 'Head & Footer Code', 'aFhfc_mtbx', '', 'normal', 'high' );
87
+ }
88
+ }
89
+ function aFhfc_mtbx( $post )
90
+ {
91
+ $values = get_post_custom( $post->ID );
92
+ $head_text = isset( $values['aFhfc_head_code'] ) ? esc_attr( $values['aFhfc_head_code'][0] ) : '';
93
+ $footer_text = isset( $values['aFhfc_footer_code'] ) ? esc_attr( $values['aFhfc_footer_code'][0] ) : '';
94
+ wp_nonce_field( 'aFhfc_nonce', 'aFhfc_mb_nonce' );
95
+ ?>
96
+ <p>
97
+ <label for="aFhfc_head_code">Head:</label>
98
+ <textarea class="large-text" name="aFhfc_head_code" id="aFhfc_head_code"><?php echo $head_text; ?></textarea>
99
+ </p>
100
+ <p>
101
+ <label for="aFhfc_footer_code">Footer:</label>
102
+ <textarea class="large-text" name="aFhfc_footer_code" id="aFhfc_footer_code"><?php echo $footer_text; ?></textarea>
103
+ </p>
104
+ <?php
105
+ }
106
+ add_action( 'save_post', 'aFhfc_save' );
107
+ function aFhfc_save( $post_id )
108
+ {
109
+ if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
110
+ if( !isset( $_POST['aFhfc_mb_nonce'] ) || !wp_verify_nonce( $_POST['aFhfc_mb_nonce'], 'aFhfc_nonce' ) ) return;
111
+ if( !current_user_can( 'manage_options' ) ) return;
112
+ if( isset( $_POST['aFhfc_head_code'] ) )
113
+ update_post_meta( $post_id, 'aFhfc_head_code', $_POST['aFhfc_head_code'] );
114
+ if( isset( $_POST['aFhfc_footer_code'] ) )
115
+ update_post_meta( $post_id, 'aFhfc_footer_code', $_POST['aFhfc_footer_code'] );
116
+ }
117
+
118
+
119
+
120
+ /*
121
+ F R O N T E N D O U T P U T
122
+ ===============================
123
+ Outputs the head and footer code for individual posts
124
+ */
125
+
126
+ function aFhfc_head_output( $post ) {
127
+ $aFhfc_head_code = get_post_meta( get_the_ID(), 'aFhfc_head_code', true );
128
+ echo $aFhfc_head_code."\n";
129
+ }
130
+ add_action('wp_head', 'aFhfc_head_output');
131
+ function aFhfc_footer_output( $post ) {
132
+ $aFhfc_footer_code = get_post_meta( get_the_ID(), 'aFhfc_footer_code', true );
133
+ echo $aFhfc_footer_code."\n";
134
+ }
135
+ add_action('wp_footer', 'aFhfc_footer_output');
index.php ADDED
@@ -0,0 +1,2 @@
 
 
1
+ <?php
2
+ # Silence is golden.
options.php ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wrap">
2
+ <?php screen_icon(); ?>
3
+ <h2>Head & Footer Code</h2>
4
+ <div id="poststuff">
5
+ <div id="post-body" class="metabox-holder columns-2">
6
+ <div id="post-body-content">
7
+ <form action="options.php" method="post" id="<?php echo $plugin_id; ?>_options_form" name="<?php echo $plugin_id; ?>_options_form">
8
+ <?php settings_fields($plugin_id.'_options'); ?>
9
+ <label for="aFhfc_site_wide_head_code">
10
+ <h2 class="title">Site-wide Head Code</h2>
11
+ <p><textarea name="aFhfc_site_wide_head_code" rows="10" cols="50" id="aFhfc_site_wide_head_code" class="large-text code"><?php echo get_option('aFhfc_site_wide_head_code'); ?></textarea></p>
12
+ </label>
13
+ <label for="aFhfc_site_wide_footer_code">
14
+ <h2 class="title">Site-wide Footer Code</h2>
15
+ <p><textarea name="aFhfc_site_wide_footer_code" rows="10" cols="50" id="aFhfc_site_wide_footer_code" class="large-text code"><?php echo get_option('aFhfc_site_wide_footer_code'); ?></textarea></p>
16
+ </label>
17
+ <?php submit_button(); ?>
18
+ </form>
19
+ </div> <!-- post-body-content -->
20
+ <!-- sidebar -->
21
+ <div id="postbox-container-1" class="postbox-container"><?php
22
+ # <h2>Support Tickets</h2>
23
+ # <p>If you need custom support for this plugin (AddFunc Head & Footer Code) or any other AddFunc plugin, you can purchase help with a support ticket below. Support tickets are responded to within 48 hours, but we answer them as soon as possible.</p>
24
+ # <p><strong>How it works</strong></p>
25
+ # <ol>
26
+ # <li>Purchase a support ticket below</li>
27
+ # <li>I contact you as soon as I can (no less than 48 hours) and help resolve your issue</li>
28
+ # <li>That's it!</li>
29
+ # </ol>
30
+ # <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
31
+ # <input type="hidden" name="cmd" value="_s-xclick">
32
+ # <input type="hidden" name="hosted_button_id" value="2ALABGHC83M4W">
33
+ # <table>
34
+ # <tr>
35
+ # <td><input type="hidden" name="on0" value="Name your ticket">Name your ticket</td>
36
+ # </tr>
37
+ # <tr>
38
+ # <td><input type="text" name="os0" maxlength="200"></td>
39
+ # </tr>
40
+ # <tr>
41
+ # <td><input type="hidden" name="on1" value="Best way to contact you">Best way to contact you</td>
42
+ # </tr>
43
+ # <tr>
44
+ # <td><input type="text" name="os1" maxlength="200"></td>
45
+ # </tr>
46
+ # </table>
47
+ # <input type="image" src="https://www.paypalobjects.com/webstatic/en_US/i/buttons/buy-logo-small.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
48
+ # <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
49
+ # </form>
50
+ # <p><strong>Note</strong>: This is for&nbsp;<em>custom</em>&nbsp;needs for help, not for problems with the plugin or instructions that should already be explained/corrected in the description or the plugin itself. If you feel there are important details omitted from the <a href="http://wordpress.org/plugins/addfunc-head-footer-code/" target="_blank">Description</a>, <a href="http://wordpress.org/plugins/addfunc-head-footer-code/installation/" target="_blank">Installation</a> steps, etc. of the plugin or problems with the plugin itself, please report them in the <a href="http://wordpress.org/support/plugin/addfunc-head-footer-code" target="_blank">Support forum</a>. Thanks!</p> ?>
51
+ </div> <!-- #postbox-container-1 .postbox-container -->
52
+ </div> <!-- #post-body .metabox-holder .columns-2 -->
53
+ <br class="clear">
54
+ </div> <!-- #poststuff -->
55
+ </div>
readme.txt ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ === AddFunc Head & Footer Code ===
3
+
4
+ Contributors: AddFunc,average.technology,joerhoney
5
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7AF7P3TFKQ2C2
6
+ Tags: head code, footer code, head, footer, head footer code, add to head, add to footer, per page, header footer code, header footer, header code, header, custom head, custom footer, custom header, script, code script, head script, footer script, head footer script, header footer script, header script, custom head script, custom footer script, custom header script, head javascript, footer javascript, header javascript, javascript code, tracking code, tracking script, tracking javascript, Google Analytics code, Google Analytics, Google Analytics head code, Google Analytics footer code, Google Analytics tracking code, Google Analytics conversion code, Google Analytics remarketing code, Google Analytics script, Google Analytics, Google Analytics head script, Google Analytics footer script, Google Analytics tracking script, Google Analytics conversion script, Google Analytics remarketing script, Google Analytics javascript
7
+ Requires at least: 3.0.1
8
+ Tested up to: 4.2
9
+ Stable tag: 1.1
10
+ License: GPLv2 or later
11
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
+
13
+ Easily add code to your head and/or footer, site-wide and/or on any individual page/post.
14
+
15
+ == Description ==
16
+
17
+ Allows admins to add code to the `<head>` and/or footer of an individual post and/or site-wide. Ideal for scripts such as Google Analytics conversion tracking code and any other general or page-specific JavaScript.
18
+
19
+ **Custom support tickets are available**
20
+
21
+ See [Other Notes][1] tab for details.
22
+
23
+ [1]: http://wordpress.org/plugins/addfunc-head-footer-code/other_notes/
24
+
25
+ == Installation ==
26
+
27
+ 1. Upload the entire `/addfunc-head-footer-code` folder to the `/wp-content/plugins/` directory
28
+ 2. Activate the plugin through the *Plugins* menu in WordPress
29
+ 3. Add code site-wide in *Settings>Head & Footer Code* or on individual pages/posts using the Head & Footer Code meta box when in edit mode in a page (or any post type)
30
+
31
+ == Frequently Asked Questions ==
32
+
33
+ = Where does the head code output? =
34
+
35
+ Wherever `wp_head()` is located in your theme.
36
+
37
+ = Where does the footer code output? =
38
+
39
+ Wherever `wp_footer()` is located in your theme.
40
+
41
+ = Does it really require WordPress 3.0.1 or later? =
42
+
43
+ I have not tested it on earlier versions. In fact, I could use help with testing. Feel free to try it out in an earlier version and let me know if it works! :)
44
+
45
+ = Does AddFunc have a website? =
46
+
47
+ The cobbler has no shoes. ...we're working on it.
48
+
49
+ == Screenshots ==
50
+
51
+ 1. Simply paste your code into one of these two fields and it will be included on every page of your website.
52
+
53
+ 2. Add your code to these fields respectively and it will output specifically to this page, post or custom post type.
54
+
55
+ == Changelog ==
56
+
57
+ = 1.1 =
58
+ 28-Nov-2014
59
+
60
+ * Fixes meta box nounce
61
+ * Changes all references to Average (including but not limited to "avrg", "average", etc.) to relate to AddFunc (changing project name)
62
+ * Changes a few other function and variable names for namespacing purposes
63
+ * Submitted to WordPress under the name AddFunc
64
+
65
+ = 1.0 =
66
+ 7-Aug-2014
67
+
68
+ * Includes readme.txt
69
+ * Submitted to WordPress
70
+
71
+ = 0.4.1 =
72
+ 6-Aug-2014
73
+
74
+ * Code cleaned up (mostly comments removed)
75
+ * Excludes unnecessary file: style.css
76
+
77
+ = 0.4 =
78
+ 8-Jul-2014
79
+
80
+ * Bug fix: replaced "my-meta-box-id" with "avrghdftrcdMetaBox" (duh)
81
+
82
+ = 0.3 =
83
+ 27-Oct-2013
84
+
85
+ * Hid Head & Footer Code meta box from non-admin users
86
+
87
+ = 0.2 =
88
+ 15-Oct-2013
89
+
90
+ * Adds a Head & Footer Code settings page for site-wide code (for admins only)
91
+
92
+ = 0.1 =
93
+ 14-Aug-2013
94
+
95
+ * Adds Head & Footer Code meta box to all pages, posts and cusom post types
96
+ * Saves Head & Footer Code entry to the database as custom fields
97
+ * Outputs code to the website in `wp_head()` and `wp_footer()`
98
+
99
+ == Custom Support ==
100
+
101
+ If you have a custom support need, [please purchase your support ticket here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7AF7P3TFKQ2C2). Support tickets are responded to within 24 hours, but we answer them as soon as possible.
102
+
103
+ **How it works**
104
+
105
+ 1. [Purchase a support ticket via PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=7AF7P3TFKQ2C2)
106
+ 2. You get a chance to provide the best way to contact you and a description of your need
107
+ 3. I contact you as soon as I can (no less than 24 hours) and help resolve your issue
108
+
109
+ **Note:** This is for custom needs for help, not problems with the plugin, or instructions that should already be explain in the description. If you feel there are important details omitted from the description, installation steps, etc. of the plugin, please report them in the Support forum. Thanks!
110
+
111
+ == Upgrade Notice ==