public static function get_post_class($post_type, $post_class = '\\Timber\\Post')
{
$post_class = apply_filters('Timber\\PostClassMap', $post_class);
$post_class_use = '\\Timber\\Post';
if (is_array($post_class)) {
if (isset($post_class[$post_type])) {
$post_class_use = $post_class[$post_type];
} else {
Helper::error_log($post_type . ' not found in ' . print_r($post_class, true));
}
} elseif (is_string($post_class)) {
$post_class_use = $post_class;
} else {
Helper::error_log('Unexpeted value for PostClass: ' . print_r($post_class, true));
}
if (!class_exists($post_class_use) || !(is_subclass_of($post_class_use, '\\Timber\\Post') || is_a($post_class_use, '\\Timber\\Post', true))) {
Helper::error_log('Class ' . $post_class_use . ' either does not exist or implement \\Timber\\Post');
}
return $post_class_use;
}
/** * @param mixed $query * @param string|array $PostClass * @return array|bool|null */ public static function get_post($query = false, $PostClass = '\\Timber\\Post') { // if a post id is passed, grab the post directly if (is_numeric($query)) { $post_type = get_post_type($query); $PostClass = PostGetter::get_post_class($post_type, $PostClass); $post = new $PostClass($query); // get the latest revision if we're dealing with a preview $posts = PostsCollection::maybe_set_preview(array($post)); if ($post = reset($posts)) { return $post; } } $posts = self::get_posts($query, $PostClass); if ($post = reset($posts)) { return $post; } }