diff --git a/src/classes/tainacan-utils.php b/src/classes/tainacan-utils.php index 1bf8c85a9..acdb51d0e 100644 --- a/src/classes/tainacan-utils.php +++ b/src/classes/tainacan-utils.php @@ -12,4 +12,29 @@ function tainacan_get_api_postdata() { $postdata = file_get_contents("php://input"); $post = json_decode($postdata); return $post; +} + +/** + * Retrieve if the post status is viewable + * @return boollean + */ +if(!function_exists("is_post_status_viewable")) { + function is_post_status_viewable( $post_status ) { + if ( is_scalar( $post_status ) ) { + $post_status = \get_post_status_object( $post_status ); + if ( ! $post_status ) { + return false; + } + } + + if ( + ! \is_object( $post_status ) || + $post_status->internal || + $post_status->protected + ) { + return false; + } + + return $post_status->publicly_queryable || ( $post_status->_builtin && $post_status->public ); + } } \ No newline at end of file