cptui_get_post_type_code

Display our copy-able code for registered post types.

Description

cptui_get_post_type_code( (array) $cptui_post_types = array(), (bool) $single = false ); 

Parameters (2)

0. $cptui_post_types — Optional. (array) => array()
Array of post types to render. Optional.
1. $single — Optional. (bool) => false
Whether or not we are rendering a single post type. Optional. Default false.

Usage

  1. if ( !function_exists( 'cptui_get_post_type_code' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'custom-post-type-ui/inc/tools.php'; 
  3.  
  4. // Array of post types to render. Optional. 
  5. $cptui_post_types = array(); 
  6.  
  7. // Whether or not we are rendering a single post type. Optional. Default false. 
  8. $single = false; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = cptui_get_post_type_code($cptui_post_types, $single); 
  12.  

Defined (1)

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

/inc/tools.php  
  1. function cptui_get_post_type_code( $cptui_post_types = array(), $single = false ) { 
  2. // Whitespace very much matters here, thus why it's all flush against the left side. 
  3. if ( ! empty( $cptui_post_types ) ) { 
  4. $callback = 'cptui_register_my_cpts'; 
  5. if ( $single ) { 
  6. $key = key( $cptui_post_types ); 
  7. $callback = 'cptui_register_my_cpts_' . str_replace( '-', '_', $cptui_post_types[ $key ]['name'] ); 
  8. ?> 
  9.  
  10. function <?php echo $callback; ?>() { 
  11. <?php // Space before this line reflects in textarea. 
  12. foreach ( $cptui_post_types as $type ) { 
  13. ?> 
  14.  
  15. add_action( 'init', '<?php echo $callback; ?>' ); 
  16. <?php 
  17. } else { 
  18. _e( 'No post types to display at this time', 'custom-post-type-ui' );