/** * Create Wordpress post types * * @return null */ public function createPostTypes() { // check if passed parameter is an array if (!is_array(PostTypeModel::$types)) { // if it's not, create one $postTypes = array(PostTypeModel::$types); } else { // add already existing array to $postTypes $postTypes = PostTypeModel::$types; } // loop through the $postTypes array foreach ($postTypes as $type) { // make string lowercase and remove spaces and hyphens and replace with underscores $post_type = HelpersModel::formatStripSpaces($type); // run register_post_type for wordpress register_post_type($post_type, array('labels' => array('name' => __($type), 'singular_name' => __(HelpersModel::depluralize($type))), 'public' => true, 'has_archive' => true)); } }
/** * Format an id name * * @param array $parameters * * @return array */ public function formatId($name, $string, $character = '_') { // get total number of characters inside string $stringLength = strlen($string); // create regex word search for ($i = 0; $i < $stringLength; $i++) { if ($i == 0) { $regex = '[' . $string[0] . strtoupper($string[0]) . ']'; } else { $regex .= $string[$i]; } } $regex = (string) '/\\b' . $regex . '\\b/'; // strip the word sidebar if it exists $id = trim(preg_replace($regex, "", $name)); // modify formatting of id name $id = 'sidebar-' . HelpersModel::formatStripSpaces($id, '-'); return $id; }