Return the post type in for admin pages
/**
* Return the post type for admin pages
*/
class Return_Admin_Post_Type {
/**
* Initialize the class and set its properties.
*/
public function __construct( $post_type = array() ) {
$this->get_post_type();
}
/**
* Determine the type of page and return it's post type
*
* @return string the post type
* @global $post
* @global $typenow
* @global $current_screen
* @global $pagenow
*/
public function get_post_type() {
global $post, $typenow, $current_screen, $pagenow;
if($post && $post->post_type) {
return $post->post_type;
} elseif($typenow) {
return $typenow;
} elseif($current_screen && $current_screen->post_type) {
return $current_screen->post_type;
} elseif(isset($_REQUEST['post_type'])) {
return sanitize_key( $_REQUEST['post_type'] );
} elseif(!isset($_REQUEST['post_type']) && $pagenow == 'edit.php' ) {
return 'post';
} elseif(!isset($_REQUEST['post_type']) && $pagenow == 'post-new.php' ) {
return 'post';
} elseif(isset($_GET['post'])) {
$thispost = get_post($_GET['post']);
return $thispost->post_type;
} else {
return null;
}
}
}
/**
* Initialize the class
*
* @example $variable = new Return_Admin_Post_Type();;
*/
/**
* Call the function
*
* @example $working_variable = $variable->get_post_type();
*/