Create and verify a nonce

Create and verify a nonce

All of this is created in a class

// place this in __construct of the class
$this->nonce_name = 'name_' . $my_post_type_slug;
$this->nonce_action = 'saving_posttype_' . $my_post_type_slug;
add_action('save_post', 'save_my_custom_posttype', 10);

// place this in a meta box
echo '
';

// your custom save w/ nonce
function save_my_custom_posttype($post_id) {

	if (isset($_POST[ $this->nonce_name ]) && wp_verify_nonce( $_POST[ $this->nonce_name ], $this->nonce_action ) !== false ) {
		// do something
	}
}

Leave a Reply

Skip to toolbar