Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function wedevs_add_top_meta_box() {
- add_meta_box('top-ad-meta-box', __('Top & Highlight Ads', 'appthemes'), 'wedevs_top_price', APP_POST_TYPE, 'normal', 'high');
- }
- add_action( 'admin_menu', 'wedevs_add_top_meta_box' );
- function wedevs_top_price() {
- global $post;
- //if post is a custom post type and only during the first execution of the action quick_edit_custom_box
- if ( $post->post_type == APP_POST_TYPE ) {
- $top = get_post_meta( $post->ID, 'cp_sys_top_price', true );
- $top = ( $top != '' ) ? 'on' : 'off';
- $highlight = get_post_meta( $post->ID, 'cp_sys_highlight_price', true );
- $highlight = ( $highlight != '' ) ? 'on' : 'off';
- ?>
- <table class="form-table ad-meta-table">
- <?php wp_nonce_field( basename( __FILE__ ), 'wedevs_top_highlight_nonce' ); ?>
- <tr>
- <th style="width:20%"><label for="ad-top"><?php _e('Top Ad', 'appthemes'); ?>:</label></th>
- <td class="top-ad">
- <input name="cp_sys_top_price" value="on" type="checkbox" <?php checked( $top, 'on' ); ?> />
- </td>
- </tr>
- <tr>
- <th style="width:20%"><label for="ad-highlight"><?php _e('Highlight Ad', 'appthemes'); ?>:</label></th>
- <td class="ad-highlight">
- <input name="cp_sys_highlight_price" value="on" type="checkbox" <?php checked( $highlight, 'on' ); ?> />
- </td>
- </tr>
- </table>
- <?php
- }
- }
- function wedevs_save_top( $post_id ) {
- // verify this came from the our screen and with proper authorization,
- if ( !wp_verify_nonce($_POST['wedevs_top_highlight_nonce'], basename(__FILE__)) )
- return $post_id;
- // verify if this is an auto save routine.
- // if it is our form and it has not been submitted, dont want to do anything
- if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
- return $post_id;
- // lastly check to make sure this user has permissions to save post fields
- if ( !current_user_can('edit_post', $post_id) )
- return $post_id;
- if( isset( $_POST['cp_sys_top_price'] ) ) {
- update_post_meta( $post_id, 'cp_sys_top_price', $_POST['cp_sys_top_price'] );
- } else {
- delete_post_meta( $post_id, 'cp_sys_top_price' );
- }
- if( isset( $_POST['cp_sys_highlight_price'] ) ) {
- update_post_meta( $post_id, 'cp_sys_highlight_price', $_POST['cp_sys_highlight_price'] );
- } else {
- delete_post_meta( $post_id, 'cp_sys_highlight_price' );
- }
- }
- add_action( 'save_post', 'wedevs_save_top' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement