Created
June 20, 2014 15:51
-
-
Save fredguth/57e23770c3d563890154 to your computer and use it in GitHub Desktop.
Display Metabox on Post Format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Show metabox on post format | |
* @author @fredguth | |
* @link https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress/wiki/Adding-your-own-show_on-filters | |
* | |
* @param bool $display | |
* @param array $meta_box | |
* @return bool display metabox | |
*/ | |
function fg_metabox_show_on_post_format( $display, $meta_box ) { | |
if ( 'post-format' !== $meta_box['show_on']['key'] ) | |
return $display; | |
// Get the current ID | |
if ( isset( $_GET['post'] ) ) { | |
$post_id = $_GET['post']; | |
} elseif ( isset( $_POST['post_ID'] ) ) { | |
$post_id = $_POST['post_ID']; | |
} | |
//return false early if there is no ID | |
if( !isset( $post_id ) ) return false; | |
//Get format of the post | |
$post_format = get_post_format( $post_id ); | |
// If value isn't an array, turn it into one | |
$meta_box['show_on']['value'] = !is_array( $meta_box['show_on']['value'] ) ? array( $meta_box['show_on']['value'] ) : $meta_box['show_on']['value']; | |
return in_array( $post_format, $meta_box['show_on']['value'] ); | |
} | |
add_filter( 'cmb_show_on', 'fg_metabox_show_on_post_format', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment