本文整理汇总了PHP中acf_format_value函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_format_value函数的具体用法?PHP acf_format_value怎么用?PHP acf_format_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_format_value函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format_value
function format_value($value, $post_id, $field)
{
// bail early if no value
if (empty($value) || empty($field['layouts'])) {
return false;
}
// populate $layouts
$layouts = array();
foreach (array_keys($field['layouts']) as $i) {
// get layout
$layout = $field['layouts'][$i];
// append to $layouts
$layouts[$layout['name']] = $layout['sub_fields'];
}
// loop over rows
foreach (array_keys($value) as $i) {
// get layout name
$l = $value[$i]['acf_fc_layout'];
// bail early if layout deosnt exist
if (empty($layouts[$l])) {
continue;
}
// get layout
$layout = $layouts[$l];
// loop through sub fields
foreach (array_keys($layout) as $j) {
// get sub field
$sub_field = $layout[$j];
// extract value
$sub_value = acf_extract_var($value[$i], $sub_field['key']);
// format value
$sub_value = acf_format_value($sub_value, $post_id, $sub_field);
// append to $row
$value[$i][$sub_field['name']] = $sub_value;
}
}
// return
return $value;
}
示例2: format_value
function format_value($value, $post_id, $field)
{
// bail early if no value
if (empty($value)) {
return false;
}
// modify
$field = $this->prepare_field_for_save($field);
// loop over rows
foreach (array_keys($field['sub_fields']) as $i) {
// get sub field
$sub_field = $field['sub_fields'][$i];
// extract value
$sub_value = acf_extract_var($value, $sub_field['key']);
// format value
$sub_value = acf_format_value($sub_value, $post_id, $sub_field);
// append to $row
$value[$sub_field['_name']] = $sub_value;
}
// return
return $value;
}
示例3: format_value
function format_value($value, $post_id, $field)
{
// bail early if no value
if (empty($value) || empty($field['sub_fields'])) {
return $value;
}
// loop over rows
foreach (array_keys($value) as $i) {
// loop through sub fields
foreach (array_keys($field['sub_fields']) as $j) {
// get sub field
$sub_field = $field['sub_fields'][$j];
// extract value
$sub_value = acf_extract_var($value[$i], $sub_field['key']);
// format value
$sub_value = acf_format_value($sub_value, $post_id, $sub_field);
// append to $row
$value[$i][$sub_field['name']] = $sub_value;
}
}
// return
return $value;
}
示例4: load_value
function load_value($value, $post_id, $field)
{
$fields = array();
foreach ($field['sub_fields'] as $sub_field) {
$sub_field_name = $sub_field['name'];
// update prefix to allow for nested values
$sub_field['prefix'] = $field["name"];
$sub_field['name'] = "{$field['name']}_{$sub_field_name}";
// load value
if ($sub_field['value'] === null) {
$sub_field['value'] = acf_format_value(acf_get_value($post_id, $sub_field), $post_id, $sub_field);
}
$fields[$sub_field_name] = $sub_field['value'];
}
return $fields;
}
示例5: get_sub_field
function get_sub_field($selector, $format_value = true)
{
// vars
$row = acf_get_row();
// bail early if no row
if (!$row) {
return false;
}
// attempt to find sub field
$sub_field = acf_get_sub_field($selector, $row['field']);
// update selector
if ($sub_field) {
$selector = $sub_field['key'];
} else {
$format_value = false;
}
// return value
if (isset($row['value'][$row['i']][$selector])) {
// get
$value = $row['value'][$row['i']][$selector];
// format
if ($format_value) {
$value = acf_format_value($value, $row['post_id'], $sub_field);
}
// return
return $value;
}
// return false
return false;
}
示例6: getField
public function getField($fieldId, $format = true)
{
if (!function_exists('acf_is_field_key')) {
throw new \Exception('Advanced Custom Fields must be installed to use ' . __METHOD__);
}
$value = maybe_unserialize($this->getMeta($fieldId));
$fieldId = $this->getMeta('_' . $fieldId);
if (!acf_is_field_key($fieldId)) {
return null;
}
$field = get_field_object($fieldId, $this->ID, false, false);
$value = apply_filters("acf/load_value", $value, $this->ID, $field);
$value = apply_filters("acf/load_value/type={$field['type']}", $value, $this->ID, $field);
$value = apply_filters("acf/load_value/name={$field['name']}", $value, $this->ID, $field);
$value = apply_filters("acf/load_value/key={$field['key']}", $value, $this->ID, $field);
if ($format) {
$value = acf_format_value($value, $this->ID, $field);
}
return $value;
}
示例7: get_field_object
function get_field_object($selector, $post_id = false, $format_value = true, $load_value = true)
{
// complete loading
acf()->complete();
// compatibilty
if (is_array($format_value)) {
$format_value = acf_parse_args($format_value, array('format_value' => true, 'load_value' => true));
extract($format_value);
}
// vars
$override_name = false;
// filter post_id
$post_id = acf_get_valid_post_id($post_id);
// load field reference if not a field_key
if (!acf_is_field_key($selector)) {
$override_name = $selector;
$selector = acf_get_field_reference($selector, $post_id);
}
// get field key
$field = acf_get_field($selector);
// bail early if no field found
if (!$field) {
return false;
}
// override name?
// This allows the $selector to be a sub field (images_0_image)
if ($override_name) {
$field['name'] = $override_name;
}
// load value
if ($load_value) {
$field['value'] = acf_get_value($post_id, $field);
}
// format value
if ($format_value) {
// get value for field
$field['value'] = acf_format_value($field['value'], $post_id, $field);
}
// return
return $field;
}
示例8: format_value
/**
* Run a field value through ACF's formatting filters to prepare them for output
*
* For example, paragraphs and line breaks are added to WYSIWYG fields.
*
* @param mixed $value ACF field value
* @param array $field_data Info about the field type as provided by ACF
* @return mixed Formatted field value
*/
public static function format_value($value, $field_data)
{
if (self::is_pro_installed()) {
return acf_format_value($value, uniqid('layotter_acf_'), $field_data);
} else {
return apply_filters('acf/format_value_for_api', $value, uniqid('layotter_acf_'), $field_data);
// for all field types
}
}
示例9: pmxe_export_acf_field_xml
//.........这里部分代码省略.........
}
$field_value = implode(",", $v);
} else {
if (is_numeric($field_value)) {
$entry = get_user_by('ID', $field_value);
if ($entry) {
$field_value = $entry->user_email;
}
} else {
$field_value = $field_value['user_email'];
}
}
break;
case 'taxonomy':
$xmlWriter->startElement($element_name);
if (!in_array($field_options['field_type'], array('radio', 'select'))) {
foreach ($field_value as $key => $tid) {
$entry = get_term($tid, $field_options['taxonomy']);
if ($entry and !is_wp_error($entry)) {
$xmlWriter->startElement('term');
$xmlWriter->writeCData($entry->slug);
$xmlWriter->endElement();
}
}
} else {
$entry = get_term($field_value, $field_options['taxonomy']);
if ($entry) {
$xmlWriter->startElement('term');
$xmlWriter->writeCData($entry->slug);
$xmlWriter->endElement();
}
}
$xmlWriter->endElement();
$put_to_xml = false;
break;
case 'select':
if (!empty($field_options['multiple'])) {
$field_value = implode(",", $field_value);
}
break;
case 'checkbox':
$field_value = implode(",", $field_value);
break;
case 'repeater':
$xmlWriter->startElement($element_name);
if (have_rows($field_name, $recordID)) {
while (have_rows($field_name, $recordID)) {
the_row();
$row = acf_get_row();
//$xmlWriter->startElementNs('key_' . $row['i'], 'row', null);
$xmlWriter->startElement('row');
foreach ($row['field']['sub_fields'] as $sub_field) {
// get
$v = acf_format_value($row['value'][$row['i']][$sub_field['key']], $row['post_id'], $sub_field);
pmxe_export_acf_field_xml($v, $sub_field, false, $recordID, $xmlWriter, $sub_field['name'], '', '');
}
$xmlWriter->endElement();
}
}
$xmlWriter->endElement();
$put_to_xml = false;
break;
case 'flexible_content':
$xmlWriter->startElement($element_name);
// check if the flexible content field has rows of data
if (have_rows($field_name)) {
// loop through the rows of data
while (have_rows($field_name)) {
the_row();
$row = acf_get_row();
foreach ($row['field']['layouts'] as $layout) {
if ($layout['name'] == $row['value'][$row['i']]['acf_fc_layout']) {
$xmlWriter->startElement($row['value'][$row['i']]['acf_fc_layout'] . '_' . $row['i']);
foreach ($layout['sub_fields'] as $sub_field) {
if (isset($row['value'][$row['i']][$sub_field['key']])) {
// get
$v = acf_format_value($row['value'][$row['i']][$sub_field['key']], $row['post_id'], $sub_field);
pmxe_export_acf_field_xml($v, $sub_field, false, $recordID, $xmlWriter, $sub_field['name'], '', '');
}
}
$xmlWriter->endElement();
}
}
}
} else {
// no layouts found
}
$xmlWriter->endElement();
$put_to_xml = false;
break;
default:
break;
}
if ($put_to_xml) {
$xmlWriter->startElement($element_name);
$xmlWriter->writeCData(apply_filters('pmxe_acf_field', pmxe_filter(maybe_serialize($field_value), $fieldSnipped), $field_name, $recordID));
$xmlWriter->endElement();
}
}
}
示例10: get_sub_field_object
function get_sub_field_object($selector, $format_value = true, $load_value = true)
{
// vars
$row = acf_get_loop('active');
// bail early if no row
if (!$row) {
return false;
}
// attempt to find sub field
$sub_field = get_row_sub_field($selector);
// bail early if no sub field
if (!$sub_field) {
return false;
}
// load value
$sub_field['value'] = get_row_sub_value($sub_field['key']);
// format value
if ($format_value) {
// get value for field
$sub_field['value'] = acf_format_value($sub_field['value'], $row['post_id'], $sub_field);
}
// return
return $sub_field;
}
示例11: render_simple_field
public function render_simple_field($field)
{
echo '<div class="acf-output-wrap">';
$value = acf_format_value($field['value'], $this->post_id, $field);
if (is_array($value)) {
$value = implode(', ', $value);
}
echo $value;
echo '</div>';
}
示例12: format_value
function format_value($value, $post_id, $field)
{
// bail early if no value
if (empty($value) || empty($field['sub_fields'])) {
return false;
}
// loop over rows
foreach (array_keys($value) as $i) {
// loop through sub fields
foreach (array_keys($field['sub_fields']) as $j) {
// get sub field
$sub_field = $field['sub_fields'][$j];
// bail ealry if no name (tab)
if (acf_is_empty($sub_field['name'])) {
continue;
}
// extract value
$sub_value = acf_extract_var($value[$i], $sub_field['key']);
// update $sub_field name
$sub_field['name'] = "{$field['name']}_{$i}_{$sub_field['name']}";
// format value
$sub_value = acf_format_value($sub_value, $post_id, $sub_field);
// append to $row
$value[$i][$sub_field['_name']] = $sub_value;
}
}
// return
return $value;
}
示例13: get_field_objects
function get_field_objects($post_id = false, $format_value = true, $load_value = true)
{
// global
global $wpdb;
// filter post_id
$post_id = acf_get_valid_post_id($post_id);
// vars
$meta = array();
$fields = array();
// get field_names
if (is_numeric($post_id)) {
$meta = get_post_meta($post_id);
} elseif (strpos($post_id, 'user_') !== false) {
$user_id = (int) str_replace('user_', '', $post_id);
$meta = get_user_meta($user_id);
} elseif (strpos($post_id, 'comment_') !== false) {
$comment_id = (int) str_replace('comment_', '', $post_id);
$meta = get_comment_meta($comment_id);
} else {
$rows = $wpdb->get_results($wpdb->prepare("SELECT option_name, option_value FROM {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s", $post_id . '_%', '_' . $post_id . '_%'), ARRAY_A);
if (!empty($rows)) {
foreach ($rows as $row) {
$meta[$row['option_name']][] = $row['option_value'];
}
}
}
// populate vars
if (!empty($meta)) {
foreach ($meta as $k => $v) {
// Hopefuly improve efficiency: bail early if $k does start with an '_'
if ($k[0] === '_') {
continue;
}
// does a field key exist for this value?
if (!array_key_exists("_{$k}", $meta)) {
continue;
}
// get field
$field_key = $meta["_{$k}"][0];
$field = acf_get_field($field_key);
// bail early if not a parent field
if (empty($field) || acf_is_sub_field($field)) {
continue;
}
// load value
if ($load_value) {
$field['value'] = acf_get_value($post_id, $field);
// format value
if ($format_value) {
// get value for field
$field['value'] = acf_format_value($field['value'], $post_id, $field);
}
}
// append to $value
$fields[$field['name']] = $field;
}
}
// no value
if (empty($fields)) {
return false;
}
// return
return $fields;
}
示例14: export_acf_field
//.........这里部分代码省略.........
if ($entry) {
$field_value = $entry->name;
}
}
}
break;
case 'select':
if (!empty($field_options['multiple'])) {
$field_value = implode($implode_delimiter, $field_value);
}
break;
case 'checkbox':
if (is_array($field_value)) {
$field_value = implode($implode_delimiter, $field_value);
}
break;
case 'repeater':
if ($is_xml_export) {
$xmlWriter->beginElement($element_name_ns, $element_name, null);
}
if (have_rows($field_name, $pid)) {
$rowValues = array();
$repeater_sub_field_names = array();
while (have_rows($field_name, $pid)) {
the_row();
$row = self::acf_get_row();
if ($is_xml_export) {
$xmlWriter->startElement('row');
}
foreach ($row['field']['sub_fields'] as $sub_field) {
if ($acf and version_compare($acf->settings['version'], '5.0.0') >= 0) {
$v = $row['value'][$row['i']][$sub_field['key']];
if ($is_xml_export) {
$v = acf_format_value($v, $row['post_id'], $sub_field);
}
} else {
$v = get_sub_field($sub_field['name']);
}
$sub_field['delimiter'] = $implode_delimiter;
$sub_field_value = self::export_acf_field($v, $sub_field, false, $pid, $article, $xmlWriter, $acfs, $is_xml_export ? $sub_field['name'] : $element_name . '_' . $sub_field['name'], $element_name_ns, $fieldSnipped, '', $preview, $is_xml_export ? false : true);
if (!$is_xml_export) {
switch ($sub_field['type']) {
case 'google_map':
case 'paypal_item':
case 'location-field':
case 'repeater':
if (!empty($sub_field_value)) {
foreach ($sub_field_value as $repeater_key => $repeater_value) {
$rowValues[$sub_field['name']][$repeater_key][] = is_array($repeater_value) ? implode($exportOptions['delimiter'], $repeater_value) : $repeater_value;
}
}
break;
default:
$rowValues[$sub_field['name']][] = apply_filters('pmxe_acf_field', pmxe_filter(is_array($sub_field_value) ? implode($exportOptions['delimiter'], $sub_field_value) : $sub_field_value, $fieldSnipped), $sub_field['name'], $pid);
break;
}
}
}
if ($is_xml_export) {
$xmlWriter->endElement();
}
}
if ($return_value) {
return $rowValues;
}
if (!$is_xml_export) {