I'm writing a plugin for work (still) and having one more issue.
I've added my meta boxes as needed. However, the problem I'm having occurs when saving the post. My snippets for saving pretty much come from this post. I've also recieved a similar answer here, but it's just not working for some reason. :/
protected function __update_post_meta( $post_id, $field_name, $value = '' )
{
if ( empty( $value ) OR ! $value )
{
delete_post_meta( $post_id, $field_name );
}
elseif ( ! get_post_meta( $post_id, $field_name ) )
{
add_post_meta( $post_id, $field_name, $value );
}
else
{
update_post_meta( $post_id, $field_name, $value );
}
}
The above is called using the following. However, I'm not sure my problem lies with the actual saving now that I think of it. I'm thinking it might be the nonce
which may be throwing it off.
public function _wp_save_post( $post_id, $post )
{
if ( empty($_POST)
OR !isset($_POST['argus_edit_visitor'])
OR !wp_verify_nonce( $_POST['argus_edit_visitor'], 'argus_edit_visitor' ) )
{
return $post->ID;
}
if ( ! current_user_can( 'edit_post', $post->ID ) ) return $post->ID;
// v_f_name | v_l_name | v_workstation | v_id
// Argh!
$this->__update_post_meta( $post->ID, 'v_f_name', $_POST['v_f_name'] );
$this->__update_post_meta( $post->ID, 'v_l_name', $_POST['v_l_name'] );
$this->__update_post_meta( $post->ID, 'v_workstation', $_POST['v_workstation'] );
$this->__update_post_meta( $post->ID, 'v_id', $_POST['v_id'] );
}
The nonce is used like the following: <input type="hidden" name="argus_edit_visitor" id="argus_edit_visitor" value="{$nonce}" />
and created using $nonce = wp_create_nonce( plugin_basename( __FILE__ ) );
. The input field is inside block of html being stored in variable $html. Stackexchange was parsing my html otherwise I'd paste it here.
-Zack
EDIT: Just tested it, and it is the nonce's fault.
EDIT2: Typo on my part, but still doesn't work.