advantage_meta_save

The Advantage advantage meta save function.

Description

advantage_meta_save( $post_id ); 

Parameters (1)

0. $post_id
The post id.

Usage

  1. if ( !function_exists( 'advantage_meta_save' ) ) { 
  2. require_once '/inc/lib-admin.php'; 
  3.  
  4. // The post id. 
  5. $post_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = advantage_meta_save($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/inc/lib-admin.php  
  1. function advantage_meta_save( $post_id ) { 
  2. global $advantage_meta_box, $post; 
  3.  
  4. //Verify nonce 
  5. if ( ! isset( $_POST['advantage_meta_box_nonce'] ) ) 
  6. return $post_id; 
  7. if ( ! wp_verify_nonce( $_POST['advantage_meta_box_nonce'], basename( __FILE__ ) ) ) 
  8. return $post_id;  
  9. //Check autosave 
  10. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) 
  11. return $post_id; 
  12.  
  13. //Check permissions 
  14. if ( 'page' == $_POST['post_type'] ) { 
  15. if ( ! current_user_can( 'edit_page', $post_id ) ) 
  16. return $post_id; 
  17. } elseif ( ! current_user_can( 'edit_post', $post_id ) ) { 
  18. return $post_id; 
  19.  
  20. foreach ( $advantage_meta_box[ $post->post_type ]['fields'] as $field ) { 
  21. $old = get_post_meta( $post_id, $field['id'], true ); 
  22. if ( isset( $_POST[ $field['id'] ] ) ) { 
  23. $new = $_POST[ $field['id'] ]; 
  24. if ( $field['type'] == 'number') 
  25. $new = (int) $new; 
  26. else 
  27. $new = '';  
  28.  
  29. if ( $new && $new != $old ) 
  30. update_post_meta( $post_id, $field['id'], $new ); 
  31. elseif ( '' == $new && $old ) 
  32. delete_post_meta( $post_id, $field['id'], $old );