Last active
May 11, 2016 08:54
-
-
Save palicko/e367c6b5be9d9bc00dcab196e263090a to your computer and use it in GitHub Desktop.
CMB2 show_on helper functions ( show_on_front_page, show_on_subpage)
This file contains 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
/** | |
* Helper function to check if we edit front page | |
* @param type $cmb | |
* @param type $cmb | |
* @return type | |
*/ | |
function cmb2_show_if_front_page( $cmb ) { | |
// Don't show this metabox if it's not the front page template | |
if ( $cmb->object_id !== get_option( 'page_on_front' ) ) { | |
return false; | |
} | |
return true; | |
} | |
/** | |
* Helper function to check if we edit subpage (child page) | |
* @param type $cmb | |
* @param type $cmb | |
* @return type | |
*/ | |
function cmb2_show_on_subpage( $cmb ) { | |
$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 the post does have ancestors, show the box | |
if ( get_post_ancestors( $post_id ) ) { | |
return true; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment