function render_field($field) { // vars $atts = array(); $o = array('id', 'class', 'name', 'placeholder', 'rows'); $s = array('readonly', 'disabled'); $e = ''; // maxlength if ($field['maxlength']) { $o[] = 'maxlength'; } // rows if (empty($field['rows'])) { $field['rows'] = 8; } // append atts foreach ($o as $k) { $atts[$k] = $field[$k]; } // append special atts foreach ($s as $k) { if (!empty($field[$k])) { $atts[$k] = $k; } } $e .= '<textarea ' . acf_esc_attr($atts) . ' >'; $e .= esc_textarea($field['value']); $e .= '</textarea>'; // return echo $e; }
function render_field($field) { // vars $o = array('type', 'id', 'class', 'name', 'value', 'placeholder'); $e = ''; // prepend if ($field['prepend'] !== "") { $field['class'] .= ' acf-is-prepended'; $e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; } // append if ($field['append'] !== "") { $field['class'] .= ' acf-is-appended'; $e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; } // populate atts $atts = array(); foreach ($o as $k) { $atts[$k] = $field[$k]; } // special atts foreach (array('readonly', 'disabled') as $k) { if ($field[$k]) { $atts[$k] = $k; } } // render $e .= '<div class="acf-input-wrap">'; $e .= '<input ' . acf_esc_attr($atts) . ' />'; $e .= '</div>'; // return echo $e; }
function render_field($field) { // vars $input = array('type' => 'checkbox', 'id' => $field['id'], 'name' => $field['name'], 'value' => '1', 'class' => $field['class'], 'autocomplete' => 'off'); $hidden = array('name' => $field['name'], 'value' => 0); $active = $field['value'] ? true : false; $switch = ''; // checked if ($active) { $input['checked'] = 'checked'; } // ui if ($field['ui']) { // vars if ($field['ui_on_text'] === '') { $field['ui_on_text'] = __('Yes', 'acf'); } if ($field['ui_off_text'] === '') { $field['ui_off_text'] = __('No', 'acf'); } // update input $input['class'] .= ' acf-switch-input'; $input['style'] = 'display:none;'; $switch .= '<div class="acf-switch' . ($active ? ' -on' : '') . '">'; $switch .= '<span class="acf-switch-on">' . $field['ui_on_text'] . '</span>'; $switch .= '<span class="acf-switch-off">' . $field['ui_off_text'] . '</span>'; $switch .= '<div class="acf-switch-slider"></div>'; $switch .= '</div>'; } ?> <div class="acf-true-false"> <?php acf_hidden_input($hidden); ?> <label> <input <?php echo acf_esc_attr($input); ?> /> <?php if ($switch) { echo $switch; } ?> <?php if ($field['message']) { ?> <span><?php echo $field['message']; ?> </span><?php } ?> </label> </div> <?php }
function render_field($field) { // vars $e = ''; $div = array('class' => 'acf-date_picker', 'data-display_format' => acf_convert_date_to_js($field['display_format']), 'data-first_day' => $field['first_day']); $input = array('id' => $field['id'], 'class' => 'input-alt', 'type' => 'hidden', 'name' => $field['name'], 'value' => $field['value']); // html $e .= '<div ' . acf_esc_attr($div) . '>'; $e .= '<input ' . acf_esc_attr($input) . '/>'; $e .= '<input type="text" value="" class="input" />'; $e .= '</div>'; // return echo $e; }
function render_field($field) { global $q_config; $languages = qtrans_getSortedLanguages(true); $values = qtrans_split($field['value'], $quicktags = true); $currentLanguage = $this->plugin->get_active_language(); // vars $o = array('id', 'class', 'name', 'placeholder', 'rows'); $s = array('readonly', 'disabled'); $e = ''; // maxlength if ($field['maxlength'] !== '') { $o[] = 'maxlength'; } // rows if (empty($field['rows'])) { $field['rows'] = 8; } // populate atts $atts = array(); foreach ($o as $k) { $atts[$k] = $field[$k]; } // special atts foreach ($s as $k) { if ($field[$k]) { $atts[$k] = $k; } } // render $e .= '<div class="acf-input-wrap multi-language-field">'; foreach ($languages as $language) { $class = $language === $currentLanguage ? 'wp-switch-editor current-language' : 'wp-switch-editor'; $e .= '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; } foreach ($languages as $language) { $atts['class'] = $field['class']; if ($language === $currentLanguage) { $atts['class'] .= ' current-language'; } $atts['name'] = $field['name'] . "[{$language}]"; $atts['data-language'] = $language; $e .= '<textarea ' . acf_esc_attr($atts) . ' >'; $e .= esc_textarea($values[$language]); $e .= '</textarea>'; } $e .= '</div>'; // return echo $e; }
function render_field($field) { // vars $atts = array('type' => 'checkbox', 'id' => "{$field['id']}-1", 'name' => $field['name'], 'value' => '1'); // checked if (!empty($field['value'])) { $atts['checked'] = 'checked'; } // html echo '<ul class="acf-checkbox-list acf-bl ' . acf_esc_attr($field['class']) . '">'; echo '<input type="hidden" name="' . acf_esc_attr($field['name']) . '" value="0" />'; echo '<li><label><input ' . acf_esc_attr($atts) . '/>' . $field['message'] . '</label></li>'; echo '</ul>'; }
function render_field($field) { // vars $o = array('type', 'id', 'class', 'name', 'value', 'placeholder', 'icon_set'); $s = array('readonly', 'disabled'); $e = ''; // maxlength if ($field['maxlength'] !== "") { $o[] = 'maxlength'; } // prepend if ($field['prepend'] !== "") { $field['class'] .= ' acf-is-prepended'; $e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; } // append if ($field['append'] !== "") { $field['class'] .= ' acf-is-appended'; $e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; } $field['class'] .= ' ocp-icon-set'; // populate atts $atts = array(); foreach ($o as $k) { $atts[$k] = $field[$k]; } // special atts foreach ($s as $k) { if ($field[$k]) { $atts[$k] = $k; } } $atts['type'] = 'hidden'; // render $e .= '<div class="acf-input-wrap">'; $e .= '<i class="fa fa-fw ' . $atts['value'] . '"></i>'; $e .= '<a href="#TB_inline?height=550&inlineId=icon-select" class="thickbox button button-small choose-icon" onclick="jQuery(this).addClass(\'insert-icon\');getIconSet(jQuery(this));" data-set="' . $atts['icon_set'] . '">Choose Icon</a>'; $e .= '<input ' . acf_esc_attr($atts) . ' />'; $e .= '</div>'; // return echo $e; }
function render_field($field) { // format value $display_value = ''; if ($field['value']) { $display_value = acf_format_date($field['value'], $field['display_format']); } // vars $e = ''; $div = array('class' => 'acf-time-picker acf-input-wrap', 'data-time_format' => acf_convert_time_to_js($field['display_format'])); $hidden = array('id' => $field['id'], 'class' => 'input-alt', 'type' => 'hidden', 'name' => $field['name'], 'value' => $field['value']); $input = array('class' => 'input', 'type' => 'text', 'value' => $display_value); // html $e .= '<div ' . acf_esc_attr($div) . '>'; $e .= '<input ' . acf_esc_attr($hidden) . '/>'; $e .= '<input ' . acf_esc_attr($input) . '/>'; $e .= '</div>'; // return echo $e; }
public function render_field($field) { $attributes = array('id', 'class', 'name'); // populate atts $rendered_attributes = array(); foreach ($attributes as $attribute) { $rendered_attributes[$attribute] = $field[$attribute]; } $value = esc_textarea($field['value']); ?> <div class='codemirror-wrapper'> <textarea <?php echo acf_esc_attr($rendered_attributes); ?> ><?php echo $value; ?> </textarea> </div> <?php }
function render_field($field) { // decode value (convert to array) $field['value'] = acf_force_type_array($field['value']); // hiden input acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); // vars $i = 0; // class $field['class'] .= ' acf-checkbox-list'; $field['class'] .= $field['layout'] == 'horizontal' ? ' acf-hl' : ' acf-bl'; // e $e = '<ul ' . acf_esc_attr(array('class' => $field['class'])) . '>'; // checkbox saves an array $field['name'] .= '[]'; // foreach choices if (!empty($field['choices'])) { foreach ($field['choices'] as $value => $label) { // increase counter $i++; // vars $atts = array('type' => 'checkbox', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value); if (in_array($value, $field['value'])) { $atts['checked'] = 'checked'; } if (isset($field['disabled']) && in_array($value, $field['disabled'])) { $atts['disabled'] = 'true'; } // each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute if ($i > 1) { $atts['id'] .= '-' . $value; } $e .= '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>'; } } $e .= '</ul>'; // return echo $e; }
function render_field($field) { // vars $atts = array(); $o = array('type', 'id', 'class', 'min', 'max', 'step', 'name', 'value', 'placeholder'); $s = array('readonly', 'disabled'); $e = ''; // step if (!$field['step']) { $field['step'] = 'any'; } // prepend if ($field['prepend'] !== '') { $field['class'] .= ' acf-is-prepended'; $e .= '<div class="acf-input-prepend">' . $field['prepend'] . '</div>'; } // append if ($field['append'] !== '') { $field['class'] .= ' acf-is-appended'; $e .= '<div class="acf-input-append">' . $field['append'] . '</div>'; } // append atts foreach ($o as $k) { $atts[$k] = $field[$k]; } // append special atts foreach ($s as $k) { if (!empty($field[$k])) { $atts[$k] = $k; } } // render $e .= '<div class="acf-input-wrap">'; $e .= '<input ' . acf_esc_attr($atts) . ' />'; $e .= '</div>'; // return echo $e; }
function render_field($field) { // vars $o = array('type', 'id', 'class', 'name', 'value', 'placeholder'); $e = ''; // populate atts $atts = array(); foreach ($o as $k) { $atts[$k] = $field[$k]; } // special atts foreach (array('readonly', 'disabled') as $k) { if (!empty($field[$k])) { $atts[$k] = $k; } } // render $e .= '<div class="acf-input-wrap acf-url">'; $e .= '<i class="acf-icon acf-icon-globe small"></i><input ' . acf_esc_attr($atts) . ' />'; $e .= '</div>'; // return echo $e; }
function render_field($field) { // convert value to array $field['value'] = acf_force_type_array($field['value']); // add empty value (allows '' to be selected) if (empty($field['value'])) { $field['value'][''] = ''; } // placeholder if (empty($field['placeholder'])) { $field['placeholder'] = __("Select", 'acf'); } // vars $atts = array('id' => $field['id'], 'class' => $field['class'], 'name' => $field['name'], 'data-ui' => $field['ui'], 'data-ajax' => $field['ajax'], 'data-multiple' => $field['multiple'], 'data-placeholder' => $field['placeholder'], 'data-allow_null' => $field['allow_null']); // hidden input if ($field['ui']) { acf_hidden_input(array('type' => 'hidden', 'id' => $field['id'], 'name' => $field['name'], 'value' => implode(',', $field['value']))); } elseif ($field['multiple']) { acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); } // ui if ($field['ui']) { $atts['disabled'] = 'disabled'; $atts['class'] .= ' acf-hidden'; } // multiple if ($field['multiple']) { $atts['multiple'] = 'multiple'; $atts['size'] = 5; $atts['name'] .= '[]'; } // special atts foreach (array('readonly', 'disabled') as $k) { if (!empty($field[$k])) { $atts[$k] = $k; } } // vars $els = array(); $choices = array(); // loop through values and add them as options if (!empty($field['choices'])) { foreach ($field['choices'] as $k => $v) { if (is_array($v)) { // optgroup $els[] = array('type' => 'optgroup', 'label' => $k); if (!empty($v)) { foreach ($v as $k2 => $v2) { $els[] = array('type' => 'option', 'value' => $k2, 'label' => $v2, 'selected' => in_array($k2, $field['value'])); $choices[] = $k2; } } $els[] = array('type' => '/optgroup'); } else { $els[] = array('type' => 'option', 'value' => $k, 'label' => $v, 'selected' => in_array($k, $field['value'])); $choices[] = $k; } } } // prepende orphans /* if( !empty($field['value']) ) { foreach( $field['value'] as $v ) { if( empty($v) ) { continue; } if( !in_array($v, $choices) ) { array_unshift( $els, array( 'type' => 'option', 'value' => $v, 'label' => $v, 'selected' => true ) ); } } } */ // null if ($field['allow_null']) { array_unshift($els, array('type' => 'option', 'value' => '', 'label' => '- ' . $field['placeholder'] . ' -')); } // html echo '<select ' . acf_esc_attr($atts) . '>'; // construct html if (!empty($els)) { foreach ($els as $el) { // extract type $type = acf_extract_var($el, 'type'); if ($type == 'option') { // get label $label = acf_extract_var($el, 'label'); // validate selected if (acf_extract_var($el, 'selected')) { $el['selected'] = 'selected'; } // echo echo '<option ' . acf_esc_attr($el) . '>' . $label . '</option>'; } else { // echo echo '<' . $type . ' ' . acf_esc_attr($el) . '>'; } } } echo '</select>'; }
function acf_get_hidden_input($atts) { $atts['type'] = 'hidden'; return '<input ' . acf_esc_attr($atts) . ' />'; }
public function render_field($field) { // convert value to array $field['value'] = acf_get_array($field['value'], false); // add empty value (allows '' to be selected) if (empty($field['value'])) { $field['value'][''] = ''; } // placeholder if (empty($field['placeholder'])) { $field['placeholder'] = __("Select", 'acf'); } // vars $atts = array('id' => $field['id'], 'class' => $field['class'], 'name' => $field['name'], 'data-multiple' => $field['multiple'], 'data-placeholder' => $field['placeholder'], 'data-allow_null' => $field['allow_null']); // multiple if ($field['multiple']) { $atts['multiple'] = 'multiple'; $atts['size'] = 5; $atts['name'] .= '[]'; } // special atts foreach (array('readonly', 'disabled') as $k) { if (!empty($field[$k])) { $atts[$k] = $k; } } // vars $els = array(); // $choices = array(); $posttypes = $this->post_type_options(); foreach ($posttypes as $pt) { $els[] = array('type' => 'option', 'value' => $pt['value'], 'label' => $pt['label'], 'selected' => in_array($pt['value'], $field['value'])); } // null if ($field['allow_null']) { array_unshift($els, array('type' => 'option', 'value' => '', 'label' => '- ' . $field['placeholder'] . ' -')); } // html echo '<select ' . acf_esc_attr($atts) . '>'; // construct html if (!empty($els)) { foreach ($els as $el) { // extract type $type = acf_extract_var($el, 'type'); if ($type == 'option') { // get label $label = acf_extract_var($el, 'label'); // validate selected if (acf_extract_var($el, 'selected')) { $el['selected'] = 'selected'; } // echo echo '<option ' . acf_esc_attr($el) . '>' . $label . '</option>'; } else { // echo echo '<' . $type . ' ' . acf_esc_attr($el) . '>'; } } } echo '</select>'; }
function walk($choices, $values) { // bail ealry if no choices if (empty($choices)) { return; } // loop foreach ($choices as $k => $v) { // optgroup if (is_array($v)) { // optgroup echo '<optgroup label="' . esc_attr($k) . '">'; // walk $this->walk($v, $values); // close optgroup echo '</optgroup>'; // break continue; } // vars $search = html_entity_decode($k); $pos = array_search($search, $values); $atts = array('value' => $k); // validate selected if ($pos !== false) { $atts['selected'] = 'selected'; $atts['data-i'] = $pos; } // option echo '<option ' . acf_esc_attr($atts) . '>' . $v . '</option>'; } }
function render_field($field) { // format value $display_value = ''; if ($field['value']) { // get time $unixtimestamp = strtotime($field['value']); // translate $display_value = date_i18n($field['display_format'], $unixtimestamp); } // convert display_format to date and time // the letter 'm' is used for date and minute in JS, so this must be done here in PHP $formats = $this->_split_date_time($field['display_format']); // vars $e = ''; $div = array('class' => 'acf-date-time-picker acf-input-wrap', 'data-date_format' => acf_convert_date_to_js($formats['date']), 'data-time_format' => acf_convert_date_to_js($formats['time']), 'data-first_day' => $field['first_day']); $hidden = array('id' => $field['id'], 'class' => 'input-alt', 'type' => 'hidden', 'name' => $field['name'], 'value' => $field['value']); $input = array('class' => 'input', 'type' => 'text', 'value' => $display_value); // html $e .= '<div ' . acf_esc_attr($div) . '>'; $e .= '<input ' . acf_esc_attr($hidden) . '/>'; $e .= '<input ' . acf_esc_attr($input) . '/>'; $e .= '</div>'; // return echo $e; }
function render_field($field) { // format value $display_value = ''; if ($field['value']) { // get time $unixtimestamp = strtotime($field['value']); $format = $field['display_format']; // translate $display_value = date_i18n($format, $unixtimestamp); } // vars $e = ''; $div = array('class' => 'acf-date-picker acf-input-wrap', 'data-date_format' => acf_convert_date_to_js($field['display_format']), 'data-first_day' => $field['first_day']); $hidden = array('id' => $field['id'], 'class' => 'input-alt', 'type' => 'hidden', 'name' => $field['name'], 'value' => $field['value']); $input = array('class' => 'input', 'type' => 'text', 'value' => $display_value); // html $e .= '<div ' . acf_esc_attr($div) . '>'; $e .= '<input ' . acf_esc_attr($hidden) . '/>'; $e .= '<input ' . acf_esc_attr($input) . '/>'; $e .= '</div>'; // return echo $e; }
function render_field($field) { // vars $text = acf_get_sub_array($field, array('id', 'class', 'name', 'value')); $hidden = acf_get_sub_array($field, array('name', 'value')); $e = ''; // render ?> <div class="acf-color_picker"> <?php acf_hidden_input($hidden); ?> <input type="text" <?php echo acf_esc_attr($text); ?> /> </div> <?php }
<?php // global global $post; // extract args extract($args); // add prefix $field['prefix'] = "acf_fields[{$field['ID']}]"; // vars $atts = array('class' => "acf-field-object acf-field-object-{$field['type']}", 'data-id' => $field['ID'], 'data-key' => $field['key'], 'data-type' => $field['type']); $meta = array('ID' => $field['ID'], 'key' => $field['key'], 'parent' => $field['parent'], 'menu_order' => $field['menu_order'], 'save' => ''); // replace $atts['class'] = str_replace('_', '-', $atts['class']); ?> <div <?php echo acf_esc_attr($atts); ?> > <div class="meta"> <?php foreach ($meta as $k => $v) { acf_hidden_input(array('class' => "input-{$k}", 'name' => "{$field['prefix']}[{$k}]", 'value' => $v)); } ?> </div> <div class="handle"> <ul class="acf-hl acf-tbody"> <li class="li-field-order"> <span class="acf-icon acf-icon-order"><?php
function render_field($field) { // format value $hidden_value = ''; $display_value = ''; if ($field['value']) { $hidden_value = acf_format_date($field['value'], 'Ymd'); $display_value = acf_format_date($field['value'], $field['display_format']); } // vars $e = ''; $div = array('class' => 'acf-date-picker acf-input-wrap', 'data-date_format' => acf_convert_date_to_js($field['display_format']), 'data-first_day' => $field['first_day']); $hidden = array('id' => $field['id'], 'class' => 'input-alt', 'type' => 'hidden', 'name' => $field['name'], 'value' => $hidden_value); $input = array('class' => 'input', 'type' => 'text', 'value' => $display_value); // save_format - compatibility with ACF < 5.0.0 if (!empty($field['save_format'])) { // add custom JS save format $div['data-save_format'] = $field['save_format']; // revert hidden input value to raw DB value $hidden['value'] = $field['value']; // remove formatted value (will do this via JS) $input['value'] = ''; } // html $e .= '<div ' . acf_esc_attr($div) . '>'; $e .= '<input ' . acf_esc_attr($hidden) . '/>'; $e .= '<input ' . acf_esc_attr($input) . '/>'; $e .= '</div>'; // return echo $e; }
function render_field($field) { // vars $atts = array(); $e = ''; // populate atts foreach (array('id', 'class', 'name', 'value') as $k) { $atts[$k] = $field[$k]; } // render $e .= '<div class="acf-color_picker">'; $e .= '<input type="text" ' . acf_esc_attr($atts) . ' />'; $e .= '</div>'; // return echo $e; }
function render_layout($field, $layout, $i, $value) { // vars $order = 0; $el = 'div'; $sub_fields = $layout['sub_fields']; $prefix = $field['name'] . '[' . $i . ']'; // div $div = array('class' => 'layout', 'data-id' => $i, 'data-layout' => $layout['name']); // collapsed class if (acf_is_row_collapsed($field['key'], $i)) { $div['class'] .= ' -collapsed'; } // clone if (is_numeric($i)) { $order = $i + 1; } else { $div['class'] .= ' acf-clone'; } // display if ($layout['display'] == 'table') { $el = 'td'; } // title $title = $this->get_layout_title($field, $layout, $i, $value); // remove row reset_rows(); ?> <div <?php echo acf_esc_attr($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $prefix . '[acf_fc_layout]', 'value' => $layout['name'])); ?> </div> <div class="acf-fc-layout-handle" title="<?php _e('Drag to reorder', 'acf'); ?> "><?php echo $title; ?> </div> <div class="acf-fc-layout-controlls"> <a class="acf-icon -plus small" href="#" data-event="add-layout" title="<?php _e('Add layout', 'acf'); ?> "></a> <a class="acf-icon -minus small" href="#" data-event="remove-layout" title="<?php _e('Remove layout', 'acf'); ?> "></a> <a class="acf-icon -collapse small" href="#" data-event="collapse-layout" title="<?php _e('Click to toggle', 'acf'); ?> "></a> </div> <?php if (!empty($sub_fields)) { ?> <?php if ($layout['display'] == 'table') { ?> <table class="acf-table"> <thead> <tr> <?php foreach ($sub_fields as $sub_field) { // prepare field (allow sub fields to be removed) $sub_field = acf_prepare_field($sub_field); // bail ealry if no field if (!$sub_field) { continue; } // vars $atts = array(); $atts['class'] = 'acf-th'; $atts['data-name'] = $sub_field['_name']; $atts['data-type'] = $sub_field['type']; $atts['data-key'] = $sub_field['key']; // Add custom width if ($sub_field['wrapper']['width']) { $atts['data-width'] = $sub_field['wrapper']['width']; $atts['style'] = 'width: ' . $sub_field['wrapper']['width'] . '%;'; } ?> <th <?php echo acf_esc_attr($atts); ?> > <?php echo acf_get_field_label($sub_field); ?> <?php if ($sub_field['instructions']) { ?> <p class="description"><?php echo $sub_field['instructions']; ?> </p> <?php } ?> </th> <?php } ?> </tr> </thead> <tbody> <?php } else { ?> <div class="acf-fields <?php if ($layout['display'] == 'row') { ?> -left<?php } ?> "> <?php } ?> <?php // loop though sub fields foreach ($sub_fields as $sub_field) { // prevent repeater field from creating multiple conditional logic items for each row if ($i !== 'acfcloneindex') { $sub_field['conditional_logic'] = 0; } // add value if (isset($value[$sub_field['key']])) { // this is a normal value $sub_field['value'] = $value[$sub_field['key']]; } elseif (isset($sub_field['default_value'])) { // no value, but this sub field has a default value $sub_field['value'] = $sub_field['default_value']; } // update prefix to allow for nested values $sub_field['prefix'] = $prefix; // render input acf_render_field_wrap($sub_field, $el); } ?> <?php if ($layout['display'] == 'table') { ?> </tbody> </table> <?php } else { ?> </div> <?php } ?> <?php } ?> </div> <?php }
function render_field($field) { $maxrows = null; $disablesort = null; $defaultheaders = null; // vars $o = array('id', 'name'); $s = array('readonly', 'disabled'); $e = ''; // maxlength if ($field['maxrows'] !== '') { $maxrows = 'data-maxrows="' . $field['maxrows'] . '"'; } // disable sort if (!empty($field['disable_sort'])) { $disablesort = ' data-disablesort="' . $field['disable_sort'] . '"'; } // rows if (!empty($field['fixed_columns'])) { $defaultheaders = preg_split('/\\r\\n|\\r|\\n/', $field['default_headers']); $defaultheaders = 'data-defaultheaders="' . implode(",", $defaultheaders) . '"'; if (empty($field['default_headers'])) { $defaultheaders = 'data-defaultheaders="No Default Headers Set"'; } } // populate atts $atts = array(); foreach ($o as $k) { $atts[$k] = $field[$k]; } // special atts foreach ($s as $k) { if ($field[$k]) { $atts[$k] = $k; } } $e .= '<textarea style="display:none" ' . $maxrows . ' ' . $disablesort . ' ' . $defaultheaders . ' data-key="' . $field['key'] . '" ' . acf_esc_attr($atts) . ' >'; $e .= esc_textarea($field['value']); $e .= '</textarea>'; // return echo $e; }
function render_field($field) { // vars $i = 0; $checked = false; // class $field['class'] .= ' acf-radio-list'; $field['class'] .= $field['layout'] == 'horizontal' ? ' acf-hl' : ' acf-bl'; // e $e = '<ul ' . acf_esc_attr(array('class' => $field['class'])) . '>'; // other choice if ($field['other_choice']) { // vars $input = array('type' => 'text', 'name' => $field['name'], 'value' => '', 'disabled' => 'disabled'); // select other choice if value is not a valid choice if (!isset($field['choices'][$field['value']])) { unset($input['disabled']); $input['value'] = $field['value']; $field['value'] = 'other'; } $field['choices']['other'] = '</label><input type="text" ' . acf_esc_attr($input) . ' /><label>'; } // require choices if (!empty($field['choices'])) { // select first choice if value is not a valid choice if (!isset($field['choices'][$field['value']])) { $field['value'] = key($field['choices']); } // foreach choices foreach ($field['choices'] as $value => $label) { // increase counter $i++; // vars $atts = array('type' => 'radio', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value); if (strval($value) === strval($field['value'])) { $atts['checked'] = 'checked'; $checked = true; } if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) { $atts['disabled'] = 'disabled'; } // each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute if ($i > 1) { $atts['id'] .= '-' . $value; } $e .= '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>'; } } $e .= '</ul>'; echo $e; }
function render_field($field) { $checked = false; $i = 0; $icons = FruitpackIconfieldUtils::get_icons(); ?> <?php if ($icons) { ?> <ul class="acf-radio-list acf-hl acf-icon-font-list"> <?php foreach ($icons as $iconName => $iconClass) { if ($iconName != '') { $i++; $atts = array('type' => 'radio', 'id' => $field['id'], 'name' => $field['name'], 'value' => $iconClass); if (strval($iconClass) === strval($field['value'])) { $atts['checked'] = 'checked'; $checked = true; } if ($i > 1) { $atts['id'] .= '-' . $iconClass; } echo '<li>'; echo '<label>'; echo '<input ' . acf_esc_attr($atts) . '>'; echo '<i class="ico ' . $iconClass . '"></i>'; echo $iconName; echo '</label>'; echo '</li>'; } } ?> </ul> <?php } else { ?> <p>Woops, looks like you don't have any icons to choose from.</p> <?php } ?> <?php }
function acf_render_field_wrap($field, $el = 'div', $instruction = 'label') { // get valid field $field = acf_get_valid_field($field); // prepare field for input $field = acf_prepare_field($field); // el $elements = apply_filters('acf/render_field_wrap/elements', array('div' => 'div', 'tr' => 'td', 'ul' => 'li', 'ol' => 'li', 'dl' => 'dt', 'td' => 'div')); // validate $el if (!array_key_exists($el, $elements)) { $el = 'div'; } // wrapper $wrapper = array('id' => '', 'class' => 'acf-field', 'width' => '', 'style' => '', 'data-name' => $field['name'], 'data-type' => $field['type'], 'data-key' => ''); // add required if ($field['required']) { $wrapper['data-required'] = 1; } // add type $wrapper['class'] .= " acf-field-{$field['type']}"; // add key if ($field['key']) { $wrapper['class'] .= " acf-field-{$field['key']}"; $wrapper['data-key'] = $field['key']; } // replace $wrapper['class'] = str_replace('_', '-', $wrapper['class']); $wrapper['class'] = str_replace('field-field-', 'field-', $wrapper['class']); // wrap classes have changed (5.2.7) if (acf_get_compatibility('field_wrapper_class')) { $wrapper['class'] .= " field_type-{$field['type']}"; if ($field['key']) { $wrapper['class'] .= " field_key-{$field['key']}"; } } // merge in atts $wrapper = acf_merge_atts($wrapper, $field['wrapper']); // add width $width = (int) acf_extract_var($wrapper, 'width'); if ($el == 'tr' || $el == 'td') { $width = 0; } elseif ($width > 0 && $width < 100) { $wrapper['data-width'] = $width; $wrapper['style'] .= " width:{$width}%;"; } // remove empty attributes foreach ($wrapper as $k => $v) { if ($v == '') { unset($wrapper[$k]); } } // vars $show_label = $el !== 'td' ? true : false; ?> <<?php echo $el; ?> <?php echo acf_esc_attr($wrapper); ?> > <?php if ($show_label) { ?> <<?php echo $elements[$el]; ?> class="acf-label"> <label for="<?php echo $field['id']; ?> "><?php echo acf_get_field_label($field); ?> </label> <?php if ($instruction == 'label' && $field['instructions']) { ?> <p class="description"><?php echo $field['instructions']; ?> </p> <?php } ?> </<?php echo $elements[$el]; ?> > <?php } ?> <<?php echo $elements[$el]; ?> class="acf-input"> <?php acf_render_field($field); if ($instruction == 'field' && $field['instructions']) { ?> <p class="description"><?php echo $field['instructions']; ?> </p> <?php } ?> </<?php echo $elements[$el]; ?> > <?php if (!empty($field['conditional_logic'])) { ?> <script type="text/javascript"> if(typeof acf !== 'undefined'){ acf.conditional_logic.add( '<?php echo $field['key']; ?> ', <?php echo json_encode($field['conditional_logic']); ?> ); } </script> <?php } ?> </<?php echo $el; ?> > <?php }
function render_field($field) { // vars $i = 0; $e = ''; $ul = array('class' => 'acf-radio-list', 'data-allow_null' => $field['allow_null'], 'data-other_choice' => $field['other_choice']); // append to class $ul['class'] .= ' ' . ($field['layout'] == 'horizontal' ? 'acf-hl' : 'acf-bl'); $ul['class'] .= ' ' . $field['class']; // select value $checked = ''; $value = strval($field['value']); // selected choice if (isset($field['choices'][$value])) { $checked = $value; // custom choice } elseif ($field['other_choice'] && $value !== '') { $checked = 'other'; // allow null } elseif ($field['allow_null']) { // do nothing // select first input by default } else { $checked = key($field['choices']); } // ensure $checked is a string (could be an int) $checked = strval($checked); // other choice if ($field['other_choice']) { // vars $input = array('type' => 'text', 'name' => $field['name'], 'value' => '', 'disabled' => 'disabled', 'class' => 'acf-disabled'); // select other choice if value is not a valid choice if ($checked === 'other') { unset($input['disabled']); $input['value'] = $field['value']; } // append other choice $field['choices']['other'] = '</label><input type="text" ' . acf_esc_attr($input) . ' /><label>'; } // bail early if no choices if (empty($field['choices'])) { return; } // hiden input $e .= acf_get_hidden_input(array('name' => $field['name'])); // open $e .= '<ul ' . acf_esc_attr($ul) . '>'; // foreach choices foreach ($field['choices'] as $value => $label) { // ensure value is a string $value = strval($value); $class = ''; // increase counter $i++; // vars $atts = array('type' => 'radio', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value); // checked if ($value === $checked) { $atts['checked'] = 'checked'; $class = ' class="selected"'; } // deisabled if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) { $atts['disabled'] = 'disabled'; } // id (use crounter for each input) if ($i > 1) { $atts['id'] .= '-' . $value; } // append $e .= '<li><label' . $class . '><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>'; } // close $e .= '</ul>'; // return echo $e; }
function render_field($field) { // ensure array $field['value'] = acf_get_array($field['value'], false); $field['choices'] = acf_get_array($field['choices']); // hiden input acf_hidden_input(array('name' => $field['name'])); // vars $i = 0; $li = ''; $all_checked = true; // checkbox saves an array $field['name'] .= '[]'; // foreach choices if (!empty($field['choices'])) { foreach ($field['choices'] as $value => $label) { // increase counter $i++; // vars $atts = array('type' => 'checkbox', 'id' => $field['id'], 'name' => $field['name'], 'value' => $value); // is choice selected? if (in_array($value, $field['value'])) { $atts['checked'] = 'checked'; } else { $all_checked = false; } if (isset($field['disabled']) && acf_in_array($value, $field['disabled'])) { $atts['disabled'] = 'disabled'; } // each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute if ($i > 1) { $atts['id'] .= '-' . $value; } // append HTML $li .= '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>'; } // toggle all if ($field['toggle']) { // vars $label = __("Toggle All", 'acf'); $atts = array('type' => 'checkbox', 'class' => 'acf-checkbox-toggle'); // custom label if (is_string($field['toggle'])) { $label = $field['toggle']; } // checked if ($all_checked) { $atts['checked'] = 'checked'; } // append HTML $li = '<li><label><input ' . acf_esc_attr($atts) . '/>' . $label . '</label></li>' . $li; } } // allow_custom if ($field['allow_custom']) { // loop foreach ($field['value'] as $value) { // ignore if already eixsts if (isset($field['choices'][$value])) { continue; } // vars $atts = array('type' => 'text', 'name' => $field['name'], 'value' => $value); // append $li .= '<li><input class="acf-checkbox-custom" type="checkbox" checked="checked" /><input ' . acf_esc_attr($atts) . '/></li>'; } // append button $li .= '<li><a href="#" class="button acf-add-checkbox">' . __('Add new choice', 'acf') . '</a></li>'; } // class $field['class'] .= ' acf-checkbox-list'; $field['class'] .= $field['layout'] == 'horizontal' ? ' acf-hl' : ' acf-bl'; // return echo '<ul ' . acf_esc_attr(array('class' => $field['class'])) . '>' . $li . '</ul>'; }
function render_field_settings($field) { //return; // defaults? $field = $this->setup_field($field); // key is needed in the field names to correctly save the data $key = $field['key']; $html_key = 'acf_fields-' . $field['ID']; $sub_field = $this->setup_sub_field($field); $sub_field['prefix'] = "{$field['prefix']}[sub_field]"; // remove types that don't jive well with this one $fields_names = apply_filters('acf/get_field_types', array()); unset($fields_names[__('Layout', 'acf')]); unset($fields_names[__('Basic', 'acf')]['validated_field']); $field_id = str_replace("-temp", "", $field['id']); $field_key = $field['key']; // layout acf_render_field_setting($field, array('label' => __('Read Only?', 'acf_vf'), 'instructions' => __('When a field is marked read only, it will be visible but uneditable. Read only fields are marked with ', 'acf_vf') . '<i class="fa fa-ban" style="color:red;" title="' . __('Read only', 'acf_vf') . '"></i>.', 'type' => 'radio', 'name' => 'read_only', 'layout' => 'horizontal', 'prefix' => $field['prefix'], 'choices' => array(false => __('No', 'acf_vf'), true => __('Yes', 'acf_vf')))); // Validate Drafts acf_render_field_setting($field, array('label' => __('Validate Drafts/Preview?', 'acf_vf'), 'instructions' => '', 'type' => 'radio', 'name' => 'drafts', 'prefix' => $field['prefix'], 'choices' => array(true => __('Yes', 'acf_vf'), false => __('No', 'acf_vf')), 'layout' => 'horizontal')); if (false && !$this->drafts) { echo '<em>'; _e('Warning', 'acf_vf'); echo ': <code>ACF_VF_DRAFTS</code> '; _e('has been set to <code>false</code> which overrides field level configurations', 'acf_vf'); echo '.</em>'; } ?> <tr class="acf-field acf-sub_field" data-setting="validated_field" data-name="sub_field"> <td class="acf-label"> <label><?php _e('Validated Field', 'acf_vf'); ?> </label> <p class="description"></p> </td> <td class="acf-input"> <?php $atts = array('id' => 'acfcloneindex', 'class' => "field field_type-{$sub_field['type']}", 'data-id' => $sub_field['id'], 'data-key' => $sub_field['key'], 'data-type' => $sub_field['type']); $metas = array('id' => $sub_field['id'], 'key' => $sub_field['key'], 'parent' => $sub_field['parent'], 'save' => ''); ?> <div <?php echo acf_esc_attr($atts); ?> > <div class="field-meta acf-hidden"> <?php // meta foreach ($metas as $k => $v) { acf_hidden_input(array('class' => "input-{$k}", 'name' => "{$sub_field['prefix']}[{$k}]", 'value' => $v)); } ?> </div> <div class="sub-field-settings"> <table class="acf-table"> <tbody> <?php if (!isset($sub_field['function']) || empty($sub_field['function'])) { $sub_field['function'] = 'none'; } // Validated Field Type acf_render_field_setting($sub_field, array('label' => __('Field Type', 'acf_vf'), 'instructions' => __('The underlying field type that you would like to validate.', 'acf_vf'), 'type' => 'select', 'name' => 'type', 'prefix' => $sub_field['prefix'], 'choices' => $fields_names, 'required' => true), 'tr'); // Render the Sub Field do_action("acf/render_field_settings/type={$sub_field['type']}", $sub_field); ?> <tr class="field_save acf-field" data-name="conditional_logic" style="display:none;"> <td class="acf-label"></td> <td class="acf-input"></td> </tr> </tbody> </table> </div> </div> </td> </tr> <?php if (!empty($field['mask']) && $sub_field['type'] == 'number') { } $mask_error = !empty($field['mask']) && $sub_field['type'] == 'number' ? 'color:red;' : ''; // Input Mask acf_render_field_setting($field, array('label' => __('Input mask', 'acf_vf'), 'instructions' => __('Use 'a' to match A-Za-z, '9' to match 0-9, and '*' to match any alphanumeric.', 'acf_vf') . ' <a href="http://digitalbush.com/projects/masked-input-plugin/" target="_new">' . __('More info', 'acf_vf') . '</a>.<br/><br/><strong style="' . $mask_error . '"><em>' . __('Input masking is not compatible with the "number" field type!', 'acf_vf') . '</em></strong>', 'type' => 'text', 'name' => 'mask', 'prefix' => $field['prefix'], 'value' => $field['mask'], 'layout' => 'horizontal', 'class' => 'input-mask')); // Input Mask acf_render_field_setting($field, array('label' => __('Input Mask: Autoclear', 'acf_vf'), 'instructions' => __('Clear values that do match the input mask, if provided.', 'acf_vf'), 'type' => 'radio', 'name' => 'mask_autoclear', 'prefix' => $field['prefix'], 'value' => $field['mask_autoclear'], 'layout' => 'horizontal', 'choices' => array(true => __('Yes', 'acf_vf'), false => __('No', 'acf_vf')), 'class' => 'mask-settings')); // Input Mask acf_render_field_setting($field, array('label' => __('Input Mask: Placeholder', 'acf_vf'), 'instructions' => __('Use this string or character as a placeholder for the input mask.', 'acf_vf'), 'type' => 'text', 'name' => 'mask_placeholder', 'prefix' => $field['prefix'], 'value' => $field['mask_placeholder'], 'class' => 'mask-settings')); // Validation Function acf_render_field_setting($field, array('label' => __('Validation: Function', 'acf_vf'), 'instructions' => __('How should the field be server side validated?', 'acf_vf'), 'type' => 'select', 'name' => 'function', 'prefix' => $field['prefix'], 'value' => $field['function'], 'choices' => array('none' => __('None', 'acf_vf'), 'regex' => __('Regular Expression', 'acf_vf'), 'php' => __('PHP Statement', 'acf_vf')), 'layout' => 'horizontal', 'optgroup' => true, 'multiple' => '0', 'class' => 'validated_select validation-function')); ?> <tr class="acf-field validation-settings" data-setting="validated_field" data-name="pattern" id="field_option_<?php echo $html_key; ?> _validation"> <td class="acf-label"> <label><?php _e('Validation: Pattern', 'acf_vf'); ?> </label> <p class="description"> <small> <div class="validation-info"> <div class='validation-type regex'> <?php _e('Pattern match the input using', 'acf_vf'); ?> <a href="http://php.net/manual/en/function.preg-match.php" target="_new">PHP preg_match()</a>. <br /> </div> <div class='validation-type php'> <ul> <li><?php _e('Use any PHP code and return true for success or false for failure. If nothing is returned it will evaluate to true.', 'acf_vf'); ?> </li> <li><?php _e('Available variables', 'acf_vf'); ?> : <ul> <li><code>$post_id = $post->ID</code></li> <li><code>$post_type = $post->post_type</code></li> <li><code>$name = meta_key</code></li> <li><code>$value = form value</code></li> <li><code>$prev_value = db value</code></li> <li><code>$inputs = array(<blockquote>'field'=>?,<br/>'value'=>?,<br/>'prev_value'=>?<br/></blockquote>)</code></li> <li><code>&$message = error message</code></li> </ul> </li> <li><?php _e('Example', 'acf_vf'); ?> : <small><code><pre>if ( $value == "123" ){ return '123 is not valid!'; }</pre></code></small></li> </ul> </div> <div class='validation-type sql'> <?php _e('SQL', 'acf_vf'); ?> . <br /> </div> </div> </small> </p> </td> <td class="acf-input"> <?php // Pattern acf_render_field(array('label' => __('Pattern', 'acf_vf'), 'instructions' => '', 'type' => 'textarea', 'name' => 'pattern', 'prefix' => $field['prefix'], 'value' => $field['pattern'], 'layout' => 'horizontal', 'class' => 'editor')); ?> <div id="<?php echo $field_id; ?> -editor" class='ace-editor' style="height:200px;"><?php echo $field['pattern']; ?> </div> </td> </tr> <?php // Error Message acf_render_field_setting($field, array('label' => __('Validation: Error Message', 'acf_vf'), 'instructions' => __('The default error message that is returned to the client.', 'acf_vf'), 'type' => 'text', 'name' => 'message', 'prefix' => $field['prefix'], 'value' => $field['message'], 'layout' => 'horizontal', 'class' => 'validation-settings')); // Validation Function acf_render_field_setting($field, array('label' => __('Unique Value?', 'acf_vf'), 'instructions' => __("Make sure this value is unique for...", 'acf_vf'), 'type' => 'select', 'name' => 'unique', 'prefix' => $field['prefix'], 'value' => $field['unique'], 'choices' => array('non-unique' => __('Non-Unique Value', 'acf_vf'), 'global' => __('Unique Globally', 'acf_vf'), 'post_type' => __('Unique For Post Type', 'acf_vf'), 'post_key' => __('Unique For Post Type', 'acf_vf') . ' + ' . __('Field/Meta Key', 'acf_vf'), 'this_post' => __('Unique For Post', 'acf_vf'), 'this_post_key' => __('Unique For Post', 'acf_vf') . ' + ' . __('Field/Meta Key', 'acf_vf')), 'layout' => 'horizontal', 'optgroup' => false, 'multiple' => '0', 'class' => 'validated_select validation-unique')); // Unique Status $statuses = $this->get_post_statuses(); $choices = array(); foreach ($statuses as $value => $status) { $choices[$value] = $status->label; } acf_render_field_setting($field, array('label' => __('Unique Value: Apply to...?', 'acf_vf'), 'instructions' => __("Make sure this value is unique for the checked post statuses.", 'acf_vf'), 'type' => 'checkbox', 'name' => 'unique_statuses', 'prefix' => $field['prefix'], 'value' => $field['unique_statuses'], 'choices' => $choices)); }