ninja_forms_list_terms_checkboxes
Function that outputs a list of terms so that the user can exclude terms from a list selector.
Description
Parameters (2)
- 0. $field_id — Optional. (string) =>
''
- The field id.
- 1. $tax_name — Optional. (string) =>
''
- The tax name.
Usage
if ( !function_exists( 'ninja_forms_list_terms_checkboxes' ) ) { require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/admin/ajax.php'; } // The field id. $field_id = ''; // The tax name. $tax_name = ''; // NOTICE! Understand what this does before running. $result = ninja_forms_list_terms_checkboxes($field_id, $tax_name);
Defined (1)
The function is defined in the following location(s).
- /deprecated/includes/admin/ajax.php
- function ninja_forms_list_terms_checkboxes( $field_id = '', $tax_name = '' ) {
- // Bail if we aren't in the admin
- if ( ! is_admin() )
- return false;
- check_ajax_referer( 'nf_ajax', 'nf_ajax_nonce' );
- if ( $field_id == '' && isset ( $_POST['field_id'] ) ) {
- $field_id = absint( $_POST['field_id'] );
- }
- if ( $tax_name == '' && isset ( $_POST['tax_name'] ) ) {
- $tax_name = esc_html( $_POST['tax_name'] );
- }
- if ( $field_id != '' && $tax_name != '' ) {
- $field = ninja_forms_get_field_by_id( $field_id );
- if ( isset ( $field['data']['exclude_terms'] ) ) {
- $exclude_terms = $field['data']['exclude_terms'];
- } else {
- $exclude_terms = '';
- }
- $terms = get_terms( $tax_name, array( 'hide_empty' => false ) );
- if ( is_array ( $terms ) && !empty ( $terms ) ) {
- ?>
- <h4><?php _e( 'Do not show these terms', 'ninja-forms' );?>:</h4>
- <input type="hidden" name="ninja_forms_field_<?php echo $field_id;?>[exclude_terms]" value="">
- <?php
- foreach ( $terms as $term ) {
- ?>
- <div>
- <label>
- <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;?>">
- <?php echo $term->name;?>
- </label>
- </div>
- <?php
- }
- }
- }
- if ( isset ( $_POST['from_ajax'] ) && absint( $_POST['from_ajax'] ) == 1 ) {
- die();
- }
- }