ninja_forms_field_filter_populate_term

The Ninja Forms ninja forms field filter populate term function.

Description

ninja_forms_field_filter_populate_term( $data, $field_id ); 

Parameters (2)

0. $data
The data.
1. $field_id
The field id.

Usage

  1. if ( !function_exists( 'ninja_forms_field_filter_populate_term' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/display/fields/list-term-filter.php'; 
  3.  
  4. // The data. 
  5. $data = null; 
  6.  
  7. // The field id. 
  8. $field_id = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = ninja_forms_field_filter_populate_term($data, $field_id); 
  12.  

Defined (1)

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

/deprecated/includes/display/fields/list-term-filter.php  
  1. function ninja_forms_field_filter_populate_term( $data, $field_id ) { 
  2. global $post, $ninja_forms_loading, $ninja_forms_processing; 
  3.  
  4. $add_field = apply_filters( 'ninja_forms_use_post_fields', false ); 
  5. if ( !$add_field ) 
  6. return $data; 
  7.  
  8. if ( isset ( $ninja_forms_loading ) ) { 
  9. $field_row = $ninja_forms_loading->get_field_settings( $field_id ); 
  10. } else if ( isset ( $ninja_forms_processing ) ) { 
  11. $field_row = $ninja_forms_processing->get_field_settings( $field_id ); 
  12.  
  13. $field_type = $field_row['type']; 
  14. $field_data = $field_row['data']; 
  15.  
  16. if ( isset ( $field_data['exclude_terms'] ) ) { 
  17. $exclude_terms = $field_data['exclude_terms']; 
  18. } else { 
  19. $exclude_terms = array(); 
  20.  
  21. if( $field_type == '_list' AND isset( $field_data['populate_term'] ) AND $field_data['populate_term'] != '' ) { 
  22. // Set the selected option if we are editing a post. 
  23. if( is_object( $post ) ) { 
  24. $selected_terms = get_the_terms( $post->ID, $field_data['populate_term'] ); 
  25. }else{ 
  26. $selected_term = ''; 
  27.  
  28. if( is_array( $selected_terms ) ) { 
  29. foreach( $selected_terms as $term ) { 
  30. $selected_term = $term->term_id; 
  31. break; 
  32. } else { 
  33. $selected_term = ''; 
  34. if ( $field_data['list_type'] == 'dropdown' ) { 
  35. $tmp_array = array( array( 'label' => __( '- Select One', 'ninja-forms' ), 'value' => '' ) );  
  36. } else { 
  37. $tmp_array = array(); 
  38.  
  39. $populate_term = $field_data['populate_term']; 
  40. $taxonomies = array( $populate_term ); 
  41. $args = array( 
  42. 'hide_empty' => false,  
  43. 'parent' => 0 
  44. ); 
  45. $data['default_value'] = $selected_term; 
  46. foreach( get_terms( $taxonomies, $args ) as $parent_term ) { 
  47. $tmp_array[] = array( 'label' => $parent_term->name, 'value' => $parent_term->term_id ); 
  48. $child_args = array( 
  49. 'hide_empty' => false,  
  50. 'child_of' => $parent_term->term_id 
  51. ); 
  52. foreach( get_terms( $taxonomies, $child_args ) as $child_term ) { 
  53. $tmp_array[] = array( 'label' => '    '.$child_term->name, 'value' => $child_term->term_id );  
  54.  
  55. $data['list']['options'] = apply_filters( 'ninja_forms_list_terms', $tmp_array, $field_id ); 
  56. $data['list_show_value'] = 1; 
  57. return $data;