Advertisement
keha76

Untitled

Jan 27th, 2015
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. function ad_meta_boxes() {
  4.     add_meta_box( 'meta_fields', __('Fields','starter'), 'ad_cb', 'annons', 'side', 'high' );
  5. }
  6. add_action( 'add_meta_boxes', 'ad_meta_boxes');
  7.  
  8. function ad_cb( $post ) {
  9.  
  10.     wp_nonce_field( 'ad_meta_fields', 'ad_nonce' );
  11.  
  12.     $value = get_post_meta( $post->ID, '_price', true );
  13.  
  14.     echo '<label for="ad_price">';
  15.     _e( 'Price', 'starter' );
  16.     echo '</label> ';
  17.     echo '<input type="text" id="ad_price" name="ad_price" value="' . esc_attr( $value ) . '" size="25" />';
  18. }
  19.  
  20. function ad_save_meta( $post_id ) {
  21.  
  22.     if ( ! isset( $_POST['ad_meta_fields'] ) ) {
  23.         return;
  24.     }
  25.     if ( ! wp_verify_nonce( $_POST['ad_meta_fields'], 'ad_nonce' ) ) {
  26.         return;
  27.     }
  28.     if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
  29.         return;
  30.     }
  31.     if ( isset( $_POST['post_type'] ) && 'ad' == $_POST['post_type'] ) {
  32.  
  33.         if ( ! current_user_can( 'edit_ad', $post_id ) ) {
  34.             return;
  35.         }
  36.  
  37.     } else {
  38.  
  39.         if ( ! current_user_can( 'edit_ad', $post_id ) ) {
  40.             return;
  41.         }
  42.     }
  43.     if ( ! isset( $_POST['ad_meta_fields'] ) ) {
  44.         return;
  45.     }
  46.  
  47.     $data = sanitize_text_field( $_POST['price'] );
  48.     update_post_meta( $post_id, 'price', $data );
  49. }
  50. add_action( 'save_post', 'ad_save_meta' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement