Created
June 13, 2014 16:42
-
-
Save apatton-cnet/67118a0668aab7c8078c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'save_post', '_save_postdata' ); | |
function _save_postdata( $post_id ) { | |
if ( 'location' == $_POST['post_type'] ) { | |
if ( ! current_user_can( 'edit_page', $post_id ) ) | |
return; | |
} else { | |
return; | |
} | |
if ( ! isset( $_POST['_noncename_contact'] ) || ! wp_verify_nonce( $_POST['_noncename_contact'], plugin_basename( __FILE__ ) ) ) { | |
//return; | |
} | |
$meta_keys = array( | |
//meta keys | |
); | |
if ( substr( $_POST['_google_map_tld'], 0, 1) == "." ) | |
$_POST['_google_map_tld'] = substr( $_POST['_google_map_tld'], 1 ); | |
//sanitize checkbox fields | |
$checkbox_array = array( | |
//checkbox meta keys | |
); | |
foreach ( $checkbox_array as $checkbox ) { | |
if ( empty( $_POST[$checkbox] ) ) | |
$_POST[$checkbox] = 'off'; | |
} | |
foreach ( $meta_keys as $meta_key ) { | |
$meta_key = NS_PREFIX . '_' . $meta_key; | |
$old_meta_data = get_post_meta( $post_id, $meta_key, true ); | |
$new_meta_data = sanitize_text_field( $_POST[$meta_key] ); | |
if ( $new_meta_data && $new_meta_data != $old_meta_data ) { | |
update_post_meta( $post_id, $meta_key, $new_meta_data ); | |
} elseif ( '' == $new_meta_data && $old_meta_data) { | |
delete_post_meta( $post_id, $meta_key, $old_meta_data ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment