protected function getModelEntityByString($postType) { try { $modelEntity = ModelEntity::factoryFromString($postType); return $modelEntity->getModel(); } catch (Exception $e) { // don't care, not a strata model. } }
/** * Factories a model entity based on the Wordpress key * @param string $str * @return mixed An instantiated model * @throws Exception */ public static function factoryFromWpQuery() { global $wp_query; if ((bool) $wp_query->is_tax) { $term = get_term_by("slug", $wp_query->query_vars['term'], $wp_query->query_vars['taxonomy']); return ModelEntity::factoryFromString($term->taxonomy, $term); } if ($wp_query->queried_object && get_class($wp_query->queried_object) === "WP_Term") { $term = $wp_query->queried_object; return ModelEntity::factoryFromString($term->taxonomy, $term); } }
private function getStrataModel($post) { if (preg_match('/^cpt_/', $post->post_type)) { try { $modelEntity = ModelEntity::factoryFromString($post->post_type); return $modelEntity->getModel(); } catch (Exception $e) { // we dont care not a Strata model } } }