本文整理汇总了PHP中acf_prepare_field函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_prepare_field函数的具体用法?PHP acf_prepare_field怎么用?PHP acf_prepare_field使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_prepare_field函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: acf_render_field
function acf_render_field($field = false)
{
// get valid field
$field = acf_get_valid_field($field);
// prepare field for input
$field = acf_prepare_field($field);
// update $field['name']
$field['name'] = $field['_input'];
// create field specific html
do_action("acf/render_field", $field);
do_action("acf/render_field/type={$field['type']}", $field);
}
示例2: acf_render_field_wrap
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']) {
?>
//.........这里部分代码省略.........
示例3: setup_field
function setup_field($field)
{
// setup booleans, for compatibility
$field = acf_prepare_field(array_merge($this->defaults, $field));
// set up the sub_field
$sub_field = isset($field['sub_field']) ? $field['sub_field'] : array();
// create it
// mask the sub field as the parent by giving it the same key values
foreach ($field as $key => $value) {
if (in_array($key, array('sub_field', 'type'))) {
continue;
}
$sub_field[$key] = $value;
}
// these fields need some special formatting
$sub_field['_input'] = $field['prefix'] . '[' . $sub_field['key'] . ']';
$sub_field['name'] = $sub_field['_input'];
$sub_field['id'] = str_replace('-acfcloneindex', '', str_replace(']', '', str_replace('[', '-', $sub_field['_input'])));
// make sure all the defaults are set
$field['sub_field'] = array_merge($this->sub_defaults, $sub_field);
return $field;
}
示例4: render_layout
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);
?>
//.........这里部分代码省略.........
示例5: acf_render_field_wrap
function acf_render_field_wrap($field, $el = 'div', $instruction = 'label', $atts = array())
{
// 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';
}
// atts
$atts = acf_parse_args($atts, array('class' => '', 'data-name' => $field['name'], 'data-type' => $field['type']));
// add to atts
$atts['class'] .= " acf-field field_type-{$field['type']}";
// add key
if ($field['key']) {
$atts['class'] .= " field_key-{$field['key']}";
$atts['data-key'] = $field['key'];
}
// add required
if ($field['required']) {
$atts['data-required'] = 1;
}
// vars
$show_label = true;
if ($el == 'td') {
$show_label = false;
}
?>
<<?php
echo $el;
?>
<?php
echo acf_esc_attr($atts);
?>
>
<?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);
?>
<?php
if ($instruction == 'field' && $field['instructions']) {
?>
<p class="description"><?php
echo $field['instructions'];
?>
</p>
<?php
}
?>
<?php
if (!empty($field['conditional_logic'])) {
?>
<script type="text/javascript">
(function($) {
if( typeof acf !== 'undefined' )
{
//.........这里部分代码省略.........
示例6: render_field_table
function render_field_table($field)
{
?>
<table class="acf-table">
<thead>
<tr>
<?php
foreach ($field['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
acf_esc_attr_e($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>
<tr class="acf-row">
<?php
foreach ($field['sub_fields'] as $sub_field) {
acf_render_field_wrap($sub_field, 'td');
}
?>
</tr>
</tbody>
</table>
<?php
}
示例7: render_field
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;
}
//.........这里部分代码省略.........