function render_field($field) { // decode value (convert to array) $field['value'] = acf_get_array($field['value'], false); // hiden input acf_hidden_input(array('type' => 'hidden', '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; } } // 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($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 }
/** * Create the HTML interface for Currency field. * * @since 1.1.3 * * @param array $field The $field being edited. */ function render_field($field) { if (!is_array($field['value'])) { if ($field['value'] && is_string($field['value'])) { $field['value'] = explode(',', $field['value']); } elseif (!empty($field['value'])) { $field['value'] = array($field['value']); } } if (empty($field['value'])) { // add empty value (allows '' to be selected) $field['value'][''] = ''; } // vars $atts = array('id' => $field['id'], 'class' => $field['class'], 'name' => $field['name'], 'data-multiple' => $field['multiple'], 'data-allow_null' => $field['allow_null']); // hidden input if ($field['multiple']) { acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); } // 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; } } // html echo '<select ' . acf_esc_attr($atts) . '>'; // null option if ($field['allow_null']) { echo '<option value="null">- ' . __("Select", 'acf') . ' -</option>'; } // get currencies via WP Currencies $currencies = get_currencies(); // print options foreach ($currencies as $currency => $data) { $data = (array) $data; $selected = in_array($currency, $field['value']) ? 'selected="selected"' : ''; echo '<option value="' . $currency . '" ' . $selected . '>' . $currency . ' ' . $data['name'] . '</option>' . "\n"; } echo '</select>'; }
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_checkbox($field) { // hidden input acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); // checkbox saves an array if ($field['field_type'] == 'checkbox') { $field['name'] .= '[]'; } // vars $args = array('taxonomy' => $field['taxonomy'], 'hide_empty' => false, 'style' => 'none', 'walker' => new acf_taxonomy_field_walker($field)); // Un buque que le meti para que me detectara los sidebar if ($field['taxonomy'] == 'sidebar') { ?> <?php /** * Ininio parte personalizada **/ $sidebars = get_option('sidebars_widgets'); $options_sidebar = ''; global $post_ID; $save_sidebar = get_post_meta($post_ID, $field['label'], true); foreach ($sidebars as $sidebar_id => $sidebar) { if ($sidebar_id != 'wp_inactive_widgets' and $sidebar_id != 'array_version') { if (!empty($save_sidebar)) { foreach ($save_sidebar as $save) { if ($save == $sidebar_id) { $options_sidebar .= '<li><label class="selectit"><input type="checkbox" name="' . $field['name'] . '" value="' . $sidebar_id . '" checked> ' . $sidebar_id . '</label></li>'; continue; } } } $options_sidebar .= '<li><label class="selectit"><input type="checkbox" name="' . $field['name'] . '" value="' . $sidebar_id . '"> ' . $sidebar_id . '</label></li>'; } } ?> <div class="acf-taxonomy-field" data-load_save="<?php echo $field['load_save_terms']; ?> "> <input type="hidden" name="<?php echo $single_name; ?> " value="" /> <?php if ($field['field_type'] == 'select') { ?> <select id="<?php echo $field['id']; ?> " name="<?php echo $field['name']; ?> " <?php if ($field['multiple']) { ?> multiple="multiple" size="5"<?php } ?> > <?php if ($field['allow_null']) { ?> <option value=""><?php _e("None", 'acf'); ?> </option> <?php } ?> <?php } else { ?> <div class="categorychecklist-holder"> <ul class="acf-checkbox-list"> <?php if ($field['allow_null']) { ?> <li> <label class="selectit"> <input type="<?php echo $field['field_type']; ?> " name="<?php echo $field['name']; ?> " value="" /> <?php _e("None", 'acf'); ?> </label> </li> <?php } ?> <?php } ?> <?php // Aca le meto la mano para que muestre los sidebar que quiero echo $options_sidebar; ?> <?php if ($field['field_type'] == 'select') { ?> </select> <?php } else { ?> </ul> </div> <?php } ?> <?php /** * fin parte personalizada **/ ?> </div> <?php } else { // filter for 3rd party customization $args = apply_filters('acf/fields/taxonomy/wp_list_categories', $args, $field); ?> <div class="categorychecklist-holder"> <ul class="acf-checkbox-list acf-bl"> <?php if ($field['field_type'] == 'radio' && $field['allow_null']) { ?> <li> <label class="selectit"> <input type="radio" name="<?php echo $field['name']; ?> " value="" /> <?php _e("None", 'acf'); ?> </label> </li> <?php } ?> <?php wp_list_categories($args); ?> </ul> </div><?php } }
function render_field($field) { // vars $sub_fields = $field['sub_fields']; $value = acf_get_array($field['value']); $show_order = true; $show_add = true; $show_remove = true; // bail early if no sub fields if (empty($sub_fields)) { return; } // div $div = array('class' => 'acf-repeater', 'data-min' => $field['min'], 'data-max' => $field['max']); // empty if (empty($value)) { $div['class'] .= ' -empty'; } // If there are less values than min, populate the extra values if ($field['min']) { $value = array_pad($value, $field['min'], array()); } // If there are more values than man, remove some values if ($field['max']) { $value = array_slice($value, 0, $field['max']); // if max 1 row, don't show order if ($field['max'] == 1) { $show_order = false; } // if max == min, don't show add or remove buttons if ($field['max'] <= $field['min']) { $show_remove = false; $show_add = false; } } // setup values for row clone $value['acfcloneindex'] = array(); // button label if ($field['button_label'] === '') { $field['button_label'] = __('Add Row', 'acf'); } // field wrap $el = 'td'; $before_fields = ''; $after_fields = ''; if ($field['layout'] == 'row') { $el = 'div'; $before_fields = '<td class="acf-fields -left">'; $after_fields = '</td>'; } elseif ($field['layout'] == 'block') { $el = 'div'; $before_fields = '<td class="acf-fields">'; $after_fields = '</td>'; } // layout $div['class'] .= ' -' . $field['layout']; // hidden input acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); // collapsed if ($field['collapsed']) { // add target class foreach ($sub_fields as $i => $sub_field) { // bail early if no match if ($sub_field['key'] !== $field['collapsed']) { continue; } // class $sub_field['wrapper']['class'] .= ' -collapsed-target'; // update $sub_fields[$i] = $sub_field; } } ?> <div <?php acf_esc_attr_e($div); ?> > <table class="acf-table"> <?php if ($field['layout'] == 'table') { ?> <thead> <tr> <?php if ($show_order) { ?> <th class="acf-row-handle"></th> <?php } ?> <?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 } ?> <?php if ($show_remove) { ?> <th class="acf-row-handle"></th> <?php } ?> </tr> </thead> <?php } ?> <tbody> <?php foreach ($value as $i => $row) { $row_class = 'acf-row'; if ($i === 'acfcloneindex') { $row_class .= ' acf-clone'; } elseif (acf_is_row_collapsed($field['key'], $i)) { $row_class .= ' -collapsed'; } ?> <tr class="<?php echo $row_class; ?> " data-id="<?php echo $i; ?> "> <?php if ($show_order) { ?> <td class="acf-row-handle order" title="<?php _e('Drag to reorder', 'acf'); ?> "> <?php if ($field['collapsed']) { ?> <a class="acf-icon -collapse small" href="#" data-event="collapse-row" title="<?php _e('Click to toggle', 'acf'); ?> "></a> <?php } ?> <span><?php echo intval($i) + 1; ?> </span> </td> <?php } ?> <?php echo $before_fields; ?> <?php 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($row[$sub_field['key']])) { // this is a normal value $sub_field['value'] = $row[$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'] = $field['name'] . '[' . $i . ']'; // render input acf_render_field_wrap($sub_field, $el); ?> <?php } ?> <?php echo $after_fields; ?> <?php if ($show_remove) { ?> <td class="acf-row-handle remove"> <a class="acf-icon -plus small" href="#" data-event="add-row" title="<?php _e('Add row', 'acf'); ?> "></a> <a class="acf-icon -minus small" href="#" data-event="remove-row" title="<?php _e('Remove row', 'acf'); ?> "></a> </td> <?php } ?> </tr> <?php } ?> </tbody> </table> <?php if ($show_add) { ?> <ul class="acf-actions acf-hl"> <li> <a class="acf-button button button-primary" data-event="add-row"><?php echo $field['button_label']; ?> </a> </li> </ul> <?php } ?> </div> <?php }
function render_field($field) { // vars $uploader = acf_get_setting('uploader'); // enqueue if ($uploader == 'wp') { acf_enqueue_uploader(); } // vars $o = array('icon' => '', 'title' => '', 'url' => '', 'filesize' => '', 'filename' => ''); $div = array('class' => 'acf-file-uploader acf-cf', 'data-library' => $field['library'], 'data-mime_types' => $field['mime_types'], 'data-uploader' => $uploader); // has value? if ($field['value']) { $file = get_post($field['value']); if ($file) { $o['icon'] = wp_mime_type_icon($file->ID); $o['title'] = $file->post_title; $o['filesize'] = @size_format(filesize(get_attached_file($file->ID))); $o['url'] = wp_get_attachment_url($file->ID); $explode = explode('/', $o['url']); $o['filename'] = end($explode); } // url exists if ($o['url']) { $div['class'] .= ' has-value'; } } ?> <div <?php acf_esc_attr_e($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id')); ?> </div> <div class="show-if-value file-wrap acf-soh"> <div class="file-icon"> <img data-name="icon" src="<?php echo $o['icon']; ?> " alt=""/> </div> <div class="file-info"> <p> <strong data-name="title"><?php echo $o['title']; ?> </strong> </p> <p> <strong><?php _e('File name', 'acf'); ?> :</strong> <a data-name="filename" href="<?php echo $o['url']; ?> " target="_blank"><?php echo $o['filename']; ?> </a> </p> <p> <strong><?php _e('File size', 'acf'); ?> :</strong> <span data-name="filesize"><?php echo $o['filesize']; ?> </span> </p> <ul class="acf-hl acf-soh-target"> <?php if ($uploader != 'basic') { ?> <li><a class="acf-icon -pencil dark" data-name="edit" href="#"></a></li> <?php } ?> <li><a class="acf-icon -cancel dark" data-name="remove" href="#"></a></li> </ul> </div> </div> <div class="hide-if-value"> <?php if ($uploader == 'basic') { ?> <?php if ($field['value'] && !is_numeric($field['value'])) { ?> <div class="acf-error-message"><p><?php echo $field['value']; ?> </p></div> <?php } ?> <input type="file" name="<?php echo $field['name']; ?> " id="<?php echo $field['id']; ?> " /> <?php } else { ?> <p style="margin:0;"><?php _e('No file selected', 'acf'); ?> <a data-name="add" class="acf-button button" href="#"><?php _e('Add File', 'acf'); ?> </a></p> <?php } ?> </div> </div> <?php }
$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 echo $i + 1; ?> </span> <pre class="pre-field-key"><?php echo $field['key']; ?> </pre>
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 render_field($field) { // ensure value is an array if (empty($field['value'])) { $field['value'] = array(); } // rows $field['min'] = empty($field['min']) ? 0 : $field['min']; $field['max'] = empty($field['max']) ? 0 : $field['max']; // populate the empty row data (used for acfcloneindex and min setting) $empty_row = array(); foreach ($field['sub_fields'] as $f) { $empty_row[$f['key']] = isset($f['default_value']) ? $f['default_value'] : false; } // If there are less values than min, populate the extra values if ($field['min']) { for ($i = 0; $i < $field['min']; $i++) { // continue if already have a value if (array_key_exists($i, $field['value'])) { continue; } // populate values $field['value'][$i] = $empty_row; } } // If there are more values than man, remove some values if ($field['max']) { for ($i = 0; $i < count($field['value']); $i++) { if ($i >= $field['max']) { unset($field['value'][$i]); } } } // setup values for row clone $field['value']['acfcloneindex'] = $empty_row; // show columns $show_order = true; $show_add = true; $show_remove = true; if ($field['max']) { if ($field['max'] == 1) { $show_order = false; } if ($field['max'] <= $field['min']) { $show_remove = false; $show_add = false; } } // field wrap $el = 'td'; $before_fields = ''; $after_fields = ''; if ($field['layout'] == 'row') { $el = 'tr'; $before_fields = '<td class="acf-table-wrap"><table class="acf-table">'; $after_fields = '</table></td>'; } elseif ($field['layout'] == 'block') { $el = 'div'; $before_fields = '<td class="acf-fields">'; $after_fields = '</td>'; } // hidden input acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); ?> <div <?php acf_esc_attr_e(array('class' => 'acf-repeater', 'data-min' => $field['min'], 'data-max' => $field['max'])); ?> > <table <?php acf_esc_attr_e(array('class' => "acf-table acf-input-table {$field['layout']}-layout")); ?> > <?php if ($field['layout'] == 'table') { ?> <thead> <tr> <?php if ($show_order) { ?> <th class="order"><span class="order-spacer"></span></th> <?php } ?> <?php foreach ($field['sub_fields'] as $sub_field) { $atts = array('class' => "acf-th acf-th-{$sub_field['name']}", 'data-key' => $sub_field['key']); // Add custom width if ($sub_field['wrapper']['width']) { $atts['data-width'] = $sub_field['wrapper']['width']; } ?> <th <?php acf_esc_attr_e($atts); ?> > <?php acf_the_field_label($sub_field); ?> <?php if ($sub_field['instructions']) { ?> <p class="description"><?php echo $sub_field['instructions']; ?> </p> <?php } ?> </th> <?php } ?> <?php if ($show_remove) { ?> <th class="remove"><span class="remove-spacer"></span></th> <?php } ?> </tr> </thead> <?php } ?> <tbody> <?php foreach ($field['value'] as $i => $row) { ?> <tr class="acf-row<?php echo $i === 'acfcloneindex' ? ' acf-clone' : ''; ?> "> <?php if ($show_order) { ?> <td class="order" title="<?php _e('Drag to reorder', 'acf'); ?> "><?php echo intval($i) + 1; ?> </td> <?php } ?> <?php echo $before_fields; ?> <?php foreach ($field['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($row[$sub_field['key']])) { // this is a normal value $sub_field['value'] = $row[$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'] = "{$field['name']}[{$i}]"; // render input acf_render_field_wrap($sub_field, $el); ?> <?php } ?> <?php echo $after_fields; ?> <?php if ($show_remove) { ?> <td class="remove"> <a class="acf-icon small acf-repeater-add-row" href="#" data-before="1" title="<?php _e('Add row', 'acf'); ?> "><i class="acf-sprite-add"></i></a> <a class="acf-icon small acf-repeater-remove-row" href="#" title="<?php _e('Remove row', 'acf'); ?> "><i class="acf-sprite-remove"></i></a> </td> <?php } ?> </tr> <?php } ?> </tbody> </table> <?php if ($show_add) { ?> <ul class="acf-hl acf-clearfix"> <li class="acf-fr"> <a href="#" class="acf-button blue acf-repeater-add-row"><?php echo $field['button_label']; ?> </a> </li> </ul> <?php } ?> </div> <?php }
function render_field($field) { // enqueue acf_enqueue_uploader(); // vars $atts = array('id' => $field['id'], 'class' => "acf-gallery {$field['class']}", 'data-library' => $field['library'], 'data-min' => $field['min'], 'data-max' => $field['max'], 'data-mime_types' => $field['mime_types'], 'data-insert' => $field['insert'], 'data-columns' => 4); // set gallery height $height = acf_get_user_setting('gallery_height', 400); $height = max($height, 200); // minimum height is 200 $atts['style'] = "height:{$height}px"; // get posts $value = $this->get_attachments($field['value']); ?> <div <?php acf_esc_attr_e($atts); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $field['name'], 'value' => '')); ?> </div> <div class="acf-gallery-main"> <div class="acf-gallery-attachments"> <?php if ($value) { ?> <?php foreach ($value as $i => $v) { // bail early if no value if (!$v) { continue; } // vars $a = array('ID' => $v->ID, 'title' => $v->post_title, 'filename' => wp_basename($v->guid), 'type' => acf_maybe_get(explode('/', $v->post_mime_type), 0), 'class' => 'acf-gallery-attachment acf-soh'); // thumbnail $thumbnail = acf_get_post_thumbnail($a['ID'], 'medium'); // remove filename if is image if ($a['type'] == 'image') { $a['filename'] = ''; } // class $a['class'] .= ' -' . $a['type']; if ($thumbnail['type'] == 'icon') { $a['class'] .= ' -icon'; } ?> <div class="<?php echo $a['class']; ?> " data-id="<?php echo $a['ID']; ?> "> <?php acf_hidden_input(array('name' => $field['name'] . '[]', 'value' => $a['ID'])); ?> <div class="margin"> <div class="thumbnail"> <img src="<?php echo $thumbnail['url']; ?> " alt="" title="<?php echo $a['title']; ?> "/> </div> <?php if ($a['filename']) { ?> <div class="filename"><?php echo acf_get_truncated($a['filename'], 30); ?> </div> <?php } ?> </div> <div class="actions acf-soh-target"> <a class="acf-icon -cancel dark acf-gallery-remove" href="#" data-id="<?php echo $a['ID']; ?> " title="<?php _e('Remove', 'acf'); ?> "></a> </div> </div> <?php } ?> <?php } ?> </div> <div class="acf-gallery-toolbar"> <ul class="acf-hl"> <li> <a href="#" class="acf-button button button-primary acf-gallery-add"><?php _e('Add to gallery', 'acf'); ?> </a> </li> <li class="acf-fr"> <select class="acf-gallery-sort"> <option value=""><?php _e('Bulk actions', 'acf'); ?> </option> <option value="date"><?php _e('Sort by date uploaded', 'acf'); ?> </option> <option value="modified"><?php _e('Sort by date modified', 'acf'); ?> </option> <option value="title"><?php _e('Sort by title', 'acf'); ?> </option> <option value="reverse"><?php _e('Reverse current order', 'acf'); ?> </option> </select> </li> </ul> </div> </div> <div class="acf-gallery-side"> <div class="acf-gallery-side-inner"> <div class="acf-gallery-side-data"></div> <div class="acf-gallery-toolbar"> <ul class="acf-hl"> <li> <a href="#" class="acf-button button acf-gallery-close"><?php _e('Close', 'acf'); ?> </a> </li> <li class="acf-fr"> <a class="acf-button button button-primary acf-gallery-update"><?php _e('Update', 'acf'); ?> </a> </li> </ul> </div> </div> </div> </div> <?php }
function render_field($field) { global $q_config; $languages = qtrans_getSortedLanguages(true); $values = qtrans_split($field['value'], $quicktags = true); $currentLanguage = $this->plugin->get_active_language(); // enqueue acf_enqueue_uploader(); // vars $o = array('icon' => '', 'title' => '', 'size' => '', 'url' => '', 'name' => ''); $div = array('class' => 'acf-file-uploader acf-cf', 'data-library' => $field['library'], 'data-mime_types' => $field['mime_types']); $input_atts = array('type' => 'hidden', 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'value-id'); $url = ''; echo '<div class="multi-language-field multi-language-field-image">'; foreach ($languages as $language) { $class = 'wp-switch-editor'; if ($language === $currentLanguage) { $class .= ' current-language'; } echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; } foreach ($languages as $language) { $input_atts['name'] = $field['name'] . '[' . $language . ']'; $field['value'] = $values[$language]; $div['data-language'] = $language; $div['class'] = 'acf-file-uploader acf-cf'; // has value? if ($field['value'] && is_numeric($field['value'])) { $file = get_post($field['value']); if ($file) { $div['class'] .= ' has-value'; $o['icon'] = wp_mime_type_icon($file->ID); $o['title'] = $file->post_title; $o['size'] = @size_format(filesize(get_attached_file($file->ID))); $o['url'] = wp_get_attachment_url($file->ID); $explode = explode('/', $o['url']); $o['name'] = end($explode); } } // basic? $basic = !current_user_can('upload_files'); if ($basic) { $div['class'] .= ' basic'; } if ($language === $currentLanguage) { $div['class'] .= ' current-language'; } ?> <div <?php acf_esc_attr_e($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $input_atts['name'], 'value' => $field['value'], 'data-name' => 'id')); ?> </div> <div class="show-if-value file-wrap acf-soh"> <div class="file-icon"> <img data-name="icon" src="<?php echo $o['icon']; ?> " alt=""/> </div> <div class="file-info"> <p> <strong data-name="title"><?php echo $o['title']; ?> </strong> </p> <p> <strong><?php _e('File Name', 'acf'); ?> :</strong> <a data-name="name" href="<?php echo $o['url']; ?> " target="_blank"><?php echo $o['name']; ?> </a> </p> <p> <strong><?php _e('File Size', 'acf'); ?> :</strong> <span data-name="size"><?php echo $o['size']; ?> </span> </p> <ul class="acf-hl acf-soh-target"> <?php if (!$basic) { ?> <li><a class="acf-icon dark" data-name="edit" href="#"><i class="acf-sprite-edit"></i></a></li> <?php } ?> <li><a class="acf-icon dark" data-name="remove" href="#"><i class="acf-sprite-delete"></i></a></li> </ul> </div> </div> <div class="hide-if-value"> <?php if ($basic) { ?> <?php if ($field['value'] && !is_numeric($field['value'])) { ?> <div class="acf-error-message"><p><?php echo $field['value']; ?> </p></div> <?php } ?> <input type="file" name="<?php echo $field['name']; ?> " id="<?php echo $field['id']; ?> " /> <?php } else { ?> <p style="margin:0;"><?php _e('No File selected', 'acf'); ?> <a data-name="add" class="acf-button" href="#"><?php _e('Add File', 'acf'); ?> </a></p> <?php } ?> </div> </div> <?php } echo '</div>'; }
function render_field($field) { // vars $div = array('class' => 'acf-image_area_selection-inner', 'data-image_field_class' => $field['image_field_class']); ?> <div <?php acf_esc_attr_e($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $field['name'] . '[width]', 'value' => $field['value']['width'], 'data-name' => 'width')); ?> <?php acf_hidden_input(array('name' => $field['name'] . '[height]', 'value' => $field['value']['height'], 'data-name' => 'height')); ?> <?php acf_hidden_input(array('name' => $field['name'] . '[left]', 'value' => $field['value']['left'], 'data-name' => 'left')); ?> <?php acf_hidden_input(array('name' => $field['name'] . '[top]', 'value' => $field['value']['top'], 'data-name' => 'top')); ?> <?php acf_hidden_input(array('name' => $field['name'] . '[image-width]', 'value' => $field['value']['image-width'], 'data-name' => 'image-width')); ?> <?php acf_hidden_input(array('name' => $field['name'] . '[image-height]', 'value' => $field['value']['image-height'], 'data-name' => 'image-height')); ?> </div> <div class="area-actions-wrapper"> <input type="button" class="edit acf-button" value="<?php echo $this->l10n['edit']; ?> " /> <input type="button" class="confirm acf-button button-primary" value="<?php echo $this->l10n['confirm']; ?> " /> <input type="button" class="cancel acf-button" value="<?php echo $this->l10n['cancel']; ?> " /> </div><!-- .area-actions-wrapper --> </div> <?php }
function render_field($field) { // ensure value is an array if (empty($field['value'])) { $field['value'] = array(); } // rows $field['min'] = empty($field['min']) ? 0 : $field['min']; $field['max'] = empty($field['max']) ? 0 : $field['max']; // populate the empty row data (used for acfcloneindex and min setting) $empty_row = array(); foreach ($field['sub_fields'] as $f) { $empty_row[$f['key']] = isset($f['default_value']) ? $f['default_value'] : false; } // If there are less values than min, populate the extra values if ($field['min']) { for ($i = 0; $i < $field['min']; $i++) { // continue if already have a value if (array_key_exists($i, $field['value'])) { continue; } // populate values $field['value'][$i] = $empty_row; } } // If there are more values than man, remove some values if ($field['max']) { for ($i = 0; $i < count($field['value']); $i++) { if ($i >= $field['max']) { unset($field['value'][$i]); } } } // setup values for row clone $field['value']['acfcloneindex'] = $empty_row; // show columns $show_order = true; $show_add = true; $show_remove = true; if ($field['max']) { if ($field['max'] == 1) { $show_order = false; } if ($field['max'] <= $field['min']) { $show_remove = false; $show_add = false; } } // field wrap $el = 'td'; $before_fields = ''; $after_fields = ''; if ($field['layout'] == 'row') { $el = 'tr'; $before_fields = '<td class="acf-table-wrap"><table class="acf-table">'; $after_fields = '</table></td>'; } elseif ($field['layout'] == 'block') { $el = 'div'; $before_fields = '<td class="acf-fields">'; $after_fields = '</td>'; } // hidden input acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); ?> <div <?php acf_esc_attr_e(array('class' => 'acf-repeater acf-fancyrepeater', 'data-min' => $field['min'], 'data-max' => $field['max'], 'data-titlefieldkey' => $this->get_title_field_key($field))); ?> > <div class="acf-fancyrepeater-list-wrap"> <ul class="acf-hl acf-thead"> <li class="li-fancyrepeater-order"><?php _e('Order', 'acf_child_post_field'); ?> </li> <li class="li-fancyrepeater-label"><?php _e('Item', 'acf_child_post_field'); ?> </li> <li class="li-fancyrepeater-name"></li> <li class="li-fancyrepeater-type"></li> </ul> <div class="acf-fancyrepeater-list"> <?php foreach ($field['value'] as $i => $row) { ?> <?php $clone_class = $i === 'acfcloneindex' ? ' acf-clone' : ''; ?> <div class="acf-fancyrepeater-object <?php echo $clone_class; ?> "> <?php $this->render_child_table($field, $row, $i, $before_fields, $after_fields, $show_order, $el); ?> </div> <?php } ?> </div> <ul class="acf-hl acf-tfoot"> <li class="comic-sans"><i class="acf-sprite-arrow"></i><?php _e('Drag and drop to reorder', 'acf'); ?> </li> <li class="acf-fr"> <a href="#" class="acf-button blue acf-fancyrepeater-add-row">+ <?php echo $field['button_label']; ?> </a> </li> </ul> </div> </div> <?php }
function render_field($field) { // echo "<pre>"; // print_r($field); // echo "</pre>"; $taxonomies = array(); $taxonomies = acf_get_array($taxonomies); $taxonomies = acf_get_pretty_taxonomies($taxonomies); $all_taxonomies = acf_get_taxonomy_terms(); $selected_taxonomies = array(); $terms = array(); $slug_name = !empty($field['choices']) ? $field['choices'] : array_keys(acf_get_pretty_taxonomies()); foreach ($slug_name as $k1 => $v1) { $terms = array_merge($terms, get_terms($v1, array('hide_empty' => false))); foreach ($taxonomies as $k2 => $v2) { if ($v1 == $k2) { $field['choices'][$k1] = $v2; } } } foreach ($field['choices'] as $k1 => $v1) { foreach ($all_taxonomies as $k2 => $v2) { if ($v1 == $k2) { $selected_taxonomies[$v1] = $all_taxonomies[$k2]; } } } $field['choices'] = $selected_taxonomies; // 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'][''] = ''; $field['value']['cat'] = ''; } // placeholder if (empty($field['placeholder'])) { $field['placeholder'] = __("Select", 'acf'); } // vars $atts = array('id' => $field['id'], 'class' => $field['class'] . ' js-multi-taxonomy-select2', '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(); if ($field['data_type']) { // 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) { if ($field['type_value']) { foreach ($terms as $key => $val) { if ($val->name == $v2) { $els[] = array('type' => 'option', 'value' => $val->term_id, 'label' => $v2, 'selected' => $slct = $val->term_id == $field['value'] ? "selected" : ""); } } } else { $els[] = array('type' => 'option', 'value' => $k2, 'label' => $v2, 'selected' => $slct = $k2 == $field['value'] ? "selected" : ""); } $choices[] = $k2; } } $els[] = array('type' => '/optgroup'); } else { $els[] = array('type' => 'option', 'value' => $k, 'label' => $v, 'selected' => $slct = $k == $field['value'] ? "selected" : ""); $choices[] = $k; } } } // 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 acf_esc_attr($el); echo '<option ' . acf_esc_attr($el) . '>' . $label . '</option>'; } else { echo '<' . $type . ' ' . acf_esc_attr($el) . '>'; } } } echo '</select>'; } else { $els = '['; $i = 0; foreach ($field['choices'] as $k => $v) { if (is_array($v)) { $els .= '['; foreach ($v as $k2 => $v2) { foreach ($terms as $key => $val) { if ($val->name == $v2) { $els .= '["' . $v2 . '","' . $val->term_id . '",' . '"' . $slug_name[$i] . '"],'; } } } $els .= '],'; } $i++; } $els .= ']'; echo '<div class="h">'; echo '<div class="Taxonomies">'; echo '<label class="" for="' . $field['key'] . '">Taxonomies</label> '; echo '<select class="js-multi-taxonomy-select2 taxonomiesF" name="' . $field['name'] . '" id="' . $field['key'] . '-taxonomies">'; $i = 0; foreach ($field['choices'] as $k => $v) { echo '<option value="' . $i++ . '">' . $k . '</option>'; } echo '</select>'; echo '</div>'; echo '<div class="Terms">'; echo '<label class="" >Terms</label> '; echo '<input name="' . $field['name'] . '[cat]" id="' . $field['key'] . '-terms" class="js-multi-taxonomy-select2 termsF" value="" />'; echo '</div>'; echo '</div>'; // } echo ' <script> (function($){ var arr = ' . $els . '; //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ $(".TaxonomiesF").each(function(){ $(this).ready(function(){ $(this).closest(":has(.h .Terms .termsF)").find(".termsF").attr("name","' . $field['name'] . '[" + arr[$(this).closest(":has(.h .Taxonomies .TaxonomiesF)").find(".TaxonomiesF").val()][0][2]+ "]") $(this).closest(":has(.h .Terms .termsF)").find(".termsF").select2({ multiple: true, query: function (query) { var data = {results: []}, i; for (i in arr[$(this).closest(":has(.h .Taxonomies .TaxonomiesF)").find(".TaxonomiesF").val()] ) { data.results.push({id: arr[$(this).closest(":has(.h .Taxonomies .TaxonomiesF)").find(".TaxonomiesF").val()][i][1] , text: arr[$(this).closest(":has(.h .Taxonomies .TaxonomiesF)").find(".TaxonomiesF").val()][i][0]}); } query.callback(data); }, initSelection : function (element, callback) { var elementText = $(element).val(); var data = {id: elementText, text: elementText}; callback(data); } }); }); }); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++ })(jQuery); </script> '; } }
function acf_form($args = array()) { // vars $url = home_url($_SERVER['REQUEST_URI']); // defaults $args = wp_parse_args($args, array('id' => 'acf-form', 'post_id' => false, 'new_post' => false, 'field_groups' => false, 'fields' => false, 'post_title' => false, 'post_content' => false, 'form' => true, 'form_attributes' => array(), 'return' => add_query_arg('updated', 'true', $url), 'html_before_fields' => '', 'html_after_fields' => '', 'submit_value' => __("Update", 'acf'), 'updated_message' => __("Post updated", 'acf'), 'label_placement' => 'top', 'instruction_placement' => 'label', 'field_el' => 'div')); $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', 'action' => '', 'method' => 'post')); // filter post_id $args['post_id'] = acf_get_valid_post_id($args['post_id']); // load values from this post $post_id = $args['post_id']; // new post? if ($post_id == 'new_post') { // dont load values $post_id = false; // new post defaults $args['new_post'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft')); } // attributes $args['form_attributes']['class'] .= ' acf-form'; // vars $field_groups = array(); $fields = array(); // post_title if ($args['post_title']) { $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true)); } // post_content if ($args['post_content']) { $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : '')); } // specific fields if (!empty($args['fields'])) { foreach ($args['fields'] as $selector) { $fields[] = acf_get_field($selector); } } elseif (!empty($args['field_groups'])) { foreach ($args['field_groups'] as $selector) { $field_groups[] = acf_get_field_group($selector); } } elseif ($args['post_id'] == 'new_post') { $field_groups = acf_get_field_groups(array('post_type' => $args['new_post']['post_type'])); } else { $field_groups = acf_get_field_groups(array('post_id' => $args['post_id'])); } //load fields based on field groups if (!empty($field_groups)) { foreach ($field_groups as $field_group) { $fields = array_merge($fields, acf_get_fields($field_group)); } } // updated message if (!empty($_GET['updated']) && $args['updated_message']) { echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>'; } // display form if ($args['form']) { ?> <form <?php acf_esc_attr_e($args['form_attributes']); ?> > <?php } // render post data acf_form_data(array('post_id' => $args['post_id'], 'nonce' => 'acf_form')); ?> <div class="acf-hidden"> <?php acf_hidden_input(array('name' => '_acf_form', 'value' => base64_encode(json_encode($args)))); ?> </div> <div class="acf-form-fields"> <?php // html before fields echo $args['html_before_fields']; // start table if ($args['label_placement'] == 'left') { $args['field_el'] = 'tr'; ?> <table class="acf-table"><tbody><?php } acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']); // end table if ($args['label_placement'] == 'left') { ?> </tbody></table><?php } // html after fields echo $args['html_after_fields']; ?> </div><!-- acf-form-fields --> <?php if ($args['form']) { ?> <!-- Submit --> <div class="acf-form-submit"> <input type="submit" class="button button-primary button-large" value="<?php echo $args['submit_value']; ?> " /> </div> <!-- / Submit --> </form> <?php } }
" data-show-fields='<?php echo json_encode($field['show_fields']); ?> '> <div class="acf-hidden"> <?php acf_hidden_input(['name' => $field['name'] . '[url]', 'value' => $values['url'], 'data-name' => 'url']); ?> <?php acf_hidden_input(['name' => $field['name'] . '[title]', 'value' => $values['title'], 'data-name' => 'title']); ?> <?php acf_hidden_input(['name' => $field['name'] . '[target]', 'value' => $values['target'] ? 1 : 0, 'data-name' => 'target']); ?> </div> <div class="view show-if-value acf-soh"> <div class="link-info"> <p style="margin: 0;"> <span<?php if (!in_array('title', $field['show_fields'])) { echo ' hidden'; } ?> > <strong><?php echo __('Title', 'acf'); ?>
function acf_form($args = array()) { // vars $url = acf_get_current_url(); // defaults $args = wp_parse_args($args, array('id' => 'acf-form', 'post_id' => false, 'new_post' => false, 'field_groups' => false, 'fields' => false, 'post_title' => false, 'post_content' => false, 'form' => true, 'form_attributes' => array(), 'return' => add_query_arg('updated', 'true', $url), 'html_before_fields' => '', 'html_after_fields' => '', 'submit_value' => __("Update", 'acf'), 'updated_message' => __("Post updated", 'acf'), 'label_placement' => 'top', 'instruction_placement' => 'label', 'field_el' => 'div', 'uploader' => 'wp')); $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', 'action' => '', 'method' => 'post')); // filter post_id $args['post_id'] = acf_get_valid_post_id($args['post_id']); // load values from this post $post_id = $args['post_id']; // new post? if ($post_id == 'new_post') { // dont load values $post_id = false; // new post defaults $args['new_post'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft')); } // attributes $args['form_attributes']['class'] .= ' acf-form'; // vars $field_groups = array(); $fields = array(); // post_title if ($args['post_title']) { $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true)); } // post_content if ($args['post_content']) { $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : '')); } // specific fields if ($args['fields']) { foreach ($args['fields'] as $selector) { // append field ($strict = false to allow for better compatibility with field names) $fields[] = acf_maybe_get_field($selector, $post_id, false); } } elseif ($args['field_groups']) { foreach ($args['field_groups'] as $selector) { $field_groups[] = acf_get_field_group($selector); } } elseif ($args['post_id'] == 'new_post') { $field_groups = acf_get_field_groups(array('post_type' => $args['new_post']['post_type'])); } else { $field_groups = acf_get_field_groups(array('post_id' => $args['post_id'])); } //load fields based on field groups if (!empty($field_groups)) { foreach ($field_groups as $field_group) { $field_group_fields = acf_get_fields($field_group); if (!empty($field_group_fields)) { foreach (array_keys($field_group_fields) as $i) { $fields[] = acf_extract_var($field_group_fields, $i); } } } } // updated message if (!empty($_GET['updated']) && $args['updated_message']) { echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>'; } // uploader (always set incase of multiple forms on the page) acf_update_setting('uploader', $args['uploader']); // display form if ($args['form']) { ?> <form <?php acf_esc_attr_e($args['form_attributes']); ?> > <?php } // render post data acf_form_data(array('post_id' => $args['post_id'], 'nonce' => 'acf_form')); ?> <div class="acf-hidden"> <?php acf_hidden_input(array('name' => '_acf_form', 'value' => base64_encode(json_encode($args)))); ?> </div> <div class="acf-fields acf-form-fields -<?php echo $args['label_placement']; ?> "> <?php // html before fields echo $args['html_before_fields']; // render acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']); // html after fields echo $args['html_after_fields']; ?> </div><!-- acf-form-fields --> <?php if ($args['form']) { ?> <!-- Submit --> <div class="acf-form-submit"> <input type="submit" class="button button-primary button-large" value="<?php echo $args['submit_value']; ?> " /> <span class="acf-spinner"></span> </div> <!-- / Submit --> </form> <?php } }
function render_layout($field, $layout, $i, $value) { // vars $order = 0; $el = 'div'; $div = array('class' => 'layout', 'data-id' => $i, 'data-layout' => $layout['name']); //Collapse by default. $div['class'] .= ' -collapsed'; // clone if (is_numeric($i)) { $order = $i + 1; } else { $div['class'] .= ' acf-clone'; } ?> <div <?php acf_esc_attr_e($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => "{$field['name']}[{$i}][acf_fc_layout]", 'value' => $layout['name'])); ?> </div> <div class="acf-wa-layout-handle"> <span class="fc-layout-order"><?php echo $order; ?> </span> <?php echo $layout['label']; ?> </div> <ul class="acf-wa-layout-controlls acf-hl"> <li class="acf-wa-show-on-hover"> <a class="acf-icon -plus small" href="#" data-event="add-widget" title="<?php _e('Add layout', 'acf'); ?> "></a> </li> <li class="acf-wa-show-on-hover"> <a class="acf-icon -minus small" href="#" data-event="remove-widget" title="<?php _e('Remove layout', 'acf'); ?> "></a> </li> <li> <a class="acf-icon -collapse small" href="#" data-event="collapse-widget" title="<?php _e('Click to toggle', 'acf'); ?> "></a> </li> </ul> <?php if (!empty($layout['sub_fields'])) { ?> <?php if ($layout['display'] == 'table') { // update vars $el = 'td'; ?> <table class="acf-table"> <thead> <tr> <?php foreach ($layout['sub_fields'] as $sub_field) { $atts = array('class' => "acf-th acf-th-{$sub_field['name']}", 'data-key' => $sub_field['key']); // Add custom width if ($sub_field['wrapper']['width']) { $atts['data-width'] = $sub_field['wrapper']['width']; } ?> <th <?php acf_esc_attr_e($atts); ?> > <?php acf_the_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 ($layout['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'] = "{$field['name']}[{$i}]"; // 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) { // vars $uploader = acf_get_setting('uploader'); // enqueue if ($uploader == 'wp') { acf_enqueue_uploader(); } // vars $url = ''; $div = array('class' => 'acf-image-uploader acf-cf', 'data-preview_size' => $field['preview_size'], 'data-library' => $field['library'], 'data-mime_types' => $field['mime_types'], 'data-uploader' => $uploader); // has value? if ($field['value'] && is_numeric($field['value'])) { $url = wp_get_attachment_image_src($field['value'], $field['preview_size']); if ($url) { $url = $url[0]; $div['class'] .= ' has-value'; } } ?> <div <?php acf_esc_attr_e($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $field['name'], 'value' => $field['value'], 'data-name' => 'id')); ?> </div> <div class="view show-if-value acf-soh"> <img data-name="image" src="<?php echo $url; ?> " alt=""/> <ul class="acf-hl acf-soh-target"> <?php if ($uploader != 'basic') { ?> <li><a class="acf-icon acf-icon-pencil dark" data-name="edit" href="#"></a></li> <?php } ?> <li><a class="acf-icon acf-icon-cancel dark" data-name="remove" href="#"></a></li> </ul> </div> <div class="view hide-if-value"> <?php if ($uploader == 'basic') { ?> <?php if ($field['value'] && !is_numeric($field['value'])) { ?> <div class="acf-error-message"><p><?php echo $field['value']; ?> </p></div> <?php } ?> <input type="file" name="<?php echo $field['name']; ?> " id="<?php echo $field['id']; ?> " /> <?php } else { ?> <p style="margin:0;"><?php _e('No image selected', 'acf'); ?> <a data-name="add" class="acf-button" href="#"><?php _e('Add Image', 'acf'); ?> </a></p> <?php } ?> </div> </div> <?php }
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)); }
function render_field($field) { // convert $field['value'] = acf_get_array($field['value'], false); $field['choices'] = acf_get_array($field['choices']); // placeholder if (empty($field['placeholder'])) { $field['placeholder'] = __("Select", 'acf'); } // add empty value (allows '' to be selected) if (!count($field['value'])) { $field['value'][''] = ''; } // null if ($field['allow_null'] && !$field['multiple']) { $prepend = array('' => '- ' . $field['placeholder'] . ' -'); $field['choices'] = $prepend + $field['choices']; } // 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']); // 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; } } // hidden input if ($field['ui']) { $v = $field['value']; if ($field['multiple']) { $v = implode('||', $v); } else { $v = acf_maybe_get($v, 0, ''); } acf_hidden_input(array('id' => $field['id'] . '-input', 'name' => $field['name'], 'value' => $v)); } elseif ($field['multiple']) { acf_hidden_input(array('id' => $field['id'] . '-input', 'name' => $field['name'])); } // open echo '<select ' . acf_esc_attr($atts) . '>'; // walk $this->walk($field['choices'], $field['value']); // close echo '</select>'; }
function acf_form($args = array()) { // vars $url = acf_get_current_url(); // defaults $args = wp_parse_args($args, array('id' => 'acf-form', 'post_id' => false, 'new_post' => false, 'field_groups' => false, 'fields' => false, 'post_title' => false, 'post_content' => false, 'form' => true, 'form_attributes' => array(), 'return' => add_query_arg('updated', 'true', $url), 'html_before_fields' => '', 'html_after_fields' => '', 'submit_value' => __("Update", 'acf'), 'updated_message' => __("Post updated", 'acf'), 'label_placement' => 'top', 'instruction_placement' => 'label', 'field_el' => 'div')); $args['form_attributes'] = wp_parse_args($args['form_attributes'], array('id' => 'post', 'class' => '', 'action' => '', 'method' => 'post')); // filter post_id $args['post_id'] = acf_get_valid_post_id($args['post_id']); // load values from this post $post_id = $args['post_id']; // new post? if ($post_id == 'new_post') { // dont load values $post_id = false; // new post defaults $args['new_post'] = acf_parse_args($args['new_post'], array('post_type' => 'post', 'post_status' => 'draft')); } // attributes $args['form_attributes']['class'] .= ' acf-form'; // vars $field_groups = array(); $fields = array(); // post_title if ($args['post_title']) { $fields[] = acf_get_valid_field(array('name' => '_post_title', 'label' => 'Title', 'type' => 'text', 'value' => $post_id ? get_post_field('post_title', $post_id) : '', 'required' => true)); } // post_content if ($args['post_content']) { $fields[] = acf_get_valid_field(array('name' => '_post_content', 'label' => 'Content', 'type' => 'wysiwyg', 'value' => $post_id ? get_post_field('post_content', $post_id) : '')); } // specific fields if (!empty($args['fields'])) { foreach ($args['fields'] as $selector) { $fields[] = get_field_object($selector, $post_id, false, false); } } elseif (!empty($args['field_groups'])) { foreach ($args['field_groups'] as $selector) { $field_groups[] = acf_get_field_group($selector); } } elseif ($args['post_id'] == 'new_post') { $field_groups = acf_get_field_groups(array('post_type' => $args['new_post']['post_type'])); } else { $field_groups = acf_get_field_groups(array('post_id' => $args['post_id'])); } //load fields based on field groups if (!empty($field_groups)) { foreach ($field_groups as $field_group) { $field_group_fields = acf_get_fields($field_group); if (!empty($field_group_fields)) { foreach (array_keys($field_group_fields) as $i) { $fields[] = acf_extract_var($field_group_fields, $i); } } } } // updated message if (!empty($_GET['updated']) && $args['updated_message']) { echo '<div id="message" class="updated"><p>' . $args['updated_message'] . '</p></div>'; } // display form if ($args['form']) { ?> <form <?php acf_esc_attr_e($args['form_attributes']); ?> > <?php } // render post data acf_form_data(array('post_id' => $args['post_id'], 'nonce' => 'acf_form')); ?> <div class="acf-hidden"> <?php acf_hidden_input(array('name' => '_acf_form', 'value' => base64_encode(json_encode($args)))); ?> </div> <div class="acf-fields acf-form-fields"> <?php // html before fields echo $args['html_before_fields']; // start table if ($args['label_placement'] == 'left') { $args['field_el'] = 'tr'; ?> <table class="acf-table"><tbody><?php } acf_render_fields($post_id, $fields, $args['field_el'], $args['instruction_placement']); // end table if ($args['label_placement'] == 'left') { ?> </tbody></table><?php } // html after fields echo $args['html_after_fields']; ?> </div><!-- acf-form-fields --> <?php if ($args['form']) { ?> <!-- Submit --> <div class="acf-form-submit"> <input type="submit" class="button button-primary button-large" value="<?php echo $args['submit_value']; ?> " /> <span class="acf-loading" style="display: none;"></span> </div> <!-- / Submit --> </form> <script type="text/javascript"> (function($) { // vars var $spinner = $('#<?php echo $args['form_attributes']['id']; ?> .acf-form-submit .acf-loading'); // show spinner on submit $(document).on('submit', '#<?php echo $args['form_attributes']['id']; ?> ', function(){ // show spinner $spinner.css('display', 'inline-block'); }); // hide spinner after validation acf.add_filter('validation_complete', function( json, $form ){ // hide spinner $spinner.css('display', 'none'); // return return json; }); })(jQuery); </script> <?php } }
function render_field_settings($field) { // load default layout if (empty($field['layouts'])) { $field['layouts'] = array(); $field['layouts'][] = $this->get_valid_layout(); } // loop through layouts foreach ($field['layouts'] as $layout) { // get valid layout $layout = $this->get_valid_layout($layout); // vars $layout_prefix = "{$field['prefix']}[layouts][{$layout['key']}]"; ?> <tr class="acf-field" data-name="fc_layout" data-setting="flexible_content" data-id="<?php echo $layout['key']; ?> "> <td class="acf-label"> <label><?php _e("Layout", 'acf'); ?> </label> <p class="description acf-fl-actions"> <a data-name="acf-fc-reorder" title="<?php _e("Reorder Layout", 'acf'); ?> " ><?php _e("Reorder", 'acf'); ?> </a> <a data-name="acf-fc-delete" title="<?php _e("Delete Layout", 'acf'); ?> " href="#"><?php _e("Delete", 'acf'); ?> </a> <a data-name="acf-fc-duplicate" title="<?php _e("Duplicate Layout", 'acf'); ?> " href="#"><?php _e("Duplicate", 'acf'); ?> </a> <a data-name="acf-fc-add" title="<?php _e("Add New Layout", 'acf'); ?> " href="#"><?php _e("Add New", 'acf'); ?> </a> </p> </td> <td class="acf-input"> <ul class="acf-fc-meta acf-bl"> <li class="acf-fc-meta-key"> <?php acf_hidden_input(array('name' => "{$layout_prefix}[key]", 'data-name' => 'layout-key', 'value' => $layout['key'])); ?> </li> <li class="acf-fc-meta-label"> <?php acf_render_field(array('type' => 'text', 'name' => 'label', 'prefix' => $layout_prefix, 'value' => $layout['label'], 'prepend' => __('Label', 'acf'))); ?> </li> <li class="acf-fc-meta-name"> <?php acf_render_field(array('type' => 'text', 'name' => 'name', 'prefix' => $layout_prefix, 'value' => $layout['name'], 'prepend' => __('Name', 'acf'))); ?> </li> <li class="acf-fc-meta-display"> <div class="acf-input-prepend"><?php _e('Layout', 'acf'); ?> </div> <div class="acf-input-wrap select"> <?php acf_render_field(array('type' => 'select', 'name' => 'display', 'prefix' => $layout_prefix, 'value' => $layout['display'], 'choices' => array('table' => __('Table', 'acf'), 'block' => __('Block', 'acf'), 'row' => __('Row', 'acf')))); ?> </div> </li> <li class="acf-fc-meta-min"> <?php acf_render_field(array('type' => 'text', 'name' => 'min', 'prefix' => $layout_prefix, 'value' => $layout['min'], 'prepend' => __('Min', 'acf'))); ?> </li> <li class="acf-fc-meta-max"> <?php acf_render_field(array('type' => 'text', 'name' => 'max', 'prefix' => $layout_prefix, 'value' => $layout['max'], 'prepend' => __('Max', 'acf'))); ?> </li> </ul> <?php // vars $args = array('fields' => $layout['sub_fields'], 'layout' => $layout['display'], 'parent' => $field['ID']); acf_get_view('field-group-fields', $args); ?> </td> </tr> <?php } // endforeach // min acf_render_field_setting($field, array('label' => __('Button Label', 'acf'), 'instructions' => '', 'type' => 'text', 'name' => 'button_label')); // min acf_render_field_setting($field, array('label' => __('Minimum Layouts', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'min')); // max acf_render_field_setting($field, array('label' => __('Maximum Layouts', 'acf'), 'instructions' => '', 'type' => 'number', 'name' => 'max')); }
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 }
function render_field($field) { // vars $div = array('class' => 'acf-repeater', 'data-min' => $field['min'], 'data-max' => $field['max']); // ensure value is an array if (empty($field['value'])) { $field['value'] = array(); $div['class'] .= ' -empty'; } // rows $field['min'] = empty($field['min']) ? 0 : $field['min']; $field['max'] = empty($field['max']) ? 0 : $field['max']; // populate the empty row data (used for acfcloneindex and min setting) $empty_row = array(); // If there are less values than min, populate the extra values if ($field['min']) { for ($i = 0; $i < $field['min']; $i++) { // continue if already have a value if (array_key_exists($i, $field['value'])) { continue; } // populate values $field['value'][$i] = $empty_row; } } // If there are more values than man, remove some values if ($field['max']) { for ($i = 0; $i < count($field['value']); $i++) { if ($i >= $field['max']) { unset($field['value'][$i]); } } } // setup values for row clone $field['value']['acfcloneindex'] = $empty_row; // show columns $show_order = true; $show_add = true; $show_remove = true; if ($field['max']) { if ($field['max'] == 1) { $show_order = false; } if ($field['max'] <= $field['min']) { $show_remove = false; $show_add = false; } } // field wrap $el = 'td'; $before_fields = ''; $after_fields = ''; if ($field['layout'] == 'row') { $el = 'div'; $before_fields = '<td class="acf-fields -left">'; $after_fields = '</td>'; } elseif ($field['layout'] == 'block') { $el = 'div'; $before_fields = '<td class="acf-fields">'; $after_fields = '</td>'; } // layout $div['class'] .= ' -' . $field['layout']; // hidden input acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); // collapsed $collapsed = array(); if ($field['collapsed']) { // get user setting $collapsed = acf_get_user_setting('collapsed_' . $field['key'], ''); $collapsed = explode(',', $collapsed); $collapsed = array_filter($collapsed, 'is_numeric'); // add target class foreach (array_keys($field['sub_fields']) as $i) { if ($field['sub_fields'][$i]['key'] === $field['collapsed']) { $field['sub_fields'][$i]['wrapper']['class'] .= ' -collapsed-target'; } } } ?> <div <?php acf_esc_attr_e($div); ?> > <table class="acf-table"> <?php if ($field['layout'] == 'table') { ?> <thead> <tr> <?php if ($show_order) { ?> <th class="acf-row-handle"><span></span></th> <?php } ?> <?php foreach ($field['sub_fields'] as $sub_field) { $atts = array('class' => 'acf-th', 'data-key' => $sub_field['key']); // add type $atts['class'] .= ' acf-th-' . $sub_field['type']; // Add custom width if ($sub_field['wrapper']['width']) { $atts['data-width'] = $sub_field['wrapper']['width']; } ?> <th <?php acf_esc_attr_e($atts); ?> > <?php acf_the_field_label($sub_field); ?> <?php if ($sub_field['instructions']) { ?> <p class="description"><?php echo $sub_field['instructions']; ?> </p> <?php } ?> </th> <?php } ?> <?php if ($show_remove) { ?> <th class="acf-row-handle"><span></span></th> <?php } ?> </tr> </thead> <?php } ?> <tbody> <?php foreach ($field['value'] as $i => $row) { $row_class = 'acf-row'; if ($i === 'acfcloneindex') { $row_class .= ' acf-clone'; } elseif (in_array($i, $collapsed)) { $row_class .= ' -collapsed'; } ?> <tr class="<?php echo $row_class; ?> " data-id="<?php echo $i; ?> "> <?php if ($show_order) { ?> <td class="acf-row-handle order" title="<?php _e('Drag to reorder', 'acf'); ?> "> <?php if ($field['collapsed']) { ?> <a class="acf-icon -collapse small" href="#" data-event="collapse-row" title="<?php _e('Click to toggle', 'acf'); ?> "></a> <?php } ?> <span><?php echo intval($i) + 1; ?> </span> </td> <?php } ?> <?php echo $before_fields; ?> <?php foreach ($field['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($row[$sub_field['key']])) { // this is a normal value $sub_field['value'] = $row[$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'] = "{$field['name']}[{$i}]"; // render input acf_render_field_wrap($sub_field, $el); ?> <?php } ?> <?php echo $after_fields; ?> <?php if ($show_remove) { ?> <td class="acf-row-handle remove"> <a class="acf-icon -plus small" href="#" data-event="add-row" title="<?php _e('Add row', 'acf'); ?> "></a> <a class="acf-icon -minus small" href="#" data-event="remove-row" title="<?php _e('Remove row', 'acf'); ?> "></a> </td> <?php } ?> </tr> <?php } ?> </tbody> </table> <?php if ($show_add) { ?> <ul class="acf-hl"> <li class="acf-fr"> <a href="#" class="acf-button blue" data-event="add-row"><?php echo $field['button_label']; ?> </a> </li> </ul> <?php } ?> </div> <?php }
function render_field($field) { global $q_config; $languages = qtrans_getSortedLanguages(true); $values = qtrans_split($field['value'], $quicktags = true); $currentLanguage = $this->plugin->get_active_language(); // enqueue acf_enqueue_uploader(); // vars $div = array('class' => 'acf-image-uploader acf-cf', 'data-preview_size' => $field['preview_size'], 'data-library' => $field['library'], 'data-mime_types' => $field['mime_types']); $input_atts = array('type' => 'hidden', 'name' => $field['name'], 'value' => $field['value'], 'data-name' => 'value-id'); $url = ''; echo '<div class="multi-language-field multi-language-field-image">'; foreach ($languages as $language) { $class = 'wp-switch-editor'; if ($language === $currentLanguage) { $class .= ' current-language'; } echo '<a class="' . $class . '" data-language="' . $language . '">' . $q_config['language_name'][$language] . '</a>'; } foreach ($languages as $language) { $input_atts['name'] = $field['name'] . '[' . $language . ']'; $field['value'] = $values[$language]; $div['data-language'] = $language; $div['class'] = 'acf-image-uploader acf-cf'; // has value? if ($field['value'] && is_numeric($field['value'])) { $url = wp_get_attachment_image_src($field['value'], $field['preview_size']); $url = $url[0]; $div['class'] .= ' has-value'; } // basic? $basic = !current_user_can('upload_files'); if ($basic) { $div['class'] .= ' basic'; } if ($language === $currentLanguage) { $div['class'] .= ' current-language'; } ?> <div <?php acf_esc_attr_e($div); ?> > <div class="acf-hidden"> <?php acf_hidden_input(array('name' => $input_atts['name'], 'value' => $field['value'], 'data-name' => 'id')); ?> </div> <div class="view show-if-value acf-soh"> <img data-name="image" src="<?php echo $url; ?> " alt=""/> <ul class="acf-hl acf-soh-target"> <?php if (!$basic) { ?> <li><a class="acf-icon dark" data-name="edit" href="#"><i class="acf-sprite-edit"></i></a></li> <?php } ?> <li><a class="acf-icon dark" data-name="remove" href="#"><i class="acf-sprite-delete"></i></a></li> </ul> </div> <div class="view hide-if-value"> <?php if ($basic) { ?> <?php if ($field['value'] && !is_numeric($field['value'])) { ?> <div class="acf-error-message"><p><?php echo $field['value']; ?> </p></div> <?php } ?> <input type="file" name="<?php echo $field['name']; ?> " id="<?php echo $field['id']; ?> " /> <?php } else { ?> <p style="margin:0;"><?php _e('No image selected', 'acf'); ?> <a data-name="add" class="acf-button" href="#"><?php _e('Add Image', 'acf'); ?> </a></p> <?php } ?> </div> </div> <?php } echo '</div>'; }
function render_field_checkbox($field) { // hidden input acf_hidden_input(array('type' => 'hidden', 'name' => $field['name'])); // checkbox saves an array if ($field['field_type'] == 'checkbox') { $field['name'] .= '[]'; } // vars $args = array('taxonomy' => $field['taxonomy'], 'hide_empty' => false, 'style' => 'none', 'walker' => new acf_taxonomy_field_walker($field)); // filter for 3rd party customization $args = apply_filters('acf/fields/taxonomy/wp_list_categories', $args, $field); ?> <div class="categorychecklist-holder"> <ul class="acf-checkbox-list acf-bl"> <?php if ($field['field_type'] == 'radio' && $field['allow_null']) { ?> <li> <label class="selectit"> <input type="radio" name="<?php echo $field['name']; ?> " value="" /> <?php _e("None", 'acf'); ?> </label> </li> <?php } ?> <?php wp_list_categories($args); ?> </ul> </div><?php }
function render_field($field) { $taxonomies = array(); $taxonomies = acf_get_array($taxonomies); $taxonomies = acf_get_pretty_taxonomies($taxonomies); $taxonomy_terms = acf_get_taxonomy_terms(); $selected_taxonomies = array(); $terms = array(); $slug_name = !empty($field['choices']) ? $field['choices'] : array_keys(acf_get_pretty_taxonomies()); if ($field['tax_type'] == 'Term') { // select terms foreach ($slug_name as $k1 => $v1) { $terms = array_merge($terms, get_terms($v1, array('hide_empty' => false))); foreach ($taxonomies as $k2 => $v2) { if ($v1 == $k2) { $field['choices'][$k1] = $v2; } } } foreach ($field['choices'] as $k1 => $v1) { foreach ($taxonomy_terms as $k2 => $v2) { if ($v1 == $k2) { $selected_taxonomies[$v1] = $taxonomy_terms[$k2]; } } } } else { //select taxonomies $taxonomies = array(); foreach ($slug_name as $tax_name) { // only use allowed taxonomies $taxonomies[$tax_name] = get_taxonomy($tax_name); } foreach ($taxonomies as $taxonomy) { $selected_taxonomies[$taxonomy->name] = $taxonomy->label; } } $field['choices'] = $selected_taxonomies; // add empty value (allows '' to be selected) if (empty($field['value'])) { $field['value'] = ''; $field['value']['cat'] = ''; } // placeholder if (empty($field['placeholder'])) { $field['placeholder'] = __("Select", 'acf'); } // vars $atts = array('id' => $field['id'], 'class' => $field['class'] . ' js-multi-taxonomy-select2', 'name' => $field['name'], 'data-ui' => $field['ui'], 'data-ajax' => $field['ajax'], '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'; } // 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) { // allowed taxonomies if (is_array($v)) { // optgroup $els[] = array('type' => 'optgroup', 'label' => $k); if (!empty($v)) { foreach ($v as $k2 => $v2) { $strip_v2_hyphen = preg_replace('#-\\s?#', '', $v2); // Child categories have hyphens before the name, we need to remove them in order to match them if ($field['type_value']) { // value = term ID foreach ($terms as $key => $val) { if ($val->name == $strip_v2_hyphen) { $els[] = array('type' => 'option', 'value' => $val->term_id, 'label' => $v2, 'selected' => $slct = $val->term_id == $field['value'] ? "selected" : ""); } } } else { // value = term slug preg_match('#(?::)(.*)#', $k2, $value); // originally returns 'taxonomy:term-slug' this removes 'taxonomy:' $els[] = array('type' => 'option', 'value' => $value[1], 'label' => $v2, 'selected' => $slct = $value[1] == $field['value'] ? "selected" : ""); } $choices[] = $k2; } } $els[] = array('type' => '/optgroup'); } else { // value = Taxonomy Slug $els[] = array('type' => 'option', 'value' => $k, 'label' => $v, 'selected' => $slct = $k == $field['value'] ? "selected" : ""); $choices[] = $k; } } } // 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 acf_esc_attr($el); echo '<option ' . acf_esc_attr($el) . '>' . $label . '</option>'; } else { echo '<' . $type . ' ' . acf_esc_attr($el) . '>'; } } } echo '</select>'; }