cptui_get_current_taxonomy

Get the selected taxonomy from the $_POST global.

Description

(bool|string) cptui_get_current_taxonomy( (bool) $taxonomy_deleted = false ); 

Returns (bool|string)

False on no result, sanitized taxonomy if set.

Parameters (1)

0. $taxonomy_deleted — Optional. (bool) => false
Whether or not a taxonomy was recently deleted. Optional. Default false.

Usage

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

Defined (1)

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

/inc/taxonomies.php  
  1. function cptui_get_current_taxonomy( $taxonomy_deleted = false ) { 
  2.  
  3. $tax = false; 
  4.  
  5. if ( ! empty( $_POST ) ) { 
  6. if ( isset( $_POST['cptui_selected_taxonomy']['taxonomy'] ) ) { 
  7. $tax = sanitize_text_field( $_POST['cptui_selected_taxonomy']['taxonomy'] ); 
  8. } else if ( $taxonomy_deleted ) { 
  9. $taxonomies = cptui_get_taxonomy_data(); 
  10. $tax = key( $taxonomies ); 
  11. } else if ( isset( $_POST['cpt_custom_tax']['name'] ) ) { 
  12. // Return the submitted value. 
  13. if ( ! in_array( $_POST['cpt_custom_tax']['name'], cptui_reserved_taxonomies(), true ) ) { 
  14. $tax = sanitize_text_field( $_POST['cpt_custom_tax']['name'] ); 
  15. } else { 
  16. // Return the original value since user tried to submit a reserved term. 
  17. $tax = sanitize_text_field( $_POST['tax_original'] ); 
  18. } else if ( ! empty( $_GET ) && isset( $_GET['cptui_taxonomy'] ) ) { 
  19. $tax = sanitize_text_field( $_GET['cptui_taxonomy'] ); 
  20. } else { 
  21. $taxonomies = cptui_get_taxonomy_data(); 
  22. if ( ! empty( $taxonomies ) ) { 
  23. // Will return the first array key. 
  24. $tax = key( $taxonomies ); 
  25.  
  26. /** 
  27. * Filters the current taxonomy to edit. 
  28. * @since 1.3.0 
  29. * @param string $tax Taxonomy slug. 
  30. */ 
  31. return apply_filters( 'cptui_current_taxonomy', $tax );