ID, '_wp_page_template', true ); if ( $page_template == 'template-home.php' ) { add_meta_box( 'home-page-meta', esc_html__('Featured Section Content'), 'brewio_home_page_meta_content', 'page', 'normal' ); } } } add_action('add_meta_boxes_page', 'brewio_home_page_meta'); //---Home Template Meta Box Content---// function brewio_home_page_meta_content($object, $box){ wp_nonce_field( basename( __FILE__ ), 'brewio_beer_nonce' ); wp_enqueue_script('media-uploader.js', get_template_directory_uri().'/js/media-uploader.js'); wp_enqueue_style('admin.css',get_template_directory_uri().'/admin.css'); wp_enqueue_media(); ?>





post_type ); /* Check if the current user has permission to edit the post. */ if (!current_user_can($post_type->cap->edit_post, $post_id)) return $post_id; if(!class_exists('brewio_menu_meta_item')){ class brewio_menu_meta_item{ function __construct($key, $value){ $this->theKey = $key; $this->newValue = ( isset( $_POST[$value] ) ? $_POST[$value] : '' ); } } }; $metas = [ new brewio_menu_meta_item('brewio_hp_featured_title','brewio_hp_featured_title'), new brewio_menu_meta_item('brewio_hp_featured_content','brewio_hp_featured_content'), new brewio_menu_meta_item('brewio_hp_featured_image','brewio_hp_featured_image'), ]; foreach($metas as $meta){ $meta->oldValue = get_post_meta( $post_id, $meta->theKey, true ); /* If a new meta value was added and there was no previous value, add it. */ if ( $meta->newValue && '' == $meta->oldValue ) add_post_meta( $post_id, $meta->theKey, $meta->newValue, true ); /* If the new meta value does not match the old value, update it. */ elseif ( $meta->newValue && $meta->newValue != $meta->oldValue ) update_post_meta( $post_id, $meta->theKey, $meta->newValue, $meta->oldValue ); /* If there is no new meta value but an old value exists, delete it. */ elseif ( '' == $meta->newValue && $meta->oldValue ) delete_post_meta( $post_id, $meta->theKey, $meta->oldValue ); } } add_action( 'save_post', 'brewio_save_home_page_meta', 10, 2); ?>