Skip to content

Instantly share code, notes, and snippets.

@ayublin
Last active August 29, 2015 13:56
Show Gist options
  • Save ayublin/8818074 to your computer and use it in GitHub Desktop.
Save ayublin/8818074 to your computer and use it in GitHub Desktop.
Vafpress Post Formats UI Adding New Field (https://github.com/vafour/vafpress-post-formats-ui)
// add new field under gallery post format forms ui
add_action( 'vp_pfui_after_gallery_meta', 'mytheme_add_gallery_type_field' );
// handle the saving of our new field
add_action( 'admin_init' , 'mytheme_admin_init' );
function mytheme_admin_init() {
$post_formats = get_theme_support('post-formats');
if (!empty($post_formats[0]) && is_array($post_formats[0])) {
if (in_array('gallery', $post_formats[0])) {
add_action('save_post', 'mytheme_format_gallery_save_post');
}
}
}
function mytheme_add_gallery_type_field() {
global $post;
$type = get_post_meta($post->ID, '_format_gallery_type', true);
?>
<div class="vp-pfui-elm-block">
<label for="vp-pfui-format-gallery-type"><?php _e('Gallery Type', 'my-theme'); ?></label>
<!-- Radio Button Sample -->
<input type="radio" name="_format_gallery_type" value="option1" id="option1" <?php checked( $type, "option1" ); ?>><label style="display: inline-block;" for="option1">Option 1</label>
<input type="radio" name="_format_gallery_type" value="option2" id="option2" <?php checked( $type, "option2" ); ?>><label style="display: inline-block;" for="option2">Option 2</label>
<input type="radio" name="_format_gallery_type" value="option3" id="option3" <?php checked( $type, "option3" ); ?>><label style="display: inline-block;" for="option3">Option 3</label>
<!-- Select Box Sample -->
<!-- <select name="_format_gallery_type" id="vp-pfui-format-gallery-type">
<option value="option1" <?php selected( $type, "option1" ); ?>>Option 1</option>
<option value="option2" <?php selected( $type, "option2" ); ?>>Option 2</option>
<option value="option3" <?php selected( $type, "option3" ); ?>>Option 3</option>
</select> -->
<!-- Text Box Sample -->
<!-- <input type="text" name="_format_gallery_type" value="<?php echo esc_attr(get_post_meta($post->ID, '_format_gallery_type', true)); ?>" id="vp-pfui-format-gallery-type" tabindex="1" /> -->
</div>
<?php
}
function mytheme_format_gallery_save_post($post_id) {
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return;
}
if (!defined('XMLRPC_REQUEST') && isset($_POST['_format_gallery_type'])) {
update_post_meta($post_id, '_format_gallery_type', $_POST['_format_gallery_type']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment