function add__website_templates_taxonomy() { global $template_names; register_taxonomy('website_templates', 'wpss_site', array('hierarchical' => true, 'labels' => array('name' => _x('Website Template', 'taxonomy general name'), 'singular_name' => _x('Website-Template', 'taxonomy singular name'), 'search_items' => __('Search Website-Templates'), 'all_items' => __('All Website-Templates'), 'parent_item' => __('Parent Website-Template'), 'parent_item_colon' => __('Parent Website-Template:'), 'edit_item' => __('Edit Website-Template'), 'update_item' => __('Update Website-Template'), 'add_new_item' => __('Add New Website-Template'), 'new_item_name' => __('New RWebsite-Template Name'), 'menu_name' => __('Website Templates')), 'rewrite' => array('slug' => 'console', 'with_front' => false, 'hierarchical' => true))); // convert to meta box to radio buttons $custom_tax_mb = new Taxonomy_Single_Term('website_templates', array('wpss_site')); // Makes a selection required. $custom_tax_mb->set('force_selection', true); // if term 'vanilla' doesn't already exist in website_templates taxonomy... add it (then, it doesn't matter if found in templates dir or not) $term = term_exists('vanilla', 'website_templates'); if ($term == 0 || $term == null) { wp_insert_term('vanilla', 'website_templates'); } /* // Taken this out, because obviously not a secure idea to be looking in a dir outside the web path // Seems a pity to have to replicate the templates somewhwere in the web path... // Steve: if can get template names from template dir, use them...otherwise stick with hardcoded in $template_names array if (get_templates()) { $template_names = get_templates(); } */ foreach ($template_names as $template_name) { // check if template filename already exists as a term in website_templates taxonomy $term = term_exists($template_name, 'website_templates'); // if term doesn't already exist in website_templates taxonomy if ($term == 0 || $term == null) { // insert new template name to taxonomy wp_insert_term($template_name, 'website_templates'); } // close if term doesn't exist. } // close all template names }
/** * Replace default meta box in edit/add view of Post Types * * @param $taxonomy_name * @param $args * * @access private */ private function changeDefaultMetaBox($taxonomy_name, $args) { $custom_tax_mb = new \Taxonomy_Single_Term($taxonomy_name, $this->getPostsTypesNames(), $args['control_type']); foreach ($args as $name => $value) { $custom_tax_mb->set($name, $value); } }