'user_id', 'name' => 'user_id', 'value' => isset( $args['default'] ) ? $args['default'] : null, 'placeholder' => esc_html__( 'Enter username', 'opalestate-pro' ), 'label' => null, 'desc' => null, 'class' => '', 'disabled' => false, 'autocomplete' => 'off', 'data' => false, ]; $args = wp_parse_args( $args, $defaults ); $args['class'] = 'opalestate-ajax-user-search ' . $args['class']; $output = ''; $output .= $this->text_field( $args ); $output .= ''; return $output; } /** * Text Field * * Renders an HTML Text field. * * @param array $args Arguments for the text field. * * @return string The text field. * @since 1.0 * @access public * */ public function text_field( $field_args, $args = [] ) { $defaults = [ 'id' => '', 'value' => isset( $field_args['default'] ) ? $field_args['default'] : null, 'name' => '', 'description' => null, 'placeholder' => '', 'class' => 'regular-text form-control', 'disabled' => false, 'autocomplete' => 'off', 'data' => false, 'default' => '', 'required' => false, ]; $args = wp_parse_args( $field_args, $defaults ); $disabled = ''; if ( $args['disabled'] ) { $disabled = ' disabled="disabled"'; } $data = ''; if ( ! empty( $args['data'] ) ) { foreach ( $args['data'] as $key => $value ) { $data .= 'data-' . $key . '="' . $value . '" '; } } if ( $args['required'] ) { $data .= ' required="required" '; } $output = ' '; $output .= ''; $output .= ''; $output .= ''; if ( ! empty( $args['description'] ) ) { $output .= '' . esc_html( $args['description'] ) . ''; } $output .= ''; return $output; } /** * Date Picker * * Renders a date picker field. * * @param array $args Arguments for the date picker. * * @return string The date picker. * @since 1.5 * @access public * */ public function date_field( $args = [] ) { if ( empty( $args['class'] ) ) { $args['class'] = 'opalestate-datepicker form-control'; } elseif ( ! strpos( $args['class'], 'opalestate-datepicker' ) ) { $args['class'] .= ' opalestate-datepicker form-control'; } return $this->text_field( $args ); } /** * Textarea * * Renders an HTML textarea. * * @param array $args Arguments for the textarea. * * @return string The textarea. * @since 1.0 * @access public * */ public function textarea_field( $args = [] ) { $defaults = [ 'name' => '', 'value' => isset( $args['default'] ) ? $args['default'] : null, 'label' => null, 'description' => null, 'class' => 'large-text', 'disabled' => false, ]; $args = wp_parse_args( $args, $defaults ); $disabled = ''; if ( $args['disabled'] ) { $disabled = ' disabled="disabled"'; } $output = ''; $output .= ''; $data = ''; if ( $args['required'] ) { $data .= ' required="required" '; } $output .= ''; if ( ! empty( $args['description'] ) ) { $output .= '' . esc_html( $args['description'] ) . ''; } $output .= ''; return $output; } /** * Dropdown * * Renders an HTML Dropdown. * * @param array $args Arguments for the dropdown. * * @return string The dropdown. * @since 1.0 * @access public * */ public function select_field( $field_args = [] ) { $defaults = [ 'options' => [], 'name' => null, 'class' => 'form-control', 'id' => '', 'autocomplete' => 'off', 'selected' => 0, 'chosen' => false, 'placeholder' => null, 'multiple' => false, 'select_atts' => false, 'show_option_all' => esc_html__( 'All', 'opalestate-pro' ), 'show_option_none' => esc_html__( 'None', 'opalestate-pro' ), 'data' => [], 'readonly' => false, 'disabled' => false, 'required' => '', ]; $args = wp_parse_args( $field_args, $defaults ); $data_elements = ''; foreach ( $args['data'] as $key => $value ) { $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; } $multiple = ''; if ( $args['multiple'] ) { $multiple = 'MULTIPLE'; } if ( $args['chosen'] ) { $args['class'] .= ' opalestate-select-chosen'; } $placeholder = ''; if ( $args['placeholder'] ) { $placeholder = $args['placeholder']; } $output = ''; $data = ''; if ( $args['required'] ) { $data .= ' required="required" '; } $output .= sprintf( ''; return $output; } public function hidden_field( $args ) { $defaults = [ 'id' => '', 'value' => isset( $args['default'] ) ? $args['default'] : null, 'name' => '', 'description' => null, 'placeholder' => '', 'class' => 'regular-text form-control', 'disabled' => false, 'autocomplete' => 'off', 'data' => false, 'default' => '', 'required' => false, ]; $args = wp_parse_args( $args, $defaults ); $output = ''; return $output; } public function render_field( $field ) { switch ( $field['type'] ) { case 'date': return $this->date_field( $field ); break; case 'text': return $this->text_field( $field ); break; case 'hidden': return $this->hidden_field( $field ); break; case 'textarea': return $this->textarea_field( $field ); break; case 'user': return $this->ajax_user_search( $field ); break; case 'select': return $this->select_field( $field ); break; default: # code... break; } } public function render_form( $fields ) { $form_id = opalestate_unique_id( 'opalestate-form-' ); $output = ''; $this->form_id = $form_id; foreach ( $fields as $field ) { $wrap = ''; if ( isset( $field['before_row'] ) ) { $wrap .= $field['before_row']; } $wrap .= '