WPLib_Posts::get_post PHP Method

get_post() static public method

static public get_post ( WP_Post | object | integer | string | array | null | boolean $_post, string | boolean $post_type = false ) : null | WP_Post
$_post WP_Post | object | integer | string | array | null | boolean
$post_type string | boolean
return null | WP_Post
    static function get_post($_post, $post_type = false)
    {
        switch (gettype($_post)) {
            case 'integer':
                $_post = get_post($_post);
                break;
            case 'string':
                if (is_numeric($_post)) {
                    $_post = get_post(absint($_post));
                } else {
                    if ($post_type) {
                        /*
                         * Get post by slug
                         */
                        $_post = get_page_by_path($_post, OBJECT, $post_type);
                    } else {
                        $_post = null;
                    }
                }
                break;
            case 'array':
                if (isset($_post['ID'])) {
                    $_post = get_post(absint($_post['ID']));
                } else {
                    if (isset($_post['post'])) {
                        $_post = self::get_post($_post['post']);
                    }
                }
                break;
            case 'object':
                if (!is_a($_post, 'WP_Post') && property_exists($_post, 'ID')) {
                    $_post = get_post(absint($_post->ID));
                }
                break;
            default:
                $_post = null;
        }
        return $_post;
    }