tareq1988

Top & Highlight Meta

Apr 22nd, 2012
37
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. function wedevs_add_top_meta_box() {
  4.     add_meta_box('top-ad-meta-box', __('Top & Highlight Ads', 'appthemes'), 'wedevs_top_price', APP_POST_TYPE, 'normal', 'high');
  5. }
  6. add_action( 'admin_menu', 'wedevs_add_top_meta_box' );
  7.  
  8. function wedevs_top_price() {
  9.     global $post;
  10.    
  11.     //if post is a custom post type and only during the first execution of the action quick_edit_custom_box
  12.     if ( $post->post_type == APP_POST_TYPE ) {
  13.         $top = get_post_meta( $post->ID, 'cp_sys_top_price', true );
  14.         $top = ( $top != '' ) ? 'on' : 'off';
  15.        
  16.         $highlight = get_post_meta( $post->ID, 'cp_sys_highlight_price', true );
  17.         $highlight = ( $highlight != '' ) ? 'on' : 'off';
  18.         ?>
  19.    
  20.         <table class="form-table ad-meta-table">
  21.             <?php wp_nonce_field( basename( __FILE__ ), 'wedevs_top_highlight_nonce' ); ?>
  22.             <tr>
  23.                 <th style="width:20%"><label for="ad-top"><?php _e('Top Ad', 'appthemes'); ?>:</label></th>
  24.                 <td class="top-ad">
  25.                     <input name="cp_sys_top_price" value="on" type="checkbox" <?php checked( $top, 'on' ); ?> />
  26.                 </td>
  27.             </tr>
  28.            
  29.             <tr>
  30.                 <th style="width:20%"><label for="ad-highlight"><?php _e('Highlight Ad', 'appthemes'); ?>:</label></th>
  31.                 <td class="ad-highlight">
  32.                     <input name="cp_sys_highlight_price" value="on" type="checkbox" <?php checked( $highlight, 'on' ); ?> />
  33.                 </td>
  34.             </tr>
  35.            
  36.         </table>
  37.    
  38. <?php
  39.     }
  40. }
  41.  
  42.  
  43. function wedevs_save_top( $post_id ) {
  44.    
  45.     // verify this came from the our screen and with proper authorization,
  46.     if ( !wp_verify_nonce($_POST['wedevs_top_highlight_nonce'], basename(__FILE__)) )
  47.         return $post_id;
  48.    
  49.     // verify if this is an auto save routine.
  50.     // if it is our form and it has not been submitted, dont want to do anything
  51.     if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
  52.         return $post_id;
  53.  
  54.     // lastly check to make sure this user has permissions to save post fields
  55.     if ( !current_user_can('edit_post', $post_id) )
  56.         return $post_id;
  57.    
  58.     if( isset( $_POST['cp_sys_top_price'] ) ) {
  59.         update_post_meta( $post_id, 'cp_sys_top_price', $_POST['cp_sys_top_price'] );
  60.     } else {
  61.         delete_post_meta( $post_id, 'cp_sys_top_price' );
  62.     }
  63.    
  64.     if( isset( $_POST['cp_sys_highlight_price'] ) ) {
  65.         update_post_meta( $post_id, 'cp_sys_highlight_price', $_POST['cp_sys_highlight_price'] );
  66.     } else {
  67.         delete_post_meta( $post_id, 'cp_sys_highlight_price' );
  68.     }
  69. }
  70.  
  71. add_action( 'save_post', 'wedevs_save_top' );
RAW Paste Data