Head & Footer Code - Version 1.0.0

Version Description

Initial release of new plugin developed by Aleksandar Urosevic.

=

Download this release

Release Info

Developer urkekg
Plugin Icon Head & Footer Code
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

Files changed (6) hide show
  1. head-footer-code.php +32 -0
  2. inc/front.php +108 -0
  3. inc/helpers.php +41 -0
  4. inc/metaboxes.php +114 -0
  5. inc/settings.php +285 -0
  6. readme.txt +85 -0
head-footer-code.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @link http://urosevic.net
4
+ * @since 1.0.0
5
+ * @package Head_Footer_Code
6
+ *
7
+ * @wordpress-plugin
8
+ * Plugin Name: Head & Footer Code
9
+ * Plugin URI: http://urosevic.net/wordpress/plugins/head-footer-code/
10
+ * Description: Easy add site-wide and/or article specific custom code to head and/or footer sections (before the &lt;/body&gt;) by hooking to <code>wp_head</code> and <code>wp_footer</code>.
11
+ * Version: 1.0.0
12
+ * Author: Aleksandar Urosevic
13
+ * Author URI: http://urosevic.net
14
+ * License: GPL-2.0+
15
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
16
+ * Text Domain: head-footer-code
17
+ * Domain Path: /languages
18
+ */
19
+
20
+ // If this file is called directly, abort.
21
+ if ( ! defined( 'WPINC' ) ) {
22
+ die;
23
+ }
24
+
25
+ // Load files.
26
+ require_once 'inc/helpers.php';
27
+ if ( is_admin() ) {
28
+ require_once 'inc/settings.php';
29
+ require_once 'inc/metaboxes.php';
30
+ } else {
31
+ require_once 'inc/front.php';
32
+ }
inc/front.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Inject site-wide code to head and footer with custom priorty.
4
+ */
5
+ $auhfc_defaults = auhfc_defaults();
6
+ if ( empty( $auhfc_defaults['priority'] ) ) {
7
+ $auhfc_defaults['priority'] = 10;
8
+ }
9
+ add_action( 'wp_head', 'auhfc_wp_head', $auhfc_defaults['priority'] );
10
+ add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_defaults['priority'] );
11
+
12
+ /**
13
+ * Inject site-wide and Article specific head code before </head>
14
+ */
15
+ function auhfc_wp_head() {
16
+
17
+ // Get variables to test
18
+ $auhfc_settings = auhfc_defaults();
19
+ $auhfc_meta = auhfc_get_meta( 'head' );
20
+
21
+ // If no code to inject, simple exit
22
+ if ( empty( $auhfc_settings['head'] ) && empty( $auhfc_meta ) ) {
23
+ return;
24
+ }
25
+
26
+ global $post;
27
+ $behavior = auhfc_get_meta( 'behavior' );
28
+
29
+ // Prepare code output.
30
+ $out = '';
31
+
32
+ // Inject site-wide head code
33
+ if (
34
+ ! empty( $auhfc_settings['head'] ) &&
35
+ (
36
+ 'replace' !== $behavior ||
37
+ ( 'replace' == $behavior && ! in_array( $post->post_type, $auhfc_settings['post_types'] ) ) ||
38
+ ( 'replace' == $behavior && in_array( $post->post_type, $auhfc_settings['post_types'] ) && empty( $auhfc_meta ) )
39
+ )
40
+ ) {
41
+ if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide head section start -->\n"; }
42
+ $out .= $auhfc_settings['head'];
43
+ if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide head section end -->\n"; }
44
+ }
45
+
46
+ // Inject article specific head code if post_type is allowed
47
+ if ( ! empty( $auhfc_meta ) && in_array( $post->post_type, $auhfc_settings['post_types'] ) ) {
48
+ if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific head section start -->\n"; }
49
+ $out .= $auhfc_meta;
50
+ if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific head section end -->\n"; }
51
+ }
52
+
53
+ // Print prepared code.
54
+ echo $out;
55
+
56
+ // Free some memory.
57
+ unset( $out, $auhfc_settings, $auhfc_meta, $behavior );
58
+
59
+ } // END function auhfc_wp_head()
60
+
61
+ /**
62
+ * Inject site-wide and Article specific footer code before the </body>
63
+ */
64
+ function auhfc_wp_footer() {
65
+
66
+ // Get variables to test
67
+ $auhfc_settings = auhfc_defaults();
68
+ $auhfc_meta = auhfc_get_meta( 'footer' );
69
+
70
+ // If no code to inject, simple exit
71
+ if ( empty( $auhfc_settings['footer'] ) && empty( $auhfc_meta ) ) {
72
+ return;
73
+ }
74
+
75
+ global $post;
76
+ $behavior = auhfc_get_meta( 'behavior' );
77
+
78
+ // Prepare code output
79
+ $out = '';
80
+
81
+ // Inject site-wide head code
82
+ if (
83
+ ! empty( $auhfc_settings['footer'] ) &&
84
+ (
85
+ 'replace' !== $behavior ||
86
+ ( 'replace' == $behavior && ! in_array( $post->post_type, $auhfc_settings['post_types'] ) ) ||
87
+ ( 'replace' == $behavior && in_array( $post->post_type, $auhfc_settings['post_types'] ) && empty( $auhfc_meta ) )
88
+ )
89
+ ) {
90
+ if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide footer section start -->\n"; }
91
+ $out .= $auhfc_settings['footer'];
92
+ if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide footer section end -->\n"; }
93
+ }
94
+
95
+ // Inject article specific head code if post_type is allowed
96
+ if ( ! empty( $auhfc_meta ) && in_array( $post->post_type, $auhfc_settings['post_types'] ) ) {
97
+ if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific footer section start -->\n"; }
98
+ $out .= trim( $auhfc_meta );
99
+ if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific footer section end -->\n"; }
100
+ }
101
+
102
+ // Print prepared code.
103
+ echo $out;
104
+
105
+ // Free some memory.
106
+ unset( $out, $auhfc_settings, $auhfc_meta, $behavior );
107
+
108
+ } // END function auhfc_wp_footer()
inc/helpers.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Provide global defaults
5
+ * @return array Arary of defined global values
6
+ */
7
+ function auhfc_defaults() {
8
+ $defaults = array(
9
+ 'head' => '',
10
+ 'footer' => '',
11
+ 'priority' => 10,
12
+ 'post_types' => array( 'post', 'page' ),
13
+ );
14
+ $auhfc_settings = get_option( 'auhfc_settings', $defaults );
15
+ $auhfc_settings = wp_parse_args( $auhfc_settings, $defaults );
16
+ return $auhfc_settings;
17
+ } // END function auhfc_defaults()
18
+
19
+ /**
20
+ * Get values of metabox fields
21
+ * @param string $field_name Post meta field key
22
+ * @return string Post meta field value
23
+ */
24
+ function auhfc_get_meta( $field_name = '' ) {
25
+
26
+ if ( empty( $field_name ) ) {
27
+ return false;
28
+ }
29
+
30
+ global $post, $auhfc_post_meta;
31
+
32
+ $field = get_post_meta( $post->ID, '_auhfc', true );
33
+
34
+ if ( ! empty( $field ) && is_array( $field ) && ! empty( $field[ $field_name ] ) ) {
35
+ return stripslashes_deep( $field[ $field_name ] );
36
+ } elseif ( 'behavior' == $field_name ) {
37
+ return 'append';
38
+ } else {
39
+ return false;
40
+ }
41
+ } // END function auhfc_get_meta( $field_name )
inc/metaboxes.php ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Initialize metabox on proper backend screens
4
+ */
5
+ function auhfc_init_meta_boxes() {
6
+ add_action( 'add_meta_boxes', 'auhfc_add_meta_boxes' );
7
+ add_action( 'save_post', 'auhfc_save' );
8
+ }
9
+ if ( is_admin() ) {
10
+ add_action( 'load-post.php', 'auhfc_init_meta_boxes' );
11
+ add_action( 'load-post-new.php', 'auhfc_init_meta_boxes' );
12
+ }
13
+
14
+ /**
15
+ * This function adds a meta box with a callback function of my_metabox_callback()
16
+ */
17
+ function auhfc_add_meta_boxes() {
18
+
19
+ $auhfc_defaults = auhfc_defaults();
20
+
21
+ foreach ( $auhfc_defaults['post_types'] as $post_type ) {
22
+ add_meta_box(
23
+ 'auhfc-head-footer-code',
24
+ __( 'Head & Footer Code', 'head-footer-code' ),
25
+ 'auhfc_display_html',
26
+ $post_type,
27
+ 'normal',
28
+ 'low'
29
+ );
30
+ }
31
+
32
+ } // END function auhfc_add_meta_boxes()
33
+
34
+ /**
35
+ * Meta box display callback.
36
+ *
37
+ * @param WP_Post $post Current post object.
38
+ */
39
+ function auhfc_display_html( $post ) {
40
+ wp_nonce_field( '_head_footer_code_nonce', 'head_footer_code_nonce' ); ?>
41
+
42
+ <p>Here you can insert article specific code for Head (before the <code>&lt;/head&gt;</code>) and Footer (before the <code>&lt;/body&gt;</code>) sections. They work in exactly the same way as site-wide code, which you can configure under <a href="tools.php?page=head_footer_code">Tools / Head &amp; Footer Code</a>.</p>
43
+
44
+ <table class="form-table">
45
+ <tbody>
46
+ <tr class="widefat">
47
+ <th scope="row">
48
+ <label><?php esc_attr_e( 'Behavior', 'head-footer-code' ); ?></label>
49
+ </th>
50
+ <td>
51
+ <input type="radio" name="auhfc[behavior]" id="auhfc_behavior_append" value="append" <?php echo ( 'append' === auhfc_get_meta( 'behavior' ) ) ? 'checked' : ''; ?>>
52
+ <label for="auhfc_behavior_append">Append to the site-wide code</label><br />
53
+ <input type="radio" name="auhfc[behavior]" id="auhfc_behavior_replace" value="replace" <?php echo ( 'replace' === auhfc_get_meta( 'behavior' ) ) ? 'checked' : ''; ?>>
54
+ <label for="auhfc_behavior_replace">Replace the site-wide code</label>
55
+ </td>
56
+ </tr>
57
+
58
+ <tr class="widefat">
59
+ <th scope="row">
60
+ <label for="auhfc_head"><?php _e( 'Head Code', 'head-footer-code' ); ?></label>
61
+ </th>
62
+ <td>
63
+ <textarea name="auhfc[head]" id="auhfc_head" class="widefat" rows="5"><?php echo auhfc_get_meta( 'head' ); ?></textarea>
64
+ <p>Example: <code>&lt;link rel="stylesheet" href="https://domain.com/path/to/style.css" type="text/css" media="all"&gt;</code></p>
65
+ </td>
66
+ </tr>
67
+ <tr class="widefat">
68
+ <th scope="row">
69
+ <label for="auhfc_footer"><?php _e( 'Footer Code', 'head-footer-code' ); ?></label>
70
+ </th>
71
+ <td>
72
+ <textarea name="auhfc[footer]" id="auhfc_footer" class="widefat" rows="5"><?php echo auhfc_get_meta( 'footer' ); ?></textarea>
73
+ <p>Example: <code>&lt;script type="text/javascript" src="http://domain.com/path/to/script.js"&gt;&lt;/script&gt;</code></p>
74
+ </td>
75
+ </tr>
76
+ </tbody>
77
+ </table>
78
+ <?php
79
+ }
80
+
81
+ /**
82
+ * Save meta box content.
83
+ *
84
+ * @param int $post_id Post ID
85
+ */
86
+ function auhfc_save( $post_id ) {
87
+ if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
88
+ return;
89
+ }
90
+ if ( ! isset( $_POST['head_footer_code_nonce'] ) || ! wp_verify_nonce( $_POST['head_footer_code_nonce'], '_head_footer_code_nonce' ) ) {
91
+ return;
92
+ }
93
+ if ( ! current_user_can( 'edit_post', $post_id ) ) {
94
+ return;
95
+ }
96
+
97
+ if ( ! empty( $_POST['auhfc'] ) ) {
98
+
99
+ $auhfc['head'] = ( ! empty( $_POST['auhfc']['head'] ) ) ? $_POST['auhfc']['head'] : '';
100
+ $auhfc['footer'] = ( ! empty( $_POST['auhfc']['footer'] ) ) ? $_POST['auhfc']['footer'] : '';
101
+ $auhfc['behavior'] = ( ! empty( $_POST['auhfc']['behavior'] ) ) ? $_POST['auhfc']['behavior'] : '';
102
+
103
+ if ( ! empty( $auhfc ) ) {
104
+ update_post_meta( $post_id, '_auhfc', $auhfc );
105
+ }
106
+ }
107
+
108
+ } // END function auhfc_save( $post_id )
109
+
110
+ /*
111
+ Usage: auhfc_get_meta( 'head' )
112
+ Usage: auhfc_get_meta( 'footer' )
113
+ Usage: auhfc_get_meta( 'behavior' )
114
+ */
inc/settings.php ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Initiate settings section and fields.
4
+ add_action( 'admin_init', 'auhfc_settings_init' );
5
+
6
+ // Create menu item for settings page.
7
+ add_action( 'admin_menu', 'auhfc_add_admin_menu' );
8
+
9
+ // Add Settings page link to plugin actions cell.
10
+ add_filter( 'plugin_action_links_head-footer-code/head-footer-code.php', 'auhfc_plugin_settings_link' );
11
+
12
+ // Update links in plugin row on Plugins page.
13
+ add_filter( 'plugin_row_meta', 'auhfc_add_plugin_meta_links', 10, 2 );
14
+
15
+ function auhfc_add_admin_menu( ) {
16
+
17
+ add_submenu_page(
18
+ 'tools.php',
19
+ 'Head & Footer Code',
20
+ 'Head & Footer Code',
21
+ 'manage_options',
22
+ 'head_footer_code',
23
+ 'auhfc_options_page'
24
+ );
25
+
26
+ }
27
+
28
+ /**
29
+ * Register a setting and its sanitization callback
30
+ * define section and settings fields
31
+ */
32
+ function auhfc_settings_init( ) {
33
+
34
+ /**
35
+ * Get settings from options table
36
+ */
37
+ $auhfc_settings = auhfc_defaults();
38
+
39
+ /**
40
+ * Register a setting and its sanitization callback.
41
+ * This is part of the Settings API, which lets you automatically generate
42
+ * wp-admin settings pages by registering your settings and using a few
43
+ * callbacks to control the output.
44
+ */
45
+ register_setting( 'head_footer_code_sitewide_settings', 'auhfc_settings' );
46
+ register_setting( 'head_footer_code_article_settings', 'auhfc_settings' );
47
+
48
+ /**
49
+ * Settings Sections are the groups of settings you see on WordPress settings pages
50
+ * with a shared heading. In your plugin you can add new sections to existing
51
+ * settings pages rather than creating a whole new page. This makes your plugin
52
+ * simpler to maintain and creates less new pages for users to learn.
53
+ * You just tell them to change your setting on the relevant existing page.
54
+ */
55
+ add_settings_section(
56
+ 'head_footer_code_sitewide_settings',
57
+ esc_attr__( 'Site-wide Head and Footer Code', 'head-footer-code' ),
58
+ 'auhfc_sitewide_settings_section_description',
59
+ 'head_footer_code'
60
+ );
61
+
62
+ /**
63
+ * Register a settings field to a settings page and section.
64
+ * This is part of the Settings API, which lets you automatically generate
65
+ * wp-admin settings pages by registering your settings and using a few
66
+ * callbacks to control the output.
67
+ */
68
+ add_settings_field(
69
+ 'auhfc_head_code',
70
+ __( 'HEAD Code', 'head-footer-code' ),
71
+ 'auhfc_textarea_field_render',
72
+ 'head_footer_code',
73
+ 'head_footer_code_sitewide_settings',
74
+ array(
75
+ 'field' => 'auhfc_settings[head]',
76
+ 'value' => $auhfc_settings['head'],
77
+ 'description' => __( 'Code to enqueue in HEAD section', 'head-footer-code' ),
78
+ 'class' => 'widefat',
79
+ 'rows' => 7,
80
+ )
81
+ );
82
+
83
+ add_settings_field(
84
+ 'auhfc_footer_code',
85
+ __( 'FOOTER Code', 'head-footer-code' ),
86
+ 'auhfc_textarea_field_render',
87
+ 'head_footer_code',
88
+ 'head_footer_code_sitewide_settings',
89
+ array(
90
+ 'field' => 'auhfc_settings[footer]',
91
+ 'value' => $auhfc_settings['footer'],
92
+ 'description' => esc_html__( 'Code to enqueue in footer section (before the </body>)', 'head-footer-code' ),
93
+ 'class' => 'widefat',
94
+ 'rows' => 7,
95
+ )
96
+ );
97
+
98
+ add_settings_field(
99
+ 'auhfc_priority',
100
+ __( 'Priority', 'head-footer-code' ),
101
+ 'auhfc_number_field_render',
102
+ 'head_footer_code',
103
+ 'head_footer_code_sitewide_settings',
104
+ array(
105
+ 'field' => 'auhfc_settings[priority]',
106
+ 'value' => $auhfc_settings['priority'],
107
+ 'description' => esc_html__( 'Priority of inserted head and footer code. Default is 10. Larger number inject code closer to </head> and </body>.', 'head-footer-code' ),
108
+ 'class' => 'num',
109
+ 'min' => 1,
110
+ 'max' => 1000,
111
+ 'step' => 1,
112
+ )
113
+ );
114
+
115
+
116
+ /**
117
+ * Settings Sections are the groups of settings you see on WordPress settings pages
118
+ * with a shared heading. In your plugin you can add new sections to existing
119
+ * settings pages rather than creating a whole new page. This makes your plugin
120
+ * simpler to maintain and creates less new pages for users to learn.
121
+ * You just tell them to change your setting on the relevant existing page.
122
+ */
123
+ add_settings_section(
124
+ 'head_footer_code_article_settings',
125
+ esc_attr__( 'Article specific Head and Footer Code', 'head-footer-code' ),
126
+ 'auhfc_article_settings_section_description',
127
+ 'head_footer_code'
128
+ );
129
+
130
+ add_settings_field(
131
+ 'auhfc_post_types',
132
+ __( 'Post types', 'head-footer-code' ),
133
+ 'auhfc_checkbox_group_field_render',
134
+ 'head_footer_code',
135
+ 'head_footer_code_article_settings',
136
+ array(
137
+ 'field' => 'auhfc_settings[post_types]',
138
+ 'items' => get_post_types( array( 'public' => true ) ),
139
+ 'value' => $auhfc_settings['post_types'],
140
+ 'description' => esc_html__( 'Select which post types will have Article specific section. Default is post and page. Please note, even if you have Head/Footer Code set per article and then you disable that post type, article specific code will not be printed but only site-wide code.', 'head-footer-code' ),
141
+ 'class' => 'checkbox',
142
+ )
143
+ );
144
+
145
+ } // END function auhfc_settings_init( )
146
+
147
+ /**
148
+ * This function provides textarea for settings fields
149
+ */
150
+ function auhfc_textarea_field_render( $args ) {
151
+ extract( $args );
152
+ if ( empty( $rows ) ) {
153
+ $rows = 7;
154
+ }
155
+ printf( '<textarea name="%s" id="%s" rows="%s" class="%s">%s</textarea><p class="description">%s</p>', $field, $field, $rows, $class, $value, $description );
156
+ } // END function auhfc_textarea_field_render( $args )
157
+
158
+
159
+ /**
160
+ * This function provides number input for settings fields
161
+ */
162
+ function auhfc_number_field_render( $args ) {
163
+ extract( $args );
164
+ printf(
165
+ '<input type="number" name="%1$s" id="%2$s" value="%3$s" class="%4$s" min="%5$s" max="%6$s" step="%7$s" /><p class="description">%8$s</p>',
166
+ $field, // name
167
+ $field, // id
168
+ $value, // value
169
+ $class, // class
170
+ $min, // min
171
+ $max, // max
172
+ $step, // step
173
+ $description // description
174
+ );
175
+ } // END function auhfc_number_field_render($args)
176
+
177
+ /**
178
+ * This function provides checkbox group for settings fields
179
+ */
180
+ function auhfc_checkbox_group_field_render( $args ) {
181
+
182
+ extract( $args );
183
+
184
+ // Checkbox items.
185
+ $out = '<fieldset>';
186
+
187
+ foreach ( $items as $key => $label ) {
188
+
189
+ $checked = '';
190
+ if ( ! empty( $value ) ) {
191
+ $checked = ( in_array( $key, $value ) ) ? 'checked="checked"' : '';
192
+ }
193
+
194
+ $out .= sprintf(
195
+ '<label for="%s_%s"><input type="checkbox" name="%s[]" id="%s_%s" value="%s" class="%s" %s />%s</label><br>',
196
+ $field,
197
+ $key,
198
+ $field,
199
+ $field,
200
+ $key,
201
+ $key,
202
+ $class,
203
+ $checked,
204
+ $label
205
+ );
206
+ }
207
+
208
+ $out .= '</fieldset>';
209
+ $out .= sprintf( '<p class="description">%s</p>' , $description );
210
+
211
+ echo $out;
212
+
213
+ } // eom settings_field_checkbox()
214
+
215
+ function auhfc_sitewide_settings_section_description( ) {
216
+ ?>
217
+ <p>Define site-wide code and behavior. You can Add custom content like JavaScript, CSS, HTML meta and link tags, Google Analytics, site verification, etc.</p>
218
+ <?php
219
+ } // END function auhfc_sitewide_settings_section_description( )
220
+
221
+ function auhfc_article_settings_section_description( ) {
222
+ ?>
223
+ <p>Define article specific behavior.</p>
224
+ <?php
225
+ } // END function auhfc_article_settings_section_description( )
226
+
227
+ function auhfc_options_page( ) {
228
+
229
+ if ( ! current_user_can( 'manage_options' ) ) {
230
+ wp_die( esc_attr__( 'You do not have sufficient permissions to access this page.' ) );
231
+ }
232
+
233
+ ?>
234
+ <form action='options.php' method='post'>
235
+
236
+ <h1>Head &amp; Footer Code</h1>
237
+
238
+ <?php
239
+ @settings_fields( 'head_footer_code_sitewide_settings' );
240
+ @settings_fields( 'head_footer_code_article_settings' );
241
+ @do_settings_sections( 'head_footer_code' );
242
+ @submit_button();
243
+ ?>
244
+
245
+ </form>
246
+ <?php
247
+
248
+ }
249
+
250
+
251
+ /**
252
+ * Generate Settings link on Plugins page listing
253
+ * @param array $links Array of existing plugin row links.
254
+ * @return array Updated array of plugin row links with link to Settings page
255
+ */
256
+ function auhfc_plugin_settings_link( $links ) {
257
+ $settings_link = '<a href="tools.php?page=head_footer_code">Settings</a>';
258
+ array_unshift( $links, $settings_link );
259
+ return $links;
260
+ } // END public static function auhfc_plugin_settings_link( $links )
261
+
262
+ /**
263
+ * Add link to official plugin pages
264
+ * @param array $links Array of existing plugin row links.
265
+ * @param string $file Path of current plugin file.
266
+ * @return array Array of updated plugin row links
267
+ */
268
+ function auhfc_add_plugin_meta_links( $links, $file ) {
269
+ if ( 'head-footer-code/head-footer-code.php' === $file ) {
270
+ return array_merge(
271
+ $links,
272
+ array(
273
+ sprintf(
274
+ '<a href="https://wordpress.org/support/plugin/head-footer-code" target="_blank">%s</a>',
275
+ __( 'Support' )
276
+ ),
277
+ sprintf(
278
+ '<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=Q6Q762MQ97XJ6" target="_blank">%s</a>',
279
+ __( 'Donate' )
280
+ ),
281
+ )
282
+ );
283
+ }
284
+ return $links;
285
+ } // END function auhfc_add_plugin_meta_links( $links, $file )
readme.txt ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Head & Footer Code ===
2
+ Contributors: urkekg
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8RDRQXPV6YB98
4
+ Tags: wp_head, wp_footer, head footer code, custom head script, custom footer script, google analytics, pixel tracking, tracking code, javascript, scripts, site verification, css
5
+ Requires at least: 3.9
6
+ Tested up to: 4.3
7
+ Stable tag: 1.0.0
8
+ License: GPLv2 or later
9
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
+
11
+ Easy add site-wide and/or article specific custom code to head and/or footer section (before the &lt;/body&gt;) by hooking to wp_head and wp_footer.
12
+
13
+ == Description ==
14
+
15
+ Let we say that you have been told to add some custom code (HTML, JavaScript or CSS style) to page's `<head>` (like site verification code, custom styles, webfont link, etc), or just before `</body>` (like pixel tracking, analytics code, heatmap code, etc), but you are not programmer. Then you can use Head &amp; Footer Code to do that.
16
+
17
+ Simply go to Tools &rarr; Head &amp; Footer Code in your website admin dashboard, and insert custom code to HEAD or FOOTER section (depending what you have to do).
18
+
19
+ If you have to insert some custom code specific for individual article (post, page, custom post type), then you can use Article specific metabox while you editing post/page/custom post type (check out [Screenshots](https://wordpress.org/plugins/head-footer-code/screenshots/)). There you can also set should that specific code be appended to site-wide code defined on **Tools** &rarr; **Head &amp; Footer Code**, or should be overwritten.
20
+
21
+ **Works or broken?**
22
+
23
+ Please, consider to vote for this plugin. When you vote for broken, be so kind and tell in the [Forum](https://wordpress.org/support/plugin/head-footer-code) what is broken. Maybe I might be able to fix it to make the plugin also work for you.
24
+
25
+ **I need your support**
26
+
27
+ It is very hard to continue development and support for this and my other free plugisn without contributions from users like you. If you enjoy using Head &amp; Footer Code and find it useful, please consider [making a donation](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8RDRQXPV6YB98). Your donation will help encourage and support the plugin's continued development and better user support.
28
+
29
+ **Features**
30
+
31
+ * Set site-wide custom content for head page section (before the `</head>`)
32
+ * Set site-wide custom content for footer page section (before the `</body>`)
33
+ * Set article specific custom code for head page section (before the `</head>`)
34
+ * Set article specific custom content for footer page section (before the `</body>`)
35
+ * Choose priority of printed custom code to head/footer sections (lower number mean far from `</head>` and `</body>`, higher number means closer to `</head>` and `</body>`)
36
+ * Choose which post types will have enabled article specific head/footer fields
37
+ * Choose should article specific head/footer code be appended to site-wide code, or will replace site-wide code
38
+ * Site-wide section located under **Tools** > **Head & Footer Code**
39
+ * If you have enabled WP_DEBUG constant in `wp-config.php`, you'll see site-wide and article specific entries in page source code wrapped to commens.
40
+
41
+ == Installation ==
42
+
43
+ Installation of this plugin is fairly easy as any other WordPress plugin.
44
+
45
+ **Standard procedure**
46
+
47
+ 1. Go to **Plugins** &rarr; **Add New**.
48
+ 1. Search for **head footer code**.
49
+ 1. Enter to **Search Plugin** field `had footer code` and press Enter key.
50
+ 1. Locate plugin **Head &amp; Footer Code** and click **Install Now** button.
51
+ 1. After successfully installed plugin click link **Activate Plugin**.
52
+ 1. Visit the **Tools** &rarr; **Head &amp; Footer Code**.
53
+ 1. Add the desired code to proper section.
54
+
55
+ **FTP procedure**
56
+
57
+ 1. Unpack `head-footer-code.zip`
58
+ 1. Upload the whole directory and everything underneath to the `/wp-content/plugins/` directory.
59
+ 1. Activate the plugin through the 'Plugins' menu in WordPress.
60
+ 1. Visit the **Tools** &rarr; **Head &amp; Footer Code** (**Settings** link).
61
+ 1. Add the desired code to proper section.
62
+
63
+ == Frequently Asked Questions ==
64
+
65
+ = Why another one custom code plugin? =
66
+
67
+ Because all other similar plugins could not satisfy my requirements. In general, they have too much features or lack some features I need.
68
+
69
+ == Screenshots ==
70
+
71
+ 1. Head &amp; Footer Code box in Plugin search results
72
+ 2. Site-wide settings page
73
+ 3. Article specific metabox
74
+ 4. Example of custom code inserted to HEAD section (site-wide with appended article specific)
75
+ 5. Example of custom code inserted to FOOTER section (site-wide with appended article specific)
76
+
77
+ == Upgrade Notice ==
78
+
79
+ = 1.0.0 =
80
+ Initial release of new plugin developed by Aleksandar Urosevic.
81
+
82
+ == Changelog ==
83
+
84
+ = 1.0.0 =
85
+ * Initial release.