I really like your clean class structure 🙂 But I have a suggestion that might fix things (based on my experience with nonces and meta boxes from a plug-in I built last weekend):
Don’t try to create the nonce field manually. You currently have:
$nonce = wp_create_nonce( plugin_basename( __FILE__ ) );
...
<input type="hidden" name="argus_edit_visitor" id="argus_edit_visitor" value="{$nonce}" />
The standard way to create this field is using WordPress’ wp_nonce_field()
function. It will add the hidden field for you:
wp_nonce_field( __FILE__, 'argus_edit_visitor' );
Verifying the nonce
You’re verifying against the wrong string. In your code, you created the nonce with __FILE__
but you verify with the string argus_edit_vistor
. You have:
if ( empty($_POST)
OR !isset($_POST['argus_edit_visitor'])
OR !wp_verify_nonce( $_POST['argus_edit_visitor'], 'argus_edit_visitor' ) )
{
echo "Erm. Why?";
return $post->ID;
}
You should have:
if ( empty($_POST)
OR !isset($_POST['argus_edit_visitor'])
OR !wp_verify_nonce( $_POST['argus_edit_visitor'], __FILE__ ) )
{
echo "Erm. Why?";
return $post->ID;
}
I usually use plugin_basename(__FILE__)
when creating nonces. But you shouldn’t run into problems doing it your way so long as the nonce creation and nonce verification happens in the same file.