Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. /* Save the meta box's post metadata. */
  2. function kk_save_location_map( $post_id, $post ) {
  3.  
  4. /* Verify the nonce before proceeding. */
  5. if ( !isset( $_POST['location_map_nonce'] ) || !wp_verify_nonce( $_POST['location_map_nonce'], basename( __FILE__ ) ) )
  6. return $post_id;
  7.  
  8. /* Get the post type object. */
  9. $post_type = get_post_type_object( $post->post_type );
  10.  
  11. /* Check if the current user has permission to edit the post. */
  12. if ( !current_user_can( $post_type->cap->edit_post, $post_id ) )
  13. return $post_id;
  14.  
  15. /* Get the posted data and sanitize it for use as an HTML class. */
  16. $new_meta_value = ( isset( $_POST['location-map'] ) ? ( $_POST['location-map'] ) : '' );
  17.  
  18. /* Get the meta key. */
  19. $meta_key = 'location-map';
  20.  
  21. /* Get the meta value of the custom field key. */
  22. $meta_value = esc_textarea(get_post_meta( $post_id, $meta_key, true ));
  23.  
  24. /* If a new meta value was added and there was no previous value, add it. */
  25. if ( $new_meta_value && '' == $meta_value )
  26. add_post_meta( $post_id, $meta_key, $new_meta_value, true );
  27.  
  28. /* If the new meta value does not match the old value, update it. */
  29. elseif ( $new_meta_value && $new_meta_value != $meta_value )
  30. update_post_meta( $post_id, $meta_key, $new_meta_value );
  31.  
  32. /* If there is no new meta value but an old value exists, delete it. */
  33. elseif ( '' == $new_meta_value && $meta_value )
  34. delete_post_meta( $post_id, $meta_key, $meta_value );
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement