'Audio URL', 'description' => 'Audio file URL in format: mp3, ogg, wav.', 'id' => 'post-audio', 'type' => 'url', ), // url array( 'label' => 'URL', 'description' => 'Enter the URL', 'id' => 'post-link-url', 'type' => 'url', ), // quote array( 'label' => 'Cite', 'description' => 'Define the title of a work with the cite tag:', 'id' => 'post-quote-url', 'type' => 'text', ), // video array( 'label' => 'Video URL', 'description' => 'YouTube or Vimeo video URL', 'id' => 'post-video-url', 'type' => 'url', ), array( 'label' => 'Video Upload', 'description' => 'Upload video file', 'id' => 'post-video-file', 'type' => 'wysiwyg', ), ); public function __construct() { add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'save_fields' ) ); add_action( 'admin_footer', function(){ ?> screens as $s ) { add_meta_box( 'LiquidPostMeta', __( 'Liquid Post Format Options', 'aihub' ), array( $this, 'meta_box_callback' ), $s, 'normal', 'high' ); } } public function meta_box_callback( $post ) { wp_nonce_field( 'LiquidPostMeta_data', 'LiquidPostMeta_nonce' ); $this->field_generator( $post ); } public function field_generator( $post ) { foreach ( $this->fields as $field ) { $label = ''; $description = isset( $field['description'] ) ? $field['description'] : ''; $meta_value = get_post_meta( $post->ID, $field['id'], true ); if ( empty( $meta_value ) ) { if ( isset( $field['default'] ) ) { $meta_value = $field['default']; } } switch ( $field['type'] ) { case 'select': $input = sprintf( ''; break; case 'pages': $pagesargs = array( 'selected' => $meta_value, 'echo' => 0, 'name' => $field['id'], 'id' => $field['id'], 'post_type' => $field['post_type'], 'show_option_none' => 'Select a template', ); $input = wp_dropdown_pages($pagesargs); break; case 'wysiwyg': ob_start(); wp_editor($meta_value, $field['id'], array( 'media_buttons' => true ) ); $input = ob_get_contents(); ob_end_clean(); break; default: $input = sprintf( '', $field['type'] !== 'color' ? 'style="width: 100%"' : '', $field['id'], $field['id'], $field['type'], $meta_value ); } $this->format_rows( $label, $description, $input ); } } public function format_rows( $label, $description, $input ) { printf( '
%s

%s

%s
', $label, $description, $input ); } public function save_fields( $post_id ) { if ( !isset( $_POST['LiquidPostMeta_nonce'] ) ) { return $post_id; } $nonce = $_POST['LiquidPostMeta_nonce']; if ( !wp_verify_nonce( $nonce, 'LiquidPostMeta_data' ) ) { return $post_id; } if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } foreach ( $this->fields as $field ) { if ( isset( $_POST[ $field['id'] ] ) ) { switch ( $field['type'] ) { case 'email': $_POST[ $field['id'] ] = sanitize_email( $_POST[ $field['id'] ] ); break; case 'text': $_POST[ $field['id'] ] = sanitize_text_field( $_POST[ $field['id'] ] ); break; } update_post_meta( $post_id, $field['id'], $_POST[ $field['id'] ] ); } else if ( $field['type'] === 'checkbox' ) { update_post_meta( $post_id, $field['id'], '0' ); } } } } if ( class_exists('Liquid_PostFormat_Metabox') ) { new Liquid_PostFormat_Metabox; };