Tribe__Events__Pro__Main::ajax_widget_get_terms()
AJAX handler for the Widget Term Select2.
Return
(void)
Source
File: src/Tribe/Main.php
public function ajax_widget_get_terms() {
$disabled = isset( $_POST['disabled'] ) ? $_POST['disabled'] : array();
$search = tribe_get_request_var( 'search', false );
$taxonomies = get_object_taxonomies( Tribe__Events__Main::POSTTYPE, 'objects' );
$taxonomies = array_reverse( $taxonomies );
$results = array();
foreach ( $taxonomies as $tax ) {
$group = array(
'text' => esc_attr( $tax->labels->name ),
'children' => array(),
);
// echo sprintf( "<optgroup id='%s' label='%s'>", esc_attr( $tax->name ), esc_attr( $tax->labels->name ) );
$terms = get_terms( $tax->name, array( 'hide_empty' => false ) );
if ( empty( $terms ) ) {
continue;
}
foreach ( $terms as $term ) {
// This is a workout to make #93598 work
if ( $search && false === strpos( $term->name, $search ) ) {
continue;
}
$group['children'][] = array(
'id' => esc_attr( $term->term_id ),
'text' => esc_html( $term->name ),
'taxonomy' => $tax,
'disabled' => in_array( $term->term_id, $disabled ),
);
}
$results[] = $group;
}
wp_send_json_success( array( 'results' => $results ) );
}