field, array(
'placeholder' => '',
'chosen' => false,
'multiple' => false,
'sortable' => false,
'ajax' => false,
'settings' => array(),
'query_args' => array(),
) );
$this->value = ( is_array( $this->value ) ) ? $this->value : array_filter( (array) $this->value );
echo $this->field_before();
if( isset( $this->field['options'] ) ) {
if( ! empty( $args['ajax'] ) ) {
$args['settings']['data']['type'] = $args['options'];
$args['settings']['data']['nonce'] = wp_create_nonce( 'csf_chosen_ajax_nonce' );
if( ! empty( $args['query_args'] ) ) {
$args['settings']['data']['query_args'] = $args['query_args'];
}
}
$chosen_rtl = ( is_rtl() ) ? ' chosen-rtl' : '';
$multiple_name = ( $args['multiple'] ) ? '[]' : '';
$multiple_attr = ( $args['multiple'] ) ? ' multiple="multiple"' : '';
$chosen_sortable = ( $args['chosen'] && $args['sortable'] ) ? ' csf-chosen-sortable' : '';
$chosen_ajax = ( $args['chosen'] && $args['ajax'] ) ? ' csf-chosen-ajax' : '';
$placeholder_attr = ( $args['chosen'] && $args['placeholder'] ) ? ' data-placeholder="'. $args['placeholder'] .'"' : '';
$field_class = ( $args['chosen'] ) ? ' class="csf-chosen'. $chosen_rtl . $chosen_sortable . $chosen_ajax .'"' : '';
$field_name = $this->field_name( $multiple_name );
$field_attr = $this->field_attributes();
$maybe_options = $this->field['options'];
$chosen_data_attr = ( $args['chosen'] && ! empty( $args['settings'] ) ) ? ' data-chosen-settings="'. esc_attr( json_encode( $args['settings'] ) ) .'"' : '';
if( is_string( $maybe_options ) && ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) {
$options = $this->field_wp_query_data_title( $maybe_options, $this->value );
} else if( is_string( $maybe_options ) ) {
$options = $this->field_data( $maybe_options, false, $args['query_args'] );
} else {
$options = $maybe_options;
}
if( ( is_array( $options ) && ! empty( $options ) ) || ( ! empty( $args['chosen'] ) && ! empty( $args['ajax'] ) ) ) {
if( ! empty( $args['chosen'] ) && ! empty( $args['multiple'] ) ) {
echo '';
$field_name = '_pseudo';
$field_attr = '';
}
echo '';
} else {
echo ( ! empty( $this->field['empty_message'] ) ) ? $this->field['empty_message'] : esc_html__( 'No data provided for this option type.', 'bittumb' );
}
}
echo $this->field_after();
}
public function enqueue() {
if( ! wp_script_is( 'jquery-ui-sortable' ) ) {
wp_enqueue_script( 'jquery-ui-sortable' );
}
}
}
}