Skip to content

Instantly share code, notes, and snippets.

@chrisblackwell
Created September 4, 2014 12:48
Show Gist options
  • Save chrisblackwell/ebbb3bc83acfab4442e5 to your computer and use it in GitHub Desktop.
Save chrisblackwell/ebbb3bc83acfab4442e5 to your computer and use it in GitHub Desktop.
/**
* Saves the meta box field data
*
* @param int $post_id Post ID
*/
function save_meta_boxes( $post_id ) {
// Check if our nonce is set.
if ( ! isset( $_POST['{name}_nonce'] ) ) {
return $post_id;
}
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $_POST['{name}_nonce'], '{save_post}' ) ) {
return $post_id;
}
// Check this is the Contact Custom Post Type
if ( '{post_type_name}' != $_POST['post_type'] ) {
return $post_id;
}
// Check the logged in user has permission to edit this post
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
// OK to save meta data
$email = sanitize_text_field( $_POST['contact_email'] );
update_post_meta( $post_id, '_contact_email', $email );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment