cptui_check_existing_post_type_slugs

Checks if we are trying to register an already registered post type slug.

Description

cptui_check_existing_post_type_slugs( (constant) $slug_exists = false, (string) $post_type_slug = '', (array) $post_types = array() ); 

Parameters (3)

0. $slug_exists — Optional. (constant) => false
Whether or not the post type slug exists. Optional. Default false.
1. $post_type_slug — Optional. (string) => ''
The post type slug being saved. Optional. Default empty string.
2. $post_types — Optional. (array) => array()
Array of CPTUI-registered post types. Optional.

Usage

  1. if ( !function_exists( 'cptui_check_existing_post_type_slugs' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'custom-post-type-ui/inc/post-types.php'; 
  3.  
  4. // Whether or not the post type slug exists. Optional. Default false. 
  5. $slug_exists = false; 
  6.  
  7. // The post type slug being saved. Optional. Default empty string. 
  8. $post_type_slug = ''; 
  9.  
  10. // Array of CPTUI-registered post types. Optional. 
  11. $post_types = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = cptui_check_existing_post_type_slugs($slug_exists, $post_type_slug, $post_types); 
  15.  

Defined (1)

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

/inc/post-types.php  
  1. function cptui_check_existing_post_type_slugs( $slug_exists = false, $post_type_slug = '', $post_types = array() ) { 
  2.  
  3. // If true, then we'll already have a conflict, let's not re-process. 
  4. if ( true === $slug_exists ) { 
  5. return $slug_exists; 
  6.  
  7. // Check if CPTUI has already registered this slug. 
  8. if ( array_key_exists( strtolower( $post_type_slug ), $post_types ) ) { 
  9. return true; 
  10.  
  11. // Check if we're registering a reserved post type slug. 
  12. if ( in_array( $post_type_slug, cptui_reserved_post_types() ) ) { 
  13. return true; 
  14.  
  15. // Check if other plugins have registered non-public this same slug. 
  16. $public = get_post_types( array( '_builtin' => false, 'public' => true ) ); 
  17. $private = get_post_types( array( '_builtin' => false, 'public' => false ) ); 
  18. $registered_post_types = array_merge( $public, $private ); 
  19. if ( in_array( $post_type_slug, $registered_post_types ) ) { 
  20. return true; 
  21.  
  22. // If we're this far, it's false. 
  23. return $slug_exists;