Created
May 19, 2017 03:19
-
-
Save greenhornet79/d6a594fb2bed5a100ed274f495ed7f2c to your computer and use it in GitHub Desktop.
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
| <?php | |
| function ed_metabox_include_front_page( $display, $meta_box, $cmb ) { | |
| if ( ! isset( $meta_box['show_on']['key'] ) ) { | |
| return $display; | |
| } | |
| if ( 'front-page' !== $meta_box['show_on']['key'] ) { | |
| return $display; | |
| } | |
| $post_id = 0; | |
| // If we're showing it based on ID, get the current ID | |
| if ( isset( $_GET['post'] ) ) { | |
| $post_id = $_GET['post']; | |
| } elseif ( isset( $_POST['post_ID'] ) ) { | |
| $post_id = $_POST['post_ID']; | |
| } | |
| if ( ! $post_id ) { | |
| return false; | |
| } | |
| // Get ID of page set as front page, 0 if there isn't one | |
| $front_page = get_option( 'page_on_front' ); | |
| // there is a front page set and we're on it! | |
| return $post_id == $front_page; | |
| } | |
| add_filter( 'cmb2_show_on', 'ed_metabox_include_front_page', 10, 3 ); | |
| function ed_metabox_show_on_species_page( $display, $meta_box, $cmb ) { | |
| if ( ! isset( $meta_box['show_on']['key'] ) ) { | |
| return $display; | |
| } | |
| if ( 'species-page' !== $meta_box['show_on']['key'] ) { | |
| return $display; | |
| } | |
| $post_id = 0; | |
| // If we're showing it based on ID, get the current ID | |
| if ( isset( $_GET['post'] ) ) { | |
| $post_id = $_GET['post']; | |
| } elseif ( isset( $_POST['post_ID'] ) ) { | |
| $post_id = $_POST['post_ID']; | |
| } | |
| if ( ! $post_id ) { | |
| return false; | |
| } | |
| // Get ID of page set as front page, 0 if there isn't one | |
| $species_page = 7; | |
| // there is a front page set and we're on it! | |
| return $post_id == $species_page; | |
| } | |
| add_filter( 'cmb2_show_on', 'ed_metabox_show_on_species_page', 10, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment