Version Description
- Fix:
PHP Notice: Trying to get property of non-object in \wp-content\plugins\head-footer-code\inc\front.php on line 41
. - Fix: Overwrite footer content for post/page if post/page template after content have another WP Loop query (like recent posts WP Widget in RHS sidebar).
- Optimize: Avoid reading post meta if not singular or post type not enabled
- Tested in Multisite environment (main and other network websites) on WordPress v4.5-alpha-36504 and theme Twenty Sixteen v1.2-alpha.
Download this release
Release Info
Developer | urkekg |
Plugin | Head & Footer Code |
Version | 1.0.6 |
Comparing to | |
See all releases |
Code changes from version 1.0.5 to 1.0.6
- head-footer-code.php +6 -6
- inc/front.php +64 -24
- inc/helpers.php +20 -6
- inc/settings.php +1 -1
- readme.txt +10 -4
- uninstall.php +1 -1
head-footer-code.php
CHANGED
@@ -1,18 +1,18 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* @link
|
4 |
* @since 1.0.0
|
5 |
* @package Head_Footer_Code
|
6 |
*
|
7 |
* @wordpress-plugin
|
8 |
* Plugin Name: Head & Footer Code
|
9 |
-
* Plugin URI:
|
10 |
-
* Description: Easy add site-wide and/or article specific custom code to head and/or footer sections (before the </head> or </body>) by hooking to <code>wp_head</code> and <code>wp_footer</code>.
|
11 |
-
* Version: 1.0.
|
12 |
* Author: Aleksandar Urosevic
|
13 |
-
* Author URI:
|
14 |
* License: GPL-2.0+
|
15 |
-
* License URI:
|
16 |
* Text Domain: head-footer-code
|
17 |
* Domain Path: /languages
|
18 |
*/
|
1 |
<?php
|
2 |
/**
|
3 |
+
* @link https://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: https://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 </head> or </body>) by hooking to <code>wp_head</code> and <code>wp_footer</code>. Support Multisite environment.
|
11 |
+
* Version: 1.0.6
|
12 |
* Author: Aleksandar Urosevic
|
13 |
+
* Author URI: https://urosevic.net
|
14 |
* License: GPL-2.0+
|
15 |
+
* License URI: https://www.gnu.org/licenses/gpl-2.0.txt
|
16 |
* Text Domain: head-footer-code
|
17 |
* Domain Path: /languages
|
18 |
*/
|
inc/front.php
CHANGED
@@ -6,6 +6,8 @@ $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 |
|
@@ -14,18 +16,37 @@ add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_defaults['priority'] );
|
|
14 |
*/
|
15 |
function auhfc_wp_head() {
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
// Get variables to test
|
18 |
$auhfc_settings = auhfc_defaults();
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
@@ -34,27 +55,27 @@ function auhfc_wp_head() {
|
|
34 |
! empty( $auhfc_settings['head'] ) &&
|
35 |
(
|
36 |
'replace' !== $behavior ||
|
37 |
-
( 'replace' == $behavior && ! in_array( $
|
38 |
-
( 'replace' == $behavior && in_array( $
|
39 |
)
|
40 |
) {
|
41 |
-
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide head section start
|
42 |
$out .= $auhfc_settings['head'];
|
43 |
-
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide head section end
|
44 |
}
|
45 |
|
46 |
// Inject article specific head code if post_type is allowed
|
47 |
-
if ( ! empty( $auhfc_meta ) && in_array( $
|
48 |
-
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific head section start
|
49 |
$out .= $auhfc_meta;
|
50 |
-
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific head section end
|
51 |
}
|
52 |
|
53 |
// Print prepared code.
|
54 |
echo $out;
|
55 |
|
56 |
// Free some memory.
|
57 |
-
unset( $
|
58 |
|
59 |
} // END function auhfc_wp_head()
|
60 |
|
@@ -63,18 +84,37 @@ function auhfc_wp_head() {
|
|
63 |
*/
|
64 |
function auhfc_wp_footer() {
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
// Get variables to test
|
67 |
$auhfc_settings = auhfc_defaults();
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
@@ -83,26 +123,26 @@ function auhfc_wp_footer() {
|
|
83 |
! empty( $auhfc_settings['footer'] ) &&
|
84 |
(
|
85 |
'replace' !== $behavior ||
|
86 |
-
( 'replace' == $behavior && ! in_array( $
|
87 |
-
( 'replace' == $behavior && in_array( $
|
88 |
)
|
89 |
) {
|
90 |
-
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide footer section start
|
91 |
$out .= $auhfc_settings['footer'];
|
92 |
-
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide footer section end
|
93 |
}
|
94 |
|
95 |
// Inject article specific head code if post_type is allowed
|
96 |
-
if ( ! empty( $auhfc_meta ) && in_array( $
|
97 |
-
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific footer section start
|
98 |
$out .= trim( $auhfc_meta );
|
99 |
-
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific footer section end
|
100 |
}
|
101 |
|
102 |
// Print prepared code.
|
103 |
echo $out;
|
104 |
|
105 |
// Free some memory.
|
106 |
-
unset( $
|
107 |
|
108 |
} // END function auhfc_wp_footer()
|
6 |
if ( empty( $auhfc_defaults['priority'] ) ) {
|
7 |
$auhfc_defaults['priority'] = 10;
|
8 |
}
|
9 |
+
|
10 |
+
// Define actions for HEAD and FOOTER
|
11 |
add_action( 'wp_head', 'auhfc_wp_head', $auhfc_defaults['priority'] );
|
12 |
add_action( 'wp_footer', 'auhfc_wp_footer', $auhfc_defaults['priority'] );
|
13 |
|
16 |
*/
|
17 |
function auhfc_wp_head() {
|
18 |
|
19 |
+
// Get post type
|
20 |
+
if ( is_singular() ) {
|
21 |
+
global $wp_the_query;
|
22 |
+
$auhfc_post_type = $wp_the_query->get_queried_object()->post_type;
|
23 |
+
} else {
|
24 |
+
$auhfc_post_type = 'not singular';
|
25 |
+
}
|
26 |
+
|
27 |
// Get variables to test
|
28 |
$auhfc_settings = auhfc_defaults();
|
29 |
+
|
30 |
+
// Get meta for post only if it's singular
|
31 |
+
if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) {
|
32 |
+
$auhfc_meta = auhfc_get_meta( 'head' );
|
33 |
+
$behavior = auhfc_get_meta( 'behavior' );
|
34 |
+
if ( WP_DEBUG ) {
|
35 |
+
$dbg_set = "(type: {$auhfc_post_type}; bahavior: {$behavior})";
|
36 |
+
}
|
37 |
+
} else {
|
38 |
+
$auhfc_meta = '';
|
39 |
+
$behavior = '';
|
40 |
+
if ( WP_DEBUG ) {
|
41 |
+
$dbg_set = "({$auhfc_post_type})";
|
42 |
+
}
|
43 |
+
}
|
44 |
|
45 |
// If no code to inject, simple exit
|
46 |
if ( empty( $auhfc_settings['head'] ) && empty( $auhfc_meta ) ) {
|
47 |
return;
|
48 |
}
|
49 |
|
|
|
|
|
|
|
50 |
// Prepare code output.
|
51 |
$out = '';
|
52 |
|
55 |
! empty( $auhfc_settings['head'] ) &&
|
56 |
(
|
57 |
'replace' !== $behavior ||
|
58 |
+
( 'replace' == $behavior && ! in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) ||
|
59 |
+
( 'replace' == $behavior && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) && empty( $auhfc_meta ) )
|
60 |
)
|
61 |
) {
|
62 |
+
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide head section start {$dbg_set} -->\n"; }
|
63 |
$out .= $auhfc_settings['head'];
|
64 |
+
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide head section end {$dbg_set} -->\n"; }
|
65 |
}
|
66 |
|
67 |
// Inject article specific head code if post_type is allowed
|
68 |
+
if ( ! empty( $auhfc_meta ) && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) {
|
69 |
+
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific head section start {$dbg_set} -->\n"; }
|
70 |
$out .= $auhfc_meta;
|
71 |
+
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific head section end {$dbg_set} -->\n"; }
|
72 |
}
|
73 |
|
74 |
// Print prepared code.
|
75 |
echo $out;
|
76 |
|
77 |
// Free some memory.
|
78 |
+
unset( $auhfc_post_type, $auhfc_settings, $auhfc_meta, $behavior, $out );
|
79 |
|
80 |
} // END function auhfc_wp_head()
|
81 |
|
84 |
*/
|
85 |
function auhfc_wp_footer() {
|
86 |
|
87 |
+
// Get post type
|
88 |
+
if ( is_singular() ) {
|
89 |
+
global $wp_the_query;
|
90 |
+
$auhfc_post_type = $wp_the_query->get_queried_object()->post_type;
|
91 |
+
} else {
|
92 |
+
$auhfc_post_type = 'not singular';
|
93 |
+
}
|
94 |
+
|
95 |
// Get variables to test
|
96 |
$auhfc_settings = auhfc_defaults();
|
97 |
+
|
98 |
+
// Get meta for post only if it's singular
|
99 |
+
if ( 'not singular' !== $auhfc_post_type && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) {
|
100 |
+
$auhfc_meta = auhfc_get_meta( 'footer' );
|
101 |
+
$behavior = auhfc_get_meta( 'behavior' );
|
102 |
+
if ( WP_DEBUG ) {
|
103 |
+
$dbg_set = "(type: {$auhfc_post_type}; bahavior: {$behavior})";
|
104 |
+
}
|
105 |
+
} else {
|
106 |
+
$auhfc_meta = '';
|
107 |
+
$behavior = '';
|
108 |
+
if ( WP_DEBUG ) {
|
109 |
+
$dbg_set = "({$auhfc_post_type})";
|
110 |
+
}
|
111 |
+
}
|
112 |
|
113 |
// If no code to inject, simple exit
|
114 |
if ( empty( $auhfc_settings['footer'] ) && empty( $auhfc_meta ) ) {
|
115 |
return;
|
116 |
}
|
117 |
|
|
|
|
|
|
|
118 |
// Prepare code output
|
119 |
$out = '';
|
120 |
|
123 |
! empty( $auhfc_settings['footer'] ) &&
|
124 |
(
|
125 |
'replace' !== $behavior ||
|
126 |
+
( 'replace' == $behavior && ! in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) ||
|
127 |
+
( 'replace' == $behavior && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) && empty( $auhfc_meta ) )
|
128 |
)
|
129 |
) {
|
130 |
+
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide footer section start {$dbg_set} -->\n"; }
|
131 |
$out .= $auhfc_settings['footer'];
|
132 |
+
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Site-wide footer section end {$dbg_set} -->\n"; }
|
133 |
}
|
134 |
|
135 |
// Inject article specific head code if post_type is allowed
|
136 |
+
if ( ! empty( $auhfc_meta ) && in_array( $auhfc_post_type, $auhfc_settings['post_types'] ) ) {
|
137 |
+
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific footer section start {$dbg_set} -->\n"; }
|
138 |
$out .= trim( $auhfc_meta );
|
139 |
+
if ( WP_DEBUG ) { $out .= "<!-- Head & Footer Code: Article specific footer section end {$dbg_set} -->\n"; }
|
140 |
}
|
141 |
|
142 |
// Print prepared code.
|
143 |
echo $out;
|
144 |
|
145 |
// Free some memory.
|
146 |
+
unset( $auhfc_post_type, $auhfc_settings, $auhfc_meta, $behavior, $out );
|
147 |
|
148 |
} // END function auhfc_wp_footer()
|
inc/helpers.php
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
<?php
|
2 |
-
|
3 |
/**
|
4 |
* Provide global defaults
|
5 |
* @return array Arary of defined global values
|
@@ -9,7 +8,7 @@ function auhfc_defaults() {
|
|
9 |
'head' => '',
|
10 |
'footer' => '',
|
11 |
'priority' => 10,
|
12 |
-
'post_types' => array(),
|
13 |
);
|
14 |
$auhfc_settings = get_option( 'auhfc_settings', $defaults );
|
15 |
$auhfc_settings = wp_parse_args( $auhfc_settings, $defaults );
|
@@ -27,14 +26,29 @@ function auhfc_get_meta( $field_name = '' ) {
|
|
27 |
return false;
|
28 |
}
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
if ( empty( $post ) || ! is_object( $post ) ) {
|
34 |
return false;
|
35 |
}
|
36 |
|
37 |
-
$field = get_post_meta( $
|
38 |
|
39 |
if ( ! empty( $field ) && is_array( $field ) && ! empty( $field[ $field_name ] ) ) {
|
40 |
return stripslashes_deep( $field[ $field_name ] );
|
1 |
<?php
|
|
|
2 |
/**
|
3 |
* Provide global defaults
|
4 |
* @return array Arary of defined global values
|
8 |
'head' => '',
|
9 |
'footer' => '',
|
10 |
'priority' => 10,
|
11 |
+
'post_types' => array(),
|
12 |
);
|
13 |
$auhfc_settings = get_option( 'auhfc_settings', $defaults );
|
14 |
$auhfc_settings = wp_parse_args( $auhfc_settings, $defaults );
|
26 |
return false;
|
27 |
}
|
28 |
|
29 |
+
if ( is_admin() ) {
|
30 |
+
global $post;
|
31 |
+
|
32 |
+
// If $post has not an object, return false
|
33 |
+
if ( empty( $post ) || ! is_object( $post ) ) {
|
34 |
+
return false;
|
35 |
+
}
|
36 |
+
|
37 |
+
$post_id = $post->ID;
|
38 |
+
} else {
|
39 |
+
if ( is_singular() ) {
|
40 |
+
global $wp_the_query;
|
41 |
+
$post_id = $wp_the_query->get_queried_object_id();
|
42 |
+
} else {
|
43 |
+
$post_id = false;
|
44 |
+
}
|
45 |
+
}
|
46 |
|
47 |
+
if ( empty( $post_id ) ) {
|
|
|
48 |
return false;
|
49 |
}
|
50 |
|
51 |
+
$field = get_post_meta( $post_id, '_auhfc', true );
|
52 |
|
53 |
if ( ! empty( $field ) && is_array( $field ) && ! empty( $field[ $field_name ] ) ) {
|
54 |
return stripslashes_deep( $field[ $field_name ] );
|
inc/settings.php
CHANGED
@@ -279,7 +279,7 @@ function auhfc_add_plugin_meta_links( $links, $file ) {
|
|
279 |
__( 'Support' )
|
280 |
),
|
281 |
sprintf(
|
282 |
-
'<a href="
|
283 |
__( 'Donate' )
|
284 |
),
|
285 |
)
|
279 |
__( 'Support' )
|
280 |
),
|
281 |
sprintf(
|
282 |
+
'<a href="https://urosevic.net/wordpress/donate/?donate_for=head-footer-code" target="_blank">%s</a>',
|
283 |
__( 'Donate' )
|
284 |
),
|
285 |
)
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Head & Footer Code ===
|
2 |
Contributors: urkekg
|
3 |
-
Donate link:
|
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.
|
7 |
-
Stable tag: 1.0.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -24,7 +24,7 @@ Please, consider to vote for this plugin. When you vote for broken, be so kind a
|
|
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 & Footer Code and find it useful, please consider [making a donation](https://
|
28 |
|
29 |
**Features**
|
30 |
|
@@ -37,6 +37,7 @@ It is very hard to continue development and support for this and my other free p
|
|
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 comments.
|
|
|
40 |
|
41 |
General settings, including HEAD, FOOTER global code and priority, have been saved to WordPress option `auhfc_settings`.
|
42 |
Each post/page/custom post type specific HEAD and FOOTER code have been saved to post meta `_auhfc`.
|
@@ -84,6 +85,11 @@ Because all other similar plugins could not satisfy my requirements. In general,
|
|
84 |
Initial release of new plugin developed by Aleksandar Urosevic.
|
85 |
|
86 |
== Changelog ==
|
|
|
|
|
|
|
|
|
|
|
87 |
|
88 |
= 1.0.5 =
|
89 |
* Enhance: Add uninstall routine to make some housekeeping on plugin removal.
|
1 |
=== Head & Footer Code ===
|
2 |
Contributors: urkekg
|
3 |
+
Donate link: https://urosevic.net/wordpress/donate/?donate_for=head-footer-code
|
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.5
|
7 |
+
Stable tag: 1.0.6
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
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 & Footer Code and find it useful, please consider [making a donation](https://urosevic.net/wordpress/donate/?donate_for=head-footer-code). Your donation will help encourage and support the plugin's continued development and better user support.
|
28 |
|
29 |
**Features**
|
30 |
|
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 comments.
|
40 |
+
* Support [Multisite](https://codex.wordpress.org/Create_A_Network) environment.
|
41 |
|
42 |
General settings, including HEAD, FOOTER global code and priority, have been saved to WordPress option `auhfc_settings`.
|
43 |
Each post/page/custom post type specific HEAD and FOOTER code have been saved to post meta `_auhfc`.
|
85 |
Initial release of new plugin developed by Aleksandar Urosevic.
|
86 |
|
87 |
== Changelog ==
|
88 |
+
= 1.0.6 =
|
89 |
+
* Fix: `PHP Notice: Trying to get property of non-object in \wp-content\plugins\head-footer-code\inc\front.php on line 41`.
|
90 |
+
* Fix: Overwrite footer content for post/page if post/page template after content have another WP Loop query (like recent posts WP Widget in RHS sidebar).
|
91 |
+
* Optimize: Avoid reading post meta if not singular or post type not enabled
|
92 |
+
* Tested in Multisite environment (main and other network websites) on WordPress v4.5-alpha-36504 and theme Twenty Sixteen v1.2-alpha.
|
93 |
|
94 |
= 1.0.5 =
|
95 |
* Enhance: Add uninstall routine to make some housekeeping on plugin removal.
|
uninstall.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* @link
|
4 |
* @since 1.0.5
|
5 |
* @package Head_Footer_Code
|
6 |
*/
|
1 |
<?php
|
2 |
/**
|
3 |
+
* @link https://urosevic.net
|
4 |
* @since 1.0.5
|
5 |
* @package Head_Footer_Code
|
6 |
*/
|