So I created a few custom metaboxes like this, and they all operate this way. They work perfectly the first time I put anything into them, and any time I edit them after that, but if they are emptied, they will no longer update.
add_action( 'admin_menu', 'TFP_meta' );
add_action( 'save_post', 'save_TFP_meta', 10, 2 );
function TFP_meta() {
add_meta_box( 'TFP-meta-box', 'Toll Free', 'TFP_meta_box', 'page', 'side', 'low' );
}
function TFP_meta_box( $object, $box ) { ?>
<p>
<br />
<textarea name="TFP" id="TFP" cols="60" rows="4" tabindex="30" style="width: 97%;"><?php echo wp_specialchars( get_post_meta( $object->ID, 'TFP', true ), 1 ); ?></textarea>
<input type="hidden" name="TFP_meta_box_nonce" value="<?php echo wp_create_nonce( plugin_basename( __FILE__ ) ); ?>" />
<script type="text/javascript">edCanvas = document.getElementById('TFP');edInsertContent = null;</script>
</p>
<?php }
function save_TFP_meta( $post_id, $post ) {
if ( !wp_verify_nonce( $_POST['TFP_meta_box_nonce'], plugin_basename( __FILE__ ) ) )
return $post_id;
if ( !current_user_can( 'edit_post', $post_id ) )
return $post_id;
$TFP_meta_value = get_post_meta( $post_id, 'TFP', true );
$new_TFP_meta_value = stripslashes( $_POST['TFP'] );
if ( $new_TFP_meta_value && '' == $TFP_meta_value )
add_post_meta( $post_id, 'TFP', $new_TFP_meta_value, true );
elseif ( $new_TFP_meta_value != $TFP_meta_value )
update_post_meta( $post_id, 'TFP', $new_TFP_meta_value );
elseif ( '' == $new_TFP_meta_value && $TFP_meta_value )
delete_post_meta( $post_id, 'TFP', $TFP_meta_value );
}
What could be causing this? It seems like maybe just some small bug, or is something in my saving code incorrect?