cptui_get_current_post_type

Get the selected post type from the $_POST global.

Description

(bool|string) cptui_get_current_post_type( (bool) $post_type_deleted = false ); 

Returns (bool|string)

$value False on no result, sanitized post type if set.

Parameters (1)

0. $post_type_deleted — Optional. (bool) => false
Whether or not a post type was recently deleted. Optional. Default false.

Usage

  1. if ( !function_exists( 'cptui_get_current_post_type' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'custom-post-type-ui/inc/post-types.php'; 
  3.  
  4. // Whether or not a post type was recently deleted. Optional. Default false. 
  5. $post_type_deleted = false; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = cptui_get_current_post_type($post_type_deleted); 
  9.  

Defined (1)

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

/inc/post-types.php  
  1. function cptui_get_current_post_type( $post_type_deleted = false ) { 
  2.  
  3. $type = false; 
  4.  
  5. if ( ! empty( $_POST ) ) { 
  6. if ( isset( $_POST['cptui_selected_post_type']['post_type'] ) ) { 
  7. $type = sanitize_text_field( $_POST['cptui_selected_post_type']['post_type'] ); 
  8. } else if ( $post_type_deleted ) { 
  9. $post_types = cptui_get_post_type_data(); 
  10. $type = key( $post_types ); 
  11. } else if ( isset( $_POST['cpt_custom_post_type']['name'] ) ) { 
  12. // Return the submitted value. 
  13. if ( ! in_array( $_POST['cpt_custom_post_type']['name'], cptui_reserved_post_types(), true ) ) { 
  14. $type = sanitize_text_field( $_POST['cpt_custom_post_type']['name'] ); 
  15. } else { 
  16. // Return the original value since user tried to submit a reserved term. 
  17. $type = sanitize_text_field( $_POST['cpt_original'] ); 
  18. } else if ( ! empty( $_GET ) && isset( $_GET['cptui_post_type'] ) ) { 
  19. $type = sanitize_text_field( $_GET['cptui_post_type'] ); 
  20. } else { 
  21. $post_types = cptui_get_post_type_data(); 
  22. if ( ! empty( $post_types ) ) { 
  23. // Will return the first array key. 
  24. $type = key( $post_types ); 
  25.  
  26. /** 
  27. * Filters the current post type to edit. 
  28. * @since 1.3.0 
  29. * @param string $type Post type slug. 
  30. */ 
  31. return apply_filters( 'cptui_current_post_type', $type );