wpalchemy icon indicating copy to clipboard operation
wpalchemy copied to clipboard

Try to find the nonce id in my custom save

Open opicron opened this issue 14 years ago • 3 comments

in my pre_save_check in save_filter (check if the nouce is correct and no autosave is executing) I need to check the metabox id to compare the nounce.

At the moment the metabox class does not have an function to recall the current metaboxid. Would it be possible to return it to the save hooks?

Adding random vars to the save hook is not preferred, it might be better to pass the metabox object.

opicron avatar Dec 14 '10 17:12 opicron

why do you need to compare the nonce? if the "save_filter" or "save_action" are executing it means that the nonce has already been checked and found to be valid?

I do like the idea of perhaps returning the meta box object.

farinspace avatar Dec 15 '10 21:12 farinspace

This is what I've used: check_ajax_referer(); http://codex.wordpress.org/Function_Reference/check_ajax_referer

unless thats not what your looking to do.

zanematthew avatar Oct 26 '11 21:10 zanematthew

i actually needed to check the nonce yesterday b/c i needed to tweak the $_POST variable before it was inserted... and save_action and save_filter can't do that.

the nonce is simply $mb->id() . "_nonce";


echo '<input type="hidden" name="'. $this->id .'_nonce" value="' . wp_create_nonce($this->id) . '" />';

so for instance if you declare a

$document_metabox = new WPAlchemy_MetaBox(array
            (
                'id' => '_document_meta',
                'title' => __('Document',$this->plugin_domain),
                'template' => dirname ( __FILE__ ). '/WPAlchemy/document_meta.php'
            ));

the the nonce name is _document_meta_nonce

and you verify it like so:

wp_verify_nonce($_POST['_document_meta_nonce'], '_document_meta'))

helgatheviking avatar Mar 13 '12 02:03 helgatheviking