cptui_get_single_post_type_registery

Create output for single post type to be ready for copy/paste from Get Code.

Description

cptui_get_single_post_type_registery( (array) $post_type = array() ); 

Parameters (1)

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

Usage

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

Defined (1)

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

/inc/tools.php  
  1. function cptui_get_single_post_type_registery( $post_type = array() ) { 
  2.  
  3. /** This filter is documented in custom-post-type-ui/custom-post-type-ui.php */ 
  4. $post_type['map_meta_cap'] = apply_filters( 'cptui_map_meta_cap', 'true', $post_type['name'], $post_type ); 
  5.  
  6. /** This filter is documented in custom-post-type-ui/custom-post-type-ui.php */ 
  7. $user_supports_params = apply_filters( 'cptui_user_supports_params', array(), $post_type['name'], $post_type ); 
  8. if ( is_array( $user_supports_params ) ) { 
  9. $post_type['supports'] = array_merge( $post_type['supports'], $user_supports_params ); 
  10.  
  11. $yarpp = false; // Prevent notices. 
  12. if ( ! empty( $post_type['custom_supports'] ) ) { 
  13. $custom = explode( ', ', $post_type['custom_supports'] ); 
  14. foreach ( $custom as $part ) { 
  15. // We'll handle YARPP separately. 
  16. if ( in_array( $part, array( 'YARPP', 'yarpp' ) ) ) { 
  17. $yarpp = true; 
  18. continue; 
  19. $post_type['supports'][] = $part; 
  20.  
  21. $rewrite_withfront = ''; 
  22. $rewrite = get_disp_boolean( $post_type['rewrite'] ); 
  23. if ( false !== $rewrite ) { 
  24. $rewrite = disp_boolean( $post_type['rewrite'] ); 
  25.  
  26. $rewrite_slug = ' "slug" => "' . $post_type['name'] . '", '; 
  27. if ( ! empty( $post_type['rewrite_slug'] ) ) { 
  28. $rewrite_slug = ' "slug" => "' . $post_type['rewrite_slug'] . '", '; 
  29.  
  30. $withfront = disp_boolean( $post_type['rewrite_withfront'] ); 
  31. if ( ! empty( $withfront ) ) { 
  32. $rewrite_withfront = ' "with_front" => ' . $withfront . ' '; 
  33.  
  34. if ( ! empty( $post_type['rewrite_slug'] ) || ! empty( $post_type['rewrite_withfront'] ) ) { 
  35. $rewrite_start = 'array('; 
  36. $rewrite_end = ')'; 
  37.  
  38. $rewrite = $rewrite_start . $rewrite_slug . $rewrite_withfront . $rewrite_end; 
  39. } else { 
  40. $rewrite = disp_boolean( $post_type['rewrite'] ); 
  41. $has_archive = get_disp_boolean( $post_type['has_archive'] ); 
  42. if ( false !== $has_archive ) { 
  43. $has_archive = disp_boolean( $post_type['has_archive'] ); 
  44. if ( ! empty( $post_type['has_archive_string'] ) ) { 
  45. $has_archive = '"' . $post_type['has_archive_string'] . '"'; 
  46. } else { 
  47. $has_archive = disp_boolean( $post_type['has_archive'] ); 
  48.  
  49. $supports = ''; 
  50. // Do a little bit of php work to get these into strings. 
  51. if ( ! empty( $post_type['supports'] ) && is_array( $post_type['supports'] ) ) { 
  52. $supports = 'array( "' . implode( '", "', $post_type['supports'] ) . '" )'; 
  53.  
  54. if ( in_array( 'none', $post_type['supports'] ) ) { 
  55. $supports = 'false'; 
  56.  
  57. $taxonomies = ''; 
  58. if ( ! empty( $post_type['taxonomies'] ) && is_array( $post_type['taxonomies'] ) ) { 
  59. $taxonomies = 'array( "' . implode( '", "', $post_type['taxonomies'] ) . '" )'; 
  60.  
  61. if ( in_array( $post_type['query_var'], array( 'true', 'false', '0', '1' ) ) ) { 
  62. $post_type['query_var'] = disp_boolean( $post_type['query_var'] ); 
  63. if ( ! empty( $post_type['query_var_slug'] ) ) { 
  64. $post_type['query_var'] = '"' . $post_type['query_var_slug'] . '"'; 
  65.  
  66. if ( empty( $post_type['show_in_rest'] ) ) { 
  67. $post_type['show_in_rest'] = 'false'; 
  68.  
  69. $post_type['description'] = addslashes( $post_type['description'] ); 
  70.  
  71. $my_theme = wp_get_theme(); 
  72. $textdomain = $my_theme->get( 'TextDomain' ); 
  73. ?> 
  74.  
  75. /** 
  76. * Post Type: <?php echo $post_type['label']; ?>. 
  77. */ 
  78.  
  79. $labels = array( 
  80. "name" => __( '<?php echo $post_type['label']; ?>', '<?php echo $textdomain; ?>' ),  
  81. "singular_name" => __( '<?php echo $post_type['singular_label']; ?>', '<?php echo $textdomain; ?>' ),  
  82. <?php 
  83. foreach ( $post_type['labels'] as $key => $label ) { 
  84. if ( ! empty( $label ) ) { 
  85. if ( 'parent' === $key ) { 
  86. // Fix for incorrect label key. See #439. 
  87. echo "\t\t" . '"' . 'parent_item_colon' . '" => __( \'' . $label . '\', \'' . $textdomain . '\' ), ' . "\n"; 
  88. } else { 
  89. echo "\t\t" . '"' . $key . '" => __( \'' . $label . '\', \'' . $textdomain . '\' ), ' . "\n"; 
  90. ?> 
  91. ); 
  92.  
  93. $args = array( 
  94. "label" => __( '<?php echo $post_type['label']; ?>', '<?php echo $textdomain; ?>' ),  
  95. "labels" => $labels,  
  96. "description" => "<?php echo $post_type['description']; ?>",  
  97. "public" => <?php echo disp_boolean( $post_type['public'] ); ?>,  
  98. "publicly_queryable" => <?php echo disp_boolean( $post_type['publicly_queryable'] ); ?>,  
  99. "show_ui" => <?php echo disp_boolean( $post_type['show_ui'] ); ?>,  
  100. "show_in_rest" => <?php echo disp_boolean( $post_type['show_in_rest'] ); ?>,  
  101. "rest_base" => "<?php echo $post_type['rest_base']; ?>",  
  102. "has_archive" => <?php echo $has_archive; ?>,  
  103. "show_in_menu" => <?php echo disp_boolean( $post_type['show_in_menu'] ); ?>,  
  104. <?php if ( ! empty( $post_type['show_in_menu_string'] ) ) { ?> 
  105. "show_in_menu_string" => "<?php echo $post_type['show_in_menu_string']; ?>",  
  106. <?php } ?> 
  107. "exclude_from_search" => <?php echo disp_boolean( $post_type['exclude_from_search'] ); ?>,  
  108. "capability_type" => "<?php echo $post_type['capability_type']; ?>",  
  109. "map_meta_cap" => <?php echo disp_boolean( $post_type['map_meta_cap'] ); ?>,  
  110. "hierarchical" => <?php echo disp_boolean( $post_type['hierarchical'] ); ?>,  
  111. "rewrite" => <?php echo $rewrite; ?>,  
  112. "query_var" => <?php echo $post_type['query_var']; ?>,  
  113. <?php if ( ! empty( $post_type['menu_position'] ) ) { ?> 
  114. "menu_position" => <?php echo $post_type['menu_position']; ?>,  
  115. <?php } ?> 
  116. <?php if ( ! empty( $post_type['menu_icon'] ) ) { ?> 
  117. "menu_icon" => "<?php echo $post_type['menu_icon']; ?>",  
  118. <?php } ?> 
  119. <?php if ( ! empty( $supports ) ) { ?> 
  120. "supports" => <?php echo $supports; ?>,  
  121. <?php } ?> 
  122. <?php if ( ! empty( $taxonomies ) ) { ?> 
  123. "taxonomies" => <?php echo $taxonomies; ?>,  
  124. <?php } ?> 
  125. <?php if ( true === $yarpp ) { ?> 
  126. "yarpp_support" => <?php echo disp_boolean( $yarpp ); ?>,  
  127. <?php } ?> 
  128. ); 
  129.  
  130. register_post_type( "<?php echo $post_type['name']; ?>", $args ); 
  131. <?php