Head & Footer Code - Version 1.0.1

Version Description

  • Fix: PHP Notice Trying to get property of non-object
  • Optimize: Remove attachment post type from available to select as no reason to have custom head/footer code on attachments
  • Optimize: Settings code cleanup
Download this release

Release Info

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

Code changes from version 1.0.0 to 1.0.1

Files changed (4) hide show
  1. head-footer-code.php +1 -1
  2. inc/helpers.php +5 -0
  3. inc/settings.php +17 -12
  4. readme.txt +6 -1
head-footer-code.php CHANGED
@@ -8,7 +8,7 @@
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+
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.1
12
  * Author: Aleksandar Urosevic
13
  * Author URI: http://urosevic.net
14
  * License: GPL-2.0+
inc/helpers.php CHANGED
@@ -29,6 +29,11 @@ function auhfc_get_meta( $field_name = '' ) {
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 ] ) ) {
29
 
30
  global $post, $auhfc_post_meta;
31
 
32
+ // If $post has not an object, return false
33
+ if ( empty( $post ) || ! is_object( $post ) ) {
34
+ return false;
35
+ }
36
+
37
  $field = get_post_meta( $post->ID, '_auhfc', true );
38
 
39
  if ( ! empty( $field ) && is_array( $field ) && ! empty( $field[ $field_name ] ) ) {
inc/settings.php CHANGED
@@ -112,7 +112,6 @@ function auhfc_settings_init( ) {
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
@@ -127,6 +126,10 @@ function auhfc_settings_init( ) {
127
  'head_footer_code'
128
  );
129
 
 
 
 
 
130
  add_settings_field(
131
  'auhfc_post_types',
132
  __( 'Post types', 'head-footer-code' ),
@@ -135,7 +138,7 @@ function auhfc_settings_init( ) {
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',
@@ -152,7 +155,14 @@ function auhfc_textarea_field_render( $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
 
@@ -162,9 +172,8 @@ function auhfc_textarea_field_render( $args ) {
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
@@ -192,13 +201,9 @@ function auhfc_checkbox_group_field_render( $args ) {
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
@@ -206,7 +211,7 @@ function auhfc_checkbox_group_field_render( $args ) {
206
  }
207
 
208
  $out .= '</fieldset>';
209
- $out .= sprintf( '<p class="description">%s</p>' , $description );
210
 
211
  echo $out;
212
 
112
  )
113
  );
114
 
 
115
  /**
116
  * Settings Sections are the groups of settings you see on WordPress settings pages
117
  * with a shared heading. In your plugin you can add new sections to existing
126
  'head_footer_code'
127
  );
128
 
129
+ // Prepare clean list of post types w/o attachment
130
+ $clean_post_types = get_post_types( array( 'public' => true ) );
131
+ unset( $clean_post_types['attachment'] );
132
+
133
  add_settings_field(
134
  'auhfc_post_types',
135
  __( 'Post types', 'head-footer-code' ),
138
  'head_footer_code_article_settings',
139
  array(
140
  'field' => 'auhfc_settings[post_types]',
141
+ 'items' => $clean_post_types,
142
  'value' => $auhfc_settings['post_types'],
143
  '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' ),
144
  'class' => 'checkbox',
155
  if ( empty( $rows ) ) {
156
  $rows = 7;
157
  }
158
+ printf(
159
+ '<textarea name="%1$s" id="%1$s" rows="%2$s" class="%3$s">%4$s</textarea><p class="description">%5$s</p>',
160
+ $field,
161
+ $rows,
162
+ $class,
163
+ $value,
164
+ $description
165
+ );
166
  } // END function auhfc_textarea_field_render( $args )
167
 
168
 
172
  function auhfc_number_field_render( $args ) {
173
  extract( $args );
174
  printf(
175
+ '<input type="number" name="%1$s" id="%1$s" value="%2$s" class="%3$s" min="%4$s" max="%5$s" step="%6$s" /><p class="description">%7$s</p>',
176
+ $field, // name/id
 
177
  $value, // value
178
  $class, // class
179
  $min, // min
201
  }
202
 
203
  $out .= sprintf(
204
+ '<label for="%1$s_%2$s"><input type="checkbox" name="%1$s[]" id="%1$s_%2$s" value="%2$s" class="%3$s" %4$s />%5$s</label><br>',
205
  $field,
206
  $key,
 
 
 
 
207
  $class,
208
  $checked,
209
  $label
211
  }
212
 
213
  $out .= '</fieldset>';
214
+ $out .= sprintf( '<p class="description">%s</p>', $description );
215
 
216
  echo $out;
217
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
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
 
@@ -81,5 +81,10 @@ Initial release of new plugin developed by Aleksandar Urosevic.
81
 
82
  == Changelog ==
83
 
 
 
 
 
 
84
  = 1.0.0 =
85
  * Initial release.
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.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
81
 
82
  == Changelog ==
83
 
84
+ = 1.0.1 =
85
+ * Fix: PHP Notice Trying to get property of non-object
86
+ * Optimize: Remove `attachment` post type from available to select as no reason to have custom head/footer code on attachments
87
+ * Optimize: Settings code cleanup
88
+
89
  = 1.0.0 =
90
  * Initial release.