Created
July 27, 2017 11:10
-
-
Save lucymtc/b255d2c3d0dcdb7c22426f6a8567d178 to your computer and use it in GitHub Desktop.
Checks if current screen is Edit screen of a given list of post types.
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 | |
/** | |
* Return true if current screen is edit screen of a post type or list of post types. | |
* | |
* @param string|array $post_type Single or list of post types. | |
* @return boolean | |
*/ | |
function is_edit_screen( $post_types = array() ) { | |
global $pagenow; | |
if ( 'post.php' !== $pagenow ) { | |
return false; | |
} | |
if ( ! is_array( $post_types ) ) { | |
$post_types = array( $post_types ); | |
} | |
if ( ! empty( $post_types ) && function_exists( 'get_current_screen' ) ) { | |
if ( ! in_array( get_current_screen()->post_type, $post_types ) ) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment