cptui_register_single_post_type

Helper function to register the actual post_type.

Description

(null) cptui_register_single_post_type( (array) $post_type = array() ); 

Returns (null)

Result of register_post_type.

Parameters (1)

0. $post_type — Optional. (array) => array()
Post type array to register. Optional.

Usage

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

Defined (1)

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

/custom-post-type-ui.php  
  1. function cptui_register_single_post_type( $post_type = array() ) { 
  2.  
  3. /** 
  4. * Filters the map_meta_cap value. 
  5. * @since 1.0.0 
  6. * @param bool $value True. 
  7. * @param string $name Post type name being registered. 
  8. * @param array $post_type All parameters for post type registration. 
  9. */ 
  10. $post_type['map_meta_cap'] = apply_filters( 'cptui_map_meta_cap', true, $post_type['name'], $post_type ); 
  11.  
  12. /** 
  13. * Filters custom supports parameters for 3rd party plugins. 
  14. * @since 1.0.0 
  15. * @param array $value Empty array to add supports keys to. 
  16. * @param string $name Post type slug being registered. 
  17. * @param array $post_type Array of post type arguments to be registered. 
  18. */ 
  19. $user_supports_params = apply_filters( 'cptui_user_supports_params', array(), $post_type['name'], $post_type ); 
  20.  
  21. if ( is_array( $user_supports_params ) && ! empty( $user_supports_params ) ) { 
  22. if ( is_array( $post_type['supports'] ) ) { 
  23. $post_type['supports'] = array_merge( $post_type['supports'], $user_supports_params ); 
  24. } else { 
  25. $post_type['supports'] = array( $user_supports_params ); 
  26.  
  27. $yarpp = false; // Prevent notices. 
  28. if ( ! empty( $post_type['custom_supports'] ) ) { 
  29. $custom = explode( ', ', $post_type['custom_supports'] ); 
  30. foreach ( $custom as $part ) { 
  31. // We'll handle YARPP separately. 
  32. if ( in_array( $part, array( 'YARPP', 'yarpp' ) ) ) { 
  33. $yarpp = true; 
  34. continue; 
  35. $post_type['supports'][] = trim( $part ); 
  36.  
  37. if ( in_array( 'none', $post_type['supports'] ) ) { 
  38. $post_type['supports'] = false; 
  39.  
  40. $labels = array( 
  41. 'name' => $post_type['label'],  
  42. 'singular_name' => $post_type['singular_label'],  
  43. ); 
  44.  
  45. $preserved = cptui_get_preserved_keys( 'post_types' ); 
  46. foreach ( $post_type['labels'] as $key => $label ) { 
  47.  
  48. if ( ! empty( $label ) ) { 
  49. if ( 'parent' === $key ) { 
  50. $labels['parent_item_colon'] = $label; 
  51. } else { 
  52. $labels[ $key ] = $label; 
  53. } elseif ( empty( $label ) && in_array( $key, $preserved ) ) { 
  54. $labels[ $key ] = cptui_get_preserved_label( 'post_types', $key, $post_type['label'], $post_type['singular_label'] ); 
  55.  
  56. $has_archive = get_disp_boolean( $post_type['has_archive'] ); 
  57. if ( ! empty( $post_type['has_archive_string'] ) ) { 
  58. $has_archive = $post_type['has_archive_string']; 
  59.  
  60. $show_in_menu = get_disp_boolean( $post_type['show_in_menu'] ); 
  61. if ( ! empty( $post_type['show_in_menu_string'] ) ) { 
  62. $show_in_menu = $post_type['show_in_menu_string']; 
  63.  
  64. $rewrite = get_disp_boolean( $post_type['rewrite'] ); 
  65. if ( false !== $rewrite ) { 
  66. // Core converts to an empty array anyway, so safe to leave this instead of passing in boolean true. 
  67. $rewrite = array(); 
  68. $rewrite['slug'] = ( ! empty( $post_type['rewrite_slug'] ) ) ? $post_type['rewrite_slug'] : $post_type['name']; 
  69.  
  70. $rewrite['with_front'] = true; // Default value. 
  71. if ( isset( $post_type['rewrite_withfront'] ) ) { 
  72. $rewrite['with_front'] = ( 'false' === disp_boolean( $post_type['rewrite_withfront'] ) ) ? false : true; 
  73.  
  74. $menu_icon = ( ! empty( $post_type['menu_icon'] ) ) ? $post_type['menu_icon'] : null; 
  75.  
  76. if ( in_array( $post_type['query_var'], array( 'true', 'false', '0', '1' ) ) ) { 
  77. $post_type['query_var'] = get_disp_boolean( $post_type['query_var'] ); 
  78. if ( ! empty( $post_type['query_var_slug'] ) ) { 
  79. $post_type['query_var'] = $post_type['query_var_slug']; 
  80.  
  81. $menu_position = null; 
  82. if ( ! empty( $post_type['menu_position'] ) ) { 
  83. $menu_position = (int) $post_type['menu_position']; 
  84.  
  85. $public = get_disp_boolean( $post_type['public'] ); 
  86. if ( ! empty( $post_type['exclude_from_search'] ) ) { 
  87. $exclude_from_search = get_disp_boolean( $post_type['exclude_from_search'] ); 
  88. } else { 
  89. $exclude_from_search = ( false === $public ) ? true : false; 
  90.  
  91. $queryable = ( ! empty( $post_type['publicly_queryable'] ) && isset( $post_type['publicly_queryable'] ) ) ? get_disp_boolean( $post_type['publicly_queryable'] ) : $public; 
  92.  
  93. if ( empty( $post_type['show_in_nav_menus'] ) ) { 
  94. // Defaults to value of public. 
  95. $post_type['show_in_nav_menus'] = $public; 
  96.  
  97. if ( empty( $post_type['show_in_rest'] ) ) { 
  98. $post_type['show_in_rest'] = false; 
  99.  
  100. $rest_base = null; 
  101. if ( ! empty( $post_type['rest_base'] ) ) { 
  102. $rest_base = $post_type['rest_base']; 
  103.  
  104. $args = array( 
  105. 'labels' => $labels,  
  106. 'description' => $post_type['description'],  
  107. 'public' => get_disp_boolean( $post_type['public'] ),  
  108. 'publicly_queryable' => $queryable,  
  109. 'show_ui' => get_disp_boolean( $post_type['show_ui'] ),  
  110. 'show_in_nav_menus' => get_disp_boolean( $post_type['show_in_nav_menus'] ),  
  111. 'has_archive' => $has_archive,  
  112. 'show_in_menu' => $show_in_menu,  
  113. 'show_in_rest' => get_disp_boolean( $post_type['show_in_rest'] ),  
  114. 'rest_base' => $rest_base,  
  115. 'exclude_from_search' => $exclude_from_search,  
  116. 'capability_type' => $post_type['capability_type'],  
  117. 'map_meta_cap' => $post_type['map_meta_cap'],  
  118. 'hierarchical' => get_disp_boolean( $post_type['hierarchical'] ),  
  119. 'rewrite' => $rewrite,  
  120. 'menu_position' => $menu_position,  
  121. 'menu_icon' => $menu_icon,  
  122. 'query_var' => $post_type['query_var'],  
  123. 'supports' => $post_type['supports'],  
  124. 'taxonomies' => $post_type['taxonomies'],  
  125. ); 
  126.  
  127. if ( true === $yarpp ) { 
  128. $args['yarpp_support'] = $yarpp; 
  129.  
  130. /** 
  131. * Filters the arguments used for a post type right before registering. 
  132. * @since 1.0.0 
  133. * @since 1.3.0 Added original passed in values array 
  134. * @param array $args Array of arguments to use for registering post type. 
  135. * @param string $value Post type slug to be registered. 
  136. * @param array $post_type Original passed in values for post type. 
  137. */ 
  138. $args = apply_filters( 'cptui_pre_register_post_type', $args, $post_type['name'], $post_type ); 
  139.  
  140. return register_post_type( $post_type['name'], $args );