Skip to content

Instantly share code, notes, and snippets.

@lucymtc
Created July 27, 2017 11:10
Show Gist options
  • Save lucymtc/b255d2c3d0dcdb7c22426f6a8567d178 to your computer and use it in GitHub Desktop.
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.
<?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