I am trying to debug 'undefined index' errors on the WP backend when debug is set to TRUE. The offending lines are:
if ( !wp_verify_nonce( $_POST['pdwt_meta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
Which I have then changed to check whether the value has been set by adding:
if ( isset( $_POST['pdwt_meta_noncename']) || ! wp_verify_nonce( $_POST['pdwt_meta_noncename'], plugin_basename(__FILE__) )) {
return $post->ID;
}
The addition makes the error disappear but when I enter information on the custom field, it does not save.
This is how the custom field has been set:
echo '<input type="hidden" name="pdwt_meta_noncename" id="pdwt_meta_noncename" value="' .
wp_create_nonce( plugin_basename(__FILE__) ) . '" />';
Here is the save_post
part:
foreach ($pdwt_meta as $key => $value) { // loop through the $pdwt_meta array
if( $post->post_type == 'revision' ) return; // make sure the data isn't stored twice
$value = implode(',', (array)$value); // if $value is in an array, make it a comma seperated value
if(get_post_meta($post->ID, $key, FALSE)) { // if the custom field already has a value
update_post_meta($post->ID, $key, $value);
} else { // AND IF IT DOESN'T ALREADY HAVE A VALUE
add_post_meta($post->ID, $key, $value);
}
if(!$value) delete_post_meta($post->ID, $key); // DELETE IF IT'S EMPTY
}
add_action('save_post', 'pdwt_save_meta', 1, 2); // SAVE THE CUSTOM FIELDS
I did not write this specific part of the theme. Any thoughts on what could be wrong?
save_post
part by the look of itfor this line: wp_nonce_field( basename( __FILE__ ), 'custom_meta_box_nonce' ); In function save_meta() replace this line: if (!wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__))) for this line: if (!isset($_POST['custom_meta_box_nonce']) || !wp_verify_nonce($_POST['custom_meta_box_nonce'], basename(__FILE__)))