public static function create($post, $load_terms = true)
    {
        // Ex: Taco\Post\Factory::create('Video')
        if (is_string($post) && class_exists($post)) {
            return new $post;
        }

        $original_post = $post;
        if (!is_object($post)) {
            $post = get_post($post);
        }
        if (!is_object($post)) {
            throw new \Exception(sprintf('Post %s not found in the database', json_encode($original_post)));
        }
        
        // TODO Refactor how this works to be more explicit and less guess
        $class = str_replace(' ', '', ucwords(str_replace(Base::SEPARATOR, ' ', $post->post_type)));
        if (!class_exists($class)) {
            $class = str_replace(' ', '\\', ucwords(str_replace(Base::SEPARATOR, ' ', $post->post_type)));
        }
        
        $instance = new $class;
        $instance->load($post, $load_terms);
        return $instance;
    }
public static function create($post, $load_terms = true)
    {
        // Ex: Taco\Post\Factory::create('Video')
        if (is_string($post) && class_exists($post)) {
            return new $post;
        }

        $original_post = $post;
        if (!is_object($post)) {
            $post = get_post($post);
        }
        if (!is_object($post)) {
            throw new \Exception(sprintf('Post %s not found in the database', json_encode($original_post)));
        }
        
        // TODO Refactor how this works to be more explicit and less guess
        $class = str_replace(' ', '', ucwords(str_replace(Base::SEPARATOR, ' ', $post->post_type)));
        if (!class_exists($class)) {
            $class = str_replace(' ', '\\', ucwords(str_replace(Base::SEPARATOR, ' ', $post->post_type)));
        }
        
        $instance = new $class;
        $instance->load($post, $load_terms);
        return $instance;
    }
public static function create ( $ post , $ load_terms = true ) { // Ex: Taco\Post\Factory::create('Video') if ( is_string ( $ post ) && class_exists ( $ post ) ) { return new $ post ; } $ original_post = $ post ; if ( ! is_object ( $ post ) ) { $ post = get_post ( $ post ) ; } if ( ! is_object ( $ post ) ) { throw new \ Exception ( sprintf ( 'Post %s not found in the database' , json_encode ( $ original_post ) ) ) ; } // TODO Refactor how this works to be more explicit and less guess $ class = str_replace ( ' ' , '' , ucwords ( str_replace ( Base :: SEPARATOR , ' ' , $ post -> post_type ) ) ) ; if ( ! class_exists ( $ class ) ) { $ class = str_replace ( ' ' , '\\' , ucwords ( str_replace ( Base :: SEPARATOR , ' ' , $ post -> post_type ) ) ) ; } $ instance = new $ class ; $ instance -> load ( $ post , $ load_terms ) ; return $ instance ; }
Create an instance based on a WP post
This basically autoloads the meta data
@param object $post
@param bool $load_terms
@return object
Create an instance based on a WP post This basically autoloads the meta data