/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { // Parse the values to keep ordering $choices = (array) $this->get_option('choices'); $selected = array(); foreach ($value as $val) { if (array_key_exists($val, $choices)) { $selected[$val] = $choices[$val]; } } $unselected = array_diff($choices, $selected); $o = '<select id="' . $this->get_the_ID() . '" name="' . $this->get_the_name() . '[]"' . Youxi_Form::render_attr($attributes) . '>'; foreach ((array) $unselected as $key => $choice) { $o .= '<option value="' . esc_attr($key) . '">'; $o .= esc_html($choice); $o .= '</option>'; } foreach ((array) $selected as $key => $choice) { $o .= '<option value="' . esc_attr($key) . '" selected>'; $o .= esc_html($choice); $o .= '</option>'; } $o .= '</select>'; return $o; }
/** * Modify shortcode fieldsets */ public function shortcode_fieldsets($fieldsets) { if (!isset($fieldsets['auto']) && class_exists('Youxi_Form')) { $fieldsets['auto'] = Youxi_Form::auto_fieldset(); } $animation_fieldset = apply_filters('youxi_shortcode_animation_fieldset', 'animation'); if (!isset($fieldsets[$animation_fieldset])) { $fieldsets[$animation_fieldset] = apply_filters('youxi_shortcode_animation_fieldset', array('id' => 'animation', 'title' => __('Animation', 'youxi'))); } return $fieldsets; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $o = '<select id="' . $this->get_the_ID() . '" name="' . $this->get_the_name() . '"' . Youxi_Form::render_attr($attributes) . '>'; foreach ((array) $this->get_option('choices') as $key => $choice) { $o .= '<option value="' . esc_attr($key) . '" ' . selected($key, $value, false) . '>'; $o .= esc_html($choice); $o .= '</option>'; } $o .= '</select>'; return $o; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $o = '<ul id="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>'; $o .= '<li>'; $o .= '<label>'; $o .= '<input type="hidden" name="' . $this->get_the_name() . '" value="0">'; $o .= '<input type="checkbox" name="' . $this->get_the_name() . '" value="1" ' . checked($value, 1, false) . '>'; $o .= ' ' . esc_html($this->get_option('label')); $o .= '</label>'; $o .= '</li>'; $o .= '</ul>'; return $o; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $o = '<ul id="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>'; foreach ((array) $this->get_option('choices') as $val => $choice) { $o .= '<li>'; $o .= '<label>'; $o .= '<input type="radio" name="' . $this->get_the_name() . '" value="' . esc_attr($val) . '" ' . checked($val, $value, false) . '>'; $o .= ' ' . esc_html($choice); $o .= '</label>'; $o .= '</li>'; } $o .= '</ul>'; return $o; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $o = '<ul id="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>'; foreach ((array) $this->get_option('choices') as $key => $choice) { $o .= '<li>'; $o .= '<label>'; if ($this->get_option('uncheckable')) { $o .= '<input type="hidden" name="' . $this->get_the_name() . esc_attr("[{$key}]") . '" value="0">'; $o .= '<input type="checkbox" name="' . $this->get_the_name() . esc_attr("[{$key}]") . '" value="1"' . checked(isset($value[$key]) ? $value[$key] : false, true, false) . '>'; } else { $o .= '<input type="checkbox" name="' . $this->get_the_name() . '[]" value="' . esc_attr($key) . '"' . checked(in_array($key, $value), true, false) . '>'; } $o .= ' ' . esc_html($choice); $o .= '</label>'; $o .= '</li>'; } $o .= '</ul>'; return $o; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $o = '<div id="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>'; $o .= '<div class="youxi-gallery-previews">'; foreach ((array) $value as $val) { $url = wp_get_attachment_thumb_url($val); if (!isset($url) || empty($url)) { continue; } $o .= '<div class="youxi-gallery-preview-item">'; $o .= '<div class="youxi-gallery-preview-img-wrap">'; $o .= '<div class="youxi-gallery-preview-img-wrap-inner">'; $o .= '<img src="' . esc_url($url) . '" alt="">'; $o .= '</div>'; $o .= '</div>'; $o .= '<input type="hidden" name="' . $this->get_the_name() . '[]" class="youxi-gallery-value" value="' . esc_attr($val) . '">'; $o .= '</div>'; } $o .= '</div>'; $o .= '</div>'; return $o; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { return '<input id="' . $this->get_the_ID() . '" name="' . $this->get_the_name() . '" type="text" value="' . esc_attr($value) . '"' . Youxi_Form::render_attr($attributes) . '>'; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $has_items = false; $o = '<div id="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>'; $o .= '<div class="youxi-media-previews">'; foreach ((array) $value as $val) { switch ($this->get_option('return_type')) { case 'url': $url = $val; break; case 'id': $url = wp_get_attachment_thumb_url($val); break; } if (!isset($url) || empty($url)) { continue; } $has_items = true; $o .= '<div class="youxi-media-preview-item">'; $o .= '<div class="youxi-media-preview-img-wrap">'; $o .= '<div class="youxi-media-preview-img-wrap-inner">'; $o .= '<img src="' . esc_url($url) . '" alt="">'; $o .= '</div>'; $o .= '</div>'; $o .= '<input type="hidden" name="' . $this->get_the_name() . ($this->get_option('multiple') ? '[]' : '') . '" value="' . esc_attr($val) . '">'; $o .= '<button type="button" class="youxi-media-preview-remove">×</button>'; $o .= '</div>'; } $o .= '</div>'; $button_atts = array(); if (!$this->get_option('multiple') && !empty($value)) { $button_atts['style'] = 'display: none;'; } $o .= '<input type="hidden" class="youxi-media-no-item skip-criteria-check" name="' . $this->get_the_name() . '" value=""' . ($has_items ? ' disabled' : '') . '>'; $o .= '<button type="button" class="youxi-media-button"' . Youxi_Form::render_attr($button_atts) . '>+</button>'; $o .= '</div>'; return $o; }
/** * Get the HTML output for the shortcode popup content * * @return string The popup content HTML markup */ public function get_html() { $form = new Youxi_Form($this->fields, array('form_tag' => 'div', 'form_attr' => array('class' => 'youxi-form'), 'form_method' => '', 'group_attr' => array('class' => 'youxi-form-row'), 'control_attr' => array('class' => 'youxi-form-item'), 'label_attr' => array('class' => 'youxi-form-label'), 'field_attr' => array('class' => array('youxi-form-large' => array('type' => array('text', 'textarea', 'code', 'url', 'select', 'iconchooser')))), 'fieldsets' => $this->shortcode->fieldsets)); return $form->compile($this->form_data)->render(false); }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { /* Check if the value is an URL, otherwise check if it's an attachment */ if ('attachment' == get_post_type($value)) { $attachment_url = wp_get_attachment_url($value); if ($this->get_option('always_return_url')) { $value = $attachment_url; } } elseif (filter_var($value, FILTER_VALIDATE_URL)) { $attachment_url = $value; } else { $value = $this->get_option('std'); $attachment_url = $value; } $o = '<div id="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>'; $o .= '<input type="hidden" class="youxi-uploader-value" name="' . $this->get_the_name() . '" value="' . esc_attr($value) . '">'; $o .= '<input type="text" class="youxi-uploader-feedback" readonly size="32" value="' . esc_attr($attachment_url) . '"> '; $o .= '<button type="button" class="button button-primary youxi-uploader-button">' . esc_html($this->get_option('upload_btn_text')) . '</button> '; $o .= '<button type="button" class="button youxi-uploader-remove">' . esc_html($this->get_option('remove_btn_text')) . '</button>'; $o .= '</div>'; return $o; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $attributes['data-editor-mode'] = esc_attr($this->get_option('mode')); return '<textarea id="' . $this->get_the_ID() . '" name="' . $this->get_the_name() . '"' . Youxi_Form::render_attr($attributes) . '>' . esc_textarea($value) . '</textarea>'; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $choices = $this->get_option('choices'); $choices = (array) (is_callable($choices) ? call_user_func($choices) : $choices); $o = '<select id="' . $this->get_the_ID() . '" name="' . $this->get_the_name() . '"' . Youxi_Form::render_attr($attributes) . '>'; foreach ($choices as $key => $choice) { if (is_array($choice)) { if (isset($choice['icons'])) { $o .= '<optgroup label="' . (isset($choice['label']) ? $choice['label'] : $key) . '">'; foreach ($choice['icons'] as $icon_key => $icon) { $o .= $this->construct_option($icon_key, $icon, $value); } $o .= '</optgroup>'; } } else { $o .= $this->construct_option($key, $choice, $value); } } $o .= '</select>'; return $o; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $o = '<div' . Youxi_Form::render_attr($attributes) . '>'; $o .= '<input id="' . $this->get_the_ID() . '" name="' . $this->get_the_name() . '" type="text" class="youxi-slider-input" value="' . esc_attr($value) . '" readonly>'; $o .= '<div class="youxi-slider-widget-wrap">'; $o .= '<div class="youxi-slider-widget"' . $this->get_widget_options_html() . '></div>'; $o .= '</div>'; $o .= '</div>'; return $o; }
/** * Get the field's label * * @return string The label's HTML markup */ public function get_the_label($attributes = array()) { return '<label for="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>' . $this->get_option('label') . '</label>'; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $fieldsets = $this->get_option('fieldsets'); if (!is_array($fieldsets) || empty($fieldsets)) { return ''; } $t = '<div id="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>'; foreach ($fieldsets as $id => $fieldset) { $t .= '<div class="youxi-togglable-fieldset">'; $t .= '<div class="youxi-togglable-fieldset-header">'; $t .= '<label class="youxi-form-label">'; $t .= esc_html($fieldset['title']); $t .= '</label>'; $t .= '<div class="youxi-togglable-fieldset-toggle">'; $t .= '<input type="checkbox" ' . checked(isset($value[$id]), true, false) . '>'; $t .= '</div>'; $t .= '</div>'; $t .= $this->get_form($fieldset['fields'])->compile(isset($value[$id]) ? $value[$id] : array())->render(false); $t .= '</div>'; } $t .= '</div>'; return $t; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $columns = $this->get_option('columns'); $rows = $this->get_option('rows'); $value = wp_parse_args($value, array('headers' => array(), 'cells' => array())); extract($value); // Determine if the rows/columns is fixed $fixed_cols = is_array($columns) && !empty($columns); $fixed_rows = (bool) $rows; // Get the number of initial rows and columns $num_cols = $fixed_cols ? count($columns) : max(count((array) $headers), $this->get_option('min_columns')); $num_rows = $fixed_rows ? $rows : max(count((array) $cells), $this->get_option('min_rows')); // Define the data options $attributes = array_merge($attributes, array('data-fixed-rows' => esc_attr(json_encode($fixed_rows)), 'data-fixed-cols' => esc_attr(json_encode($fixed_cols)), 'data-field-name' => esc_attr($this->get_the_name()), 'data-textarea-rows' => esc_attr($this->get_option('textarea_rows')), 'data-input-mode' => esc_attr($this->get_option('mode')), 'data-min-columns' => esc_attr($this->get_option('min_columns')), 'data-max-columns' => esc_attr($this->get_option('max_columns')), 'data-min-rows' => esc_attr($this->get_option('min_rows')), 'data-max-rows' => esc_attr($this->get_option('max_rows')), 'data-confirm-del-row' => esc_attr__('Are you sure you want to delete this row?', 'youxi'), 'data-confirm-del-col' => esc_attr__('Are you sure you want to delete this column?', 'youxi'))); $output = '<div' . Youxi_Form::render_attr($attributes) . '>'; $output .= '<table>'; $output .= '<thead>'; $output .= '<tr>'; if (!$fixed_rows) { $output .= '<th' . ($fixed_cols ? '' : ' rowspan="2"') . '></th>'; } if ($fixed_cols) { // If fixed columns, render the labels directly and add a hidden input foreach ($columns as $column) { $output .= '<th class="youxi-tabular-header">' . $column . '<input name="' . $this->get_the_name() . '[headers][]" type="hidden" value="' . $column . '"></th>'; } } else { // Render the column toolbars for ($i = 0; $i < $num_cols; $i++) { $output .= '<th class="youxi-tabular-controls youxi-tabular-col-controls">'; $output .= '<button type="button" data-action="add-col-before"><i class="dashicons dashicons-arrow-left-alt2"></i></button>'; $output .= '<button type="button" data-action="delete-col"><i class="dashicons dashicons-trash"></i></button>'; $output .= '<button type="button" data-action="add-col-after"><i class="dashicons dashicons-arrow-right-alt2"></i></button>'; $output .= '</th>'; } $output .= '</tr><tr>'; // Render the column inputs for ($i = 0; $i < $num_cols; $i++) { $val = isset($headers[$i]) ? strval($headers[$i]) : ''; $output .= "<th class=\"youxi-tabular-header\"><input name=\"" . $this->get_the_name() . "[headers][]\" type=\"text\" value=\"{$val}\"></th>"; } } $output .= '</tr>'; $output .= '</thead>'; if ($num_rows) { $output .= '<tbody>'; for ($i = 0; $i < $num_rows; $i++) { $row_values = isset($cells[$i]) ? (array) $cells[$i] : array(); $output .= '<tr class="youxi-tabular-row">'; if (!$fixed_rows) { $output .= '<td class="youxi-tabular-controls youxi-tabular-row-controls">'; $output .= '<button type="button" data-action="add-row-before"><i class="dashicons dashicons-arrow-up-alt2"></i></button>'; $output .= '<button type="button" data-action="delete-row"><i class="dashicons dashicons-trash"></i></button>'; $output .= '<button type="button" data-action="add-row-after"><i class="dashicons dashicons-arrow-down-alt2"></i></button>'; $output .= '</td>'; } for ($j = 0; $j < $num_cols; $j++) { $col_value = isset($row_values[$j]) ? strval($row_values[$j]) : ''; $output .= '<td class="youxi-tabular-cell">'; switch ($this->get_option('mode')) { case 'textarea': $output .= '<textarea class="youxi-tabular-field" rows="' . $this->get_option('textarea_rows') . '" name="' . $this->get_the_name() . "[cells][{$i}][]\">" . esc_textarea($col_value) . '</textarea>'; break; case 'text': $output .= '<input class="youxi-tabular-field" type="text" name="' . $this->get_the_name() . "[cells][{$i}][]\" value=\"" . esc_attr($col_value) . "\">"; default: break; } $output .= '</td>'; } $output .= '</tr>'; } $output .= '</tbody>'; } return $output . '</table></div>'; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $o = '<input type="hidden" name="' . $this->get_the_name() . '" value="0">'; $o .= '<input id="' . $this->get_the_ID() . '" name="' . $this->get_the_name() . '" type="checkbox" value="1"' . Youxi_Form::render_attr($attributes) . checked($value, 1, false) . '>'; return $o; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { $fields = $this->get_option('fields'); if (!is_array($fields) || empty($fields)) { return ''; } $minimum_rows = $this->get_option('min'); $maximum_rows = $this->get_option('max'); $attributes = array_merge($attributes, array('class' => esc_attr('youxi-repeater'), 'data-max' => esc_attr($maximum_rows), 'data-min' => esc_attr($minimum_rows), 'data-depth' => esc_attr($this->get_option('depth')), 'data-template-id' => esc_attr($this->get_template_id()), 'data-confirm-remove' => esc_attr($this->get_option('confirm_delete')))); $t = '<div id="' . $this->get_the_ID() . '"' . Youxi_Form::render_attr($attributes) . '>'; if (!$this->get_option('depth')) { $t .= $this->get_templates(); } $t .= '<fieldset>'; $t .= '<div class="youxi-repeater-fields">'; for ($this->index = 0, $count = count($value); $this->index < $count; $this->index++) { $t .= $this->get_template($value[$this->index], false); } for (; $this->index < $minimum_rows; $this->index++) { $t .= $this->get_template(null, false); } $t .= '</div>'; $t .= '<div class="youxi-repeater-controls">'; $t .= '<button type="button" class="button button-large button-primary" data-action="add">'; $t .= esc_attr('+ ' . $this->get_option('add_text')); $t .= '</button>'; $t .= '</div>'; $t .= '</fieldset>'; $t .= '</div>'; $t .= '<div style="clear: both;"></div>'; return $t; }
/** * Get the field's HTML markup * * @param mixed The field's current value (if it exists) * @param array The HTML attributes to be added on the field * * @return string The field's HTML markup */ public function get_the_field($value, $attributes = array()) { return '<textarea id="' . $this->get_the_ID() . '" name="' . $this->get_the_name() . '"' . Youxi_Form::render_attr($attributes) . '>' . esc_textarea($value) . '</textarea>'; }