cptui_register_single_taxonomy

Helper function to register the actual taxonomy.

Description

(null) cptui_register_single_taxonomy( (array) $taxonomy = array() ); 

Returns (null)

Result of register_taxonomy.

Parameters (1)

0. $taxonomy — Optional. (array) => array()
Taxonomy array to register. Optional.

Usage

  1. if ( !function_exists( 'cptui_register_single_taxonomy' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'custom-post-type-ui/custom-post-type-ui.php'; 
  3.  
  4. // Taxonomy array to register. Optional. 
  5. $taxonomy = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = cptui_register_single_taxonomy($taxonomy); 
  9.  

Defined (1)

The function is defined in the following location(s).

/custom-post-type-ui.php  
  1. function cptui_register_single_taxonomy( $taxonomy = array() ) { 
  2.  
  3. $labels = array( 
  4. 'name' => $taxonomy['label'],  
  5. 'singular_name' => $taxonomy['singular_label'],  
  6. ); 
  7.  
  8. $description = ''; 
  9. if ( ! empty( $taxonomy['description'] ) ) { 
  10. $description = $taxonomy['description']; 
  11.  
  12. $preserved = cptui_get_preserved_keys( 'taxonomies' ); 
  13. foreach ( $taxonomy['labels'] as $key => $label ) { 
  14.  
  15. if ( ! empty( $label ) ) { 
  16. $labels[ $key ] = $label; 
  17. } elseif ( empty( $label ) && in_array( $key, $preserved ) ) { 
  18. $labels[ $key ] = cptui_get_preserved_label( 'taxonomies', $key, $taxonomy['label'], $taxonomy['singular_label'] ); 
  19.  
  20. $rewrite = get_disp_boolean( $taxonomy['rewrite'] ); 
  21. if ( false !== get_disp_boolean( $taxonomy['rewrite'] ) ) { 
  22. $rewrite = array(); 
  23. $rewrite['slug'] = ( ! empty( $taxonomy['rewrite_slug'] ) ) ? $taxonomy['rewrite_slug'] : $taxonomy['name']; 
  24. $rewrite['with_front'] = true; 
  25. if ( isset( $taxonomy['rewrite_withfront'] ) ) { 
  26. $rewrite['with_front'] = ( 'false' === disp_boolean( $taxonomy['rewrite_withfront'] ) ) ? false : true; 
  27. $rewrite['hierarchical'] = false; 
  28. if ( isset( $taxonomy['rewrite_hierarchical'] ) ) { 
  29. $rewrite['hierarchical'] = ( 'true' === disp_boolean( $taxonomy['rewrite_hierarchical'] ) ) ? true : false; 
  30.  
  31. if ( in_array( $taxonomy['query_var'], array( 'true', 'false', '0', '1' ) ) ) { 
  32. $taxonomy['query_var'] = get_disp_boolean( $taxonomy['query_var'] ); 
  33. if ( true === $taxonomy['query_var'] && ! empty( $taxonomy['query_var_slug'] ) ) { 
  34. $taxonomy['query_var'] = $taxonomy['query_var_slug']; 
  35.  
  36. $public = ( ! empty( $taxonomy['public'] ) && false === get_disp_boolean( $taxonomy['public'] ) ) ? false : true; 
  37.  
  38. $show_admin_column = ( ! empty( $taxonomy['show_admin_column'] ) && false !== get_disp_boolean( $taxonomy['show_admin_column'] ) ) ? true : false; 
  39.  
  40. $show_in_menu = ( ! empty( $taxonomy['show_in_menu'] ) && false !== get_disp_boolean( $taxonomy['show_in_menu'] ) ) ? true : false; 
  41.  
  42. if ( empty( $taxonomy['show_in_menu'] ) ) { 
  43. $show_in_menu = get_disp_boolean( $taxonomy['show_ui'] ); 
  44.  
  45. $show_in_nav_menus = ( ! empty( $taxonomy['show_in_nav_menus'] ) && false !== get_disp_boolean( $taxonomy['show_in_nav_menus'] ) ) ? true : false; 
  46. if ( empty( $taxonomy['show_in_nav_menus'] ) ) { 
  47. $show_in_nav_menus = $public; 
  48.  
  49. $show_in_rest = ( ! empty( $taxonomy['show_in_rest'] ) && false !== get_disp_boolean( $taxonomy['show_in_rest'] ) ) ? true : false; 
  50.  
  51. $show_in_quick_edit = ( ! empty( $taxonomy['show_in_quick_edit'] ) && false !== get_disp_boolean( $taxonomy['show_in_quick_edit'] ) ) ? true : false; 
  52.  
  53. $rest_base = null; 
  54. if ( ! empty( $taxonomy['rest_base'] ) ) { 
  55. $rest_base = $taxonomy['rest_base']; 
  56.  
  57. $args = array( 
  58. 'labels' => $labels,  
  59. 'label' => $taxonomy['label'],  
  60. 'description' => $description,  
  61. 'public' => $public,  
  62. 'hierarchical' => get_disp_boolean( $taxonomy['hierarchical'] ),  
  63. 'show_ui' => get_disp_boolean( $taxonomy['show_ui'] ),  
  64. 'show_in_menu' => $show_in_menu,  
  65. 'show_in_nav_menus' => $show_in_nav_menus,  
  66. 'query_var' => $taxonomy['query_var'],  
  67. 'rewrite' => $rewrite,  
  68. 'show_admin_column' => $show_admin_column,  
  69. 'show_in_rest' => $show_in_rest,  
  70. 'rest_base' => $rest_base,  
  71. 'show_in_quick_edit' => $show_in_quick_edit,  
  72. ); 
  73.  
  74. $object_type = ( ! empty( $taxonomy['object_types'] ) ) ? $taxonomy['object_types'] : ''; 
  75.  
  76. /** 
  77. * Filters the arguments used for a taxonomy right before registering. 
  78. * @since 1.0.0 
  79. * @since 1.3.0 Added original passed in values array 
  80. * @param array $args Array of arguments to use for registering taxonomy. 
  81. * @param string $value Taxonomy slug to be registered. 
  82. * @param array $taxonomy Original passed in values for taxonomy. 
  83. */ 
  84. $args = apply_filters( 'cptui_pre_register_taxonomy', $args, $taxonomy['name'], $taxonomy ); 
  85.  
  86. return register_taxonomy( $taxonomy['name'], $object_type, $args );