this->is_blocks() ) { $result['options'][] = array( 'value' => '', 'label' => $field['placeholder'] ); } else { $result['options'][''] = $field['placeholder']; } } foreach ( $options as $index => $option ) { if ( ! isset( $option['key'] ) || ! is_array( $option ) ) { $key = $index; $value = $option; } else { $key = $option['key']; $value = $option['value']; } /* Looks like this code not needed anymore, but keep commented just in case if ( $multiple && empty( $option['key'] ) ) { continue; } */ $key = apply_filters( 'jet-engine/compatibility/translate-string', $key ); $value = apply_filters( 'jet-engine/compatibility/translate-string', $value ); if ( $this->is_blocks() ) { $result['options'][] = array( 'value' => $key, 'label' => $value ); } else { $result['options'][ $key ] = $value; } if ( ! empty( $option['is_checked'] ) ) { if ( $multiple ) { if ( 'checkbox' === $field['type'] && ! $check_is_array ) { $result['default'][ $key ] = 'true'; } else { $result['default'][] = $key; } } else { $result['default'] = $key; } } } return $result; } /** * Prepare field conditions. * * @param array $field * @param array $all_fields * @return array */ public function prepare_field_conditions( $field = array(), $all_fields = array() ) { $result = array(); if ( empty( $field['conditions'] ) ) { return $result; } $result['__relation__'] = ! empty( $field['conditional_relation'] ) ? $field['conditional_relation'] : 'AND'; $result['__terms__'] = array(); foreach ( $field['conditions'] as $condition ) { if ( empty( $condition['field'] ) || empty( $condition['operator'] ) ) { continue; } $condition_field = $this->get_field_args_by_name( $condition['field'], $all_fields ); if ( empty( $condition_field['type'] ) ) { continue; } switch( $condition_field['type'] ) { case 'switcher': $value = ! empty( $condition['value'] ) ? $condition['value'] : false; $value = filter_var( $value, FILTER_VALIDATE_BOOLEAN ); break; case 'checkbox': case 'checkbox-raw': case 'radio': case 'select': if ( in_array( $condition['operator'], array( 'in', 'not_in' ) ) ) { $value = ! empty( $condition['values'] ) ? $condition['values'] : array(); } else { $value = ! empty( $condition['value'] ) ? $condition['value'] : ''; } break; default: $value = ! empty( $condition['value'] ) ? $condition['value'] : ''; if ( in_array( $condition['operator'], array( 'in', 'not_in' ) ) ) { $value = explode( ',', $value ); $value = array_map( 'trim', $value ); } } if ( in_array( $condition['operator'], array( 'empty', '!empty' ) ) ) { $value = ''; } $is_checkbox = ( 'checkbox' === $condition_field['type'] ); $is_multi_select = ( 'select' === $condition_field['type'] ) && ! empty( $condition_field['is_multiple'] ) && filter_var( $condition_field['is_multiple'], FILTER_VALIDATE_BOOLEAN ); switch( $condition['operator'] ) { case 'equal': $operator = '=='; if ( $is_checkbox || $is_multi_select ) { $operator = 'contains'; } break; case 'not_equal': $operator = '!='; if ( $is_checkbox || $is_multi_select ) { $operator = '!contains'; } break; case 'in': $operator = 'in'; if ( $is_checkbox || $is_multi_select ) { $operator = 'intersect'; } break; case 'not_in': $operator = '!in'; if ( $is_checkbox || $is_multi_select ) { $operator = '!intersect'; } break; case 'greater_than': $operator = '>'; break; case 'less_than': $operator = '<'; break; case 'chars_greater_than': $operator = 'length_greater'; break; case 'chars_less_than': $operator = 'length_less'; break; default: $operator = $condition['operator']; } $result['__terms__'][] = array( 'name' => $condition['field'], 'operator' => $operator, 'value' => $value ); } return $result; } /** * Return filtered options list * * @param array $options [description] * @param array $field [description] * @return [type] [description] */ public function filter_options_list( $options = array(), $field = array() ) { return apply_filters( 'jet-engine/meta-fields/field-options', $options, $field, $this ); } /** * Get field type by name. * * @param string $name * @return string|null */ public function get_field_type_by_name( $name ) { $list = wp_list_pluck( $this->meta_box, 'type', 'name' ); return isset( $list[ $name ] ) ? $list[ $name ] : null; } /** * Get field args by name. * * @param string $name * @param array $fields * @return string|null */ public function get_field_args_by_name( $name = null, $fields = array() ) { $names = wp_list_pluck( $fields, 'name' ); $list = array_combine( $names, $fields ); return isset( $list[ $name ] ) ? $list[ $name ] : null; } } }