ninja_forms_list_terms_checkboxes

Function that outputs a list of terms so that the user can exclude terms from a list selector.

Description

ninja_forms_list_terms_checkboxes( (string) $field_id = '', (string) $tax_name = '' ); 

Parameters (2)

0. $field_id — Optional. (string) => ''
The field id.
1. $tax_name — Optional. (string) => ''
The tax name.

Usage

  1. if ( !function_exists( 'ninja_forms_list_terms_checkboxes' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/admin/ajax.php'; 
  3.  
  4. // The field id. 
  5. $field_id = ''; 
  6.  
  7. // The tax name. 
  8. $tax_name = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = ninja_forms_list_terms_checkboxes($field_id, $tax_name); 
  12.  

Defined (1)

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

/deprecated/includes/admin/ajax.php  
  1. function ninja_forms_list_terms_checkboxes( $field_id = '', $tax_name = '' ) { 
  2.  
  3. // Bail if we aren't in the admin 
  4. if ( ! is_admin() ) 
  5. return false; 
  6.  
  7. check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' ); 
  8.  
  9. if ( $field_id == '' && isset ( $_POST['field_id'] ) ) { 
  10. $field_id = absint( $_POST['field_id'] ); 
  11. }  
  12.  
  13. if ( $tax_name == '' && isset ( $_POST['tax_name'] ) ) { 
  14. $tax_name = esc_html( $_POST['tax_name'] ); 
  15.  
  16. if ( $field_id != '' && $tax_name != '' ) { 
  17. $field = ninja_forms_get_field_by_id( $field_id ); 
  18. if ( isset ( $field['data']['exclude_terms'] ) ) { 
  19. $exclude_terms = $field['data']['exclude_terms']; 
  20. } else { 
  21. $exclude_terms = ''; 
  22.  
  23. $terms = get_terms( $tax_name, array( 'hide_empty' => false ) ); 
  24. if ( is_array ( $terms ) && !empty ( $terms ) ) { 
  25. ?> 
  26. <h4><?php _e( 'Do not show these terms', 'ninja-forms' );?>:</h4> 
  27. <input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>[exclude_terms]" value=""> 
  28. <?php 
  29. foreach ( $terms as $term ) { 
  30. ?> 
  31. <div> 
  32. <label> 
  33. <input type="checkbox" <?php checked( in_array ( $term->term_id, $exclude_terms ), true );?> name="ninja_forms_field_<?php echo $field_id;?>[exclude_terms][]" value="<?php echo $term->term_id;?>"> 
  34. <?php echo $term->name;?> 
  35. </label> 
  36. </div> 
  37. <?php 
  38.  
  39. if ( isset ( $_POST['from_ajax'] ) && absint( $_POST['from_ajax'] ) == 1 ) { 
  40. die();