/deprecated/includes/display/processing/term-name-filter.php

  1. <?php if ( ! defined( 'ABSPATH' ) ) exit; 
  2. /** 
  3. * 
  4. * Function to filter the term IDS and return the term names. 
  5. * 
  6. * @since 2.2.51 
  7. * @returns void 
  8. */ 
  9.  
  10. // Make sure that this function isn't already defined. 
  11. if ( !function_exists ( 'ninja_forms_filter_term_ids_for_name' ) ) { 
  12. function ninja_forms_filter_term_ids_for_name( $val, $field_id ) { 
  13. global $ninja_forms_loading, $ninja_forms_processing; 
  14.  
  15.  
  16. $add_field = apply_filters( 'ninja_forms_use_post_fields', false ); 
  17. if ( !$add_field ) 
  18. return $val; 
  19.  
  20. if ( isset ( $ninja_forms_loading ) ) { 
  21. $field_row = $ninja_forms_loading->get_field_settings( $field_id ); 
  22. } else { 
  23. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  24.  
  25. if ( $field_row['type'] == '_list' ) { 
  26. if ( isset( $field_row['data']['populate_term'] ) and !empty ( $field_row['data']['populate_term'] ) ) { 
  27. $tax = $field_row['data']['populate_term']; 
  28. if ( !is_array( $val ) ) { 
  29. if ( strpos( $val, ", " ) !== false ) { 
  30. $val = explode( ", ", $val ); 
  31. }  
  32.  
  33. if ( is_array( $val ) ) { 
  34. $tmp = ''; 
  35. $x = 0; 
  36. foreach ( $val as $v ) { 
  37. $term_obj = get_term( $v, $tax ); 
  38. if ( $term_obj AND !is_wp_error( $term_obj ) ) { 
  39. if ( $x == 0 ) { 
  40. $tmp .= $term_obj->name; 
  41. } else { 
  42. $tmp .= ', '.$term_obj->name; 
  43. $x++;  
  44. $val = $tmp; 
  45. } else { 
  46. $term_obj = get_term( $val, $tax ); 
  47. if ( $term_obj AND !is_wp_error( $term_obj ) ) { 
  48. $val = $term_obj->name;  
  49. }  
  50.  
  51. return $val; 
  52.  
  53. add_filter( 'ninja_forms_email_user_value', 'ninja_forms_filter_term_ids_for_name', 10, 2 ); 
  54. add_filter( 'ninja_forms_export_sub_value', 'ninja_forms_filter_term_ids_for_name', 10, 2 ); 
  55.  
  56. /** 
  57. * 
  58. * Function to filter the term IDS and return the term names for the backend submission editor. 
  59. * 
  60. * @since 2.2.51 
  61. * @returns void 
  62. */ 
  63.  
  64. // Make sure that this function isn't already defined. 
  65. if ( !function_exists ( 'ninja_forms_filter_term_ids_for_name_sub_td' ) ) { 
  66. function ninja_forms_filter_term_ids_for_name_sub_td( $val, $field_id, $sub_id ) { 
  67. $add_field = apply_filters( 'ninja_forms_use_post_fields', false ); 
  68. if ( !$add_field ) 
  69. return $val; 
  70.  
  71. return ninja_forms_filter_term_ids_for_name( $val, $field_id ); 
  72.  
  73. add_filter( 'ninja_forms_view_sub_td', 'ninja_forms_filter_term_ids_for_name_sub_td', 10, 3 ); 
.