WordPress Themes, Plugins and HTML Templates › Forums › Contango WordPress Theme › A glitches & fixes thread for Contango 5.0 › Re: A glitches & fixes thread for Contango 5.0
Caught another PHP Notice — when tried to simply add a post (didn’t create any posts till now, so these notices were just waiting for me from the beginning). It happens even in clean wp 3.9.1 install with Contango 5.0. I suppose this is because I’ve set all notices to be displayed, otherwise everyone would see those notices when creating or updating a post.
So, the problem is in the end of …contangolibmodules.php:
[PHP] /**
* Thirdly we can save the value to the database
* Save Data
*/
/** Kamn Meta Boxes */
$kamn_meta_boxes = kamn_meta_boxes();
foreach( $kamn_meta_boxes as $meta_box ) {
foreach ( $meta_box as $field ) {
$old = get_post_meta( $post_id, $field, true );
$new = $_POST[$field];
if ( $new && $new != $old ) {
update_post_meta( $post_id, $field, sanitize_text_field( $new ) );
} elseif ( ” == $new && $old ) {
delete_post_meta( $post_id, $field, sanitize_text_field ( $old ) );
}
}
} // foreach( $kamn_meta_boxes as $meta_box ) [/PHP]
When I publish/update a post, the loop checks for $_POST[$field] to define $new variable, where $field is kamn_post_media_meta_control, kamn_post_sidebar, kamn_slide_caption_control etc.
The problem is, not all of these $field exist as index in $_POST, in my case non-existent appear to be:
- kamn_post_sidebar
- kamn_slide_caption_control
- kamn_slide_link
- kamn_slide_link_target
- kamn_service_icon
And I get Notices for every of those 5 twice (in two loops).
Notice text is standard (xdebug enabled):
[PHP]Notice: Undefined index: kamn_post_sidebar in …wp-contentthemescontangolibmodules.php on line 728[/PHP]
My fix to this was to replace this line
[PHP]$new = $_POST[$field];[/PHP]
with this:
[PHP]$new = isset( $_POST[$field] ) ? $_POST[$field] : ”;[/PHP]
Then Notices are gone.
What can you say about this? What am I doing wrong so only I encounter the notices?
If it is a real issue (it seems to me it is), you will fix it in next release, right? I don’t have to note my findings for recurrent editing new releases?
Thanks!