| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Registers the `blockspare_template_type` taxonomy. |
| 5 |
* |
| 6 |
* @package Blockspare |
| 7 |
*/ |
| 8 |
|
| 9 |
defined('ABSPATH') || exit; |
| 10 |
|
| 11 |
|
| 12 |
class Blockspare_TB_Template_Type_Taxonomy |
| 13 |
{ |
| 14 |
|
| 15 |
const SLUG = 'blockspare_template_type'; |
| 16 |
|
| 17 |
|
| 18 |
const TYPES = array( |
| 19 |
'header' => 'Header', |
| 20 |
'footer' => 'Footer', |
| 21 |
'front_page' => 'Front Page', |
| 22 |
'single' => 'Singular', |
| 23 |
'archive' => 'Archive', |
| 24 |
'search' => 'Search Results', |
| 25 |
'category' => 'Category', |
| 26 |
'author' => 'Author', |
| 27 |
'tag' => 'Tag', |
| 28 |
'date' => 'Date Archive', |
| 29 |
'404' => '404 Page', |
| 30 |
); |
| 31 |
|
| 32 |
/** |
| 33 |
* Registers the taxonomy and seeds its terms. |
| 34 |
*/ |
| 35 |
public function register() |
| 36 |
{ |
| 37 |
register_taxonomy( |
| 38 |
self::SLUG, |
| 39 |
Blockspare_TB_Template_Post_Type::SLUG, |
| 40 |
array( |
| 41 |
'labels' => array( |
| 42 |
'name' => __('Template Types', 'blockspare'), |
| 43 |
'singular_name' => __('Template Type', 'blockspare'), |
| 44 |
), |
| 45 |
'public' => false, |
| 46 |
'show_ui' => false, // Managed programmatically, not by users, to keep it in sync with the |
| 47 |
'show_in_rest' => true, |
| 48 |
'hierarchical' => false, |
| 49 |
) |
| 50 |
); |
| 51 |
|
| 52 |
$this->seed_terms(); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
private function seed_terms() |
| 57 |
{ |
| 58 |
foreach (self::TYPES as $slug => $label) { |
| 59 |
$slug = (string) $slug; |
| 60 |
|
| 61 |
if (! term_exists($slug, self::SLUG)) { |
| 62 |
wp_insert_term($label, self::SLUG, array('slug' => $slug)); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|