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; }
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; }
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; }
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; }
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; }
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; }
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; }
/** * 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 } }
function pmxe_export_acf_field_xml($field_value, $exportOptions, $ID, $recordID, &$xmlWriter, $element_name = '', $fieldSnipped = '', $group_id = '') { if (!empty($field_value)) { $field_value = maybe_unserialize($field_value); $field_name = $ID ? $exportOptions['cc_label'][$ID] : $exportOptions['name']; $field_options = $ID ? unserialize($exportOptions['cc_options'][$ID]) : $exportOptions; //$element_name = 'acf_' . $element_name; $put_to_xml = true; // switch ACF field type switch ($field_options['type']) { case 'date_time_picker': case 'date_picker': $field_value = date('Ymd', strtotime($field_value)); break; case 'file': case 'image': if (is_numeric($field_value)) { $field_value = wp_get_attachment_url($field_value); } elseif (is_array($field_value)) { $field_value = $field_value['url']; } break; case 'gallery': $v = array(); foreach ($field_value as $key => $item) { $v[] = $item['url']; } $field_value = implode(",", $v); break; case 'location-field': $localion_parts = explode("|", $field_value); if (!empty($localion_parts)) { $xmlWriter->startElement($element_name); $xmlWriter->startElement('address'); $xmlWriter->writeCData($localion_parts[0]); $xmlWriter->endElement(); if (!empty($localion_parts[1])) { $coordinates = explode(",", $localion_parts[1]); if (!empty($coordinates)) { $xmlWriter->startElement('lat'); $xmlWriter->writeCData($coordinates[0]); $xmlWriter->endElement(); $xmlWriter->startElement('lng'); $xmlWriter->writeCData($coordinates[1]); $xmlWriter->endElement(); } } $xmlWriter->endElement(); } $put_to_xml = false; break; case 'paypal_item': $xmlWriter->startElement($element_name); if (is_array($field_value)) { foreach ($field_value as $key => $value) { $xmlWriter->startElement($key); $xmlWriter->writeCData($value); $xmlWriter->endElement(); } } $xmlWriter->endElement(); $put_to_xml = false; break; case 'google_map': $xmlWriter->startElement($element_name); $xmlWriter->startElement('address'); $xmlWriter->writeCData($field_value['address']); $xmlWriter->endElement(); $xmlWriter->startElement('lat'); $xmlWriter->writeCData($field_value['lat']); $xmlWriter->endElement(); $xmlWriter->startElement('lng'); $xmlWriter->writeCData($field_value['lng']); $xmlWriter->endElement(); $xmlWriter->endElement(); $put_to_xml = false; break; case 'acf_cf7': case 'gravity_forms_field': if (!empty($field_options['multiple'])) { $field_value = implode(",", $field_value); } break; case 'page_link': if (is_array($field_value)) { $field_value = implode(",", $field_value); } break; case 'post_object': if (!empty($field_options['multiple'])) { $v = array(); foreach ($field_value as $key => $pid) { if (is_numeric($pid)) { $entry = get_post($pid); if ($entry) { $v[] = $entry->post_name; } } else { $v[] = $pid->post_name; } } $field_value = implode(",", $v); } else { if (is_numeric($field_value)) { $entry = get_post($field_value); if ($entry) { $field_value = $entry->post_name; } } else { $field_value = $field_value->post_name; } } break; case 'relationship': $v = array(); foreach ($field_value as $key => $pid) { $entry = get_post($pid); if ($entry) { $v[] = $entry->post_title; } } $field_value = implode(",", $v); break; case 'user': if (!empty($field_options['multiple'])) { $v = array(); foreach ($field_value as $key => $user) { if (is_numeric($user)) { $entry = get_user_by('ID', $user); if ($entry) { $v[] = $entry->user_email; } } else { $v[] = $user['user_email']; } } $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(); } } }
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; }
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>'; }
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; }
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; }
public static function export_acf_field($field_value = '', $exportOptions, $ID, $pid, &$article, $xmlWriter = false, &$acfs, $element_name = '', $element_name_ns = '', $fieldSnipped = '', $group_id = '', $preview = false, $return_value = false) { global $acf; $put_to_csv = true; $field_name = $ID ? $exportOptions['cc_label'][$ID] : $exportOptions['name']; $field_options = $ID ? unserialize($exportOptions['cc_options'][$ID]) : $exportOptions; $field_settings = $ID ? json_decode($exportOptions['cc_settings'][$ID], true) : false; $is_xml_export = $xmlWriter and XmlExportEngine::$exportOptions['export_to'] == 'xml'; if (!empty($field_value)) { $field_value = maybe_unserialize($field_value); $implode_delimiter = (isset($exportOptions['delimiter']) and $exportOptions['delimiter'] == ',') ? '|' : ','; switch ($field_options['type']) { case 'date_time_picker': case 'date_picker': $field_value = date('Ymd', strtotime($field_value)); break; case 'file': case 'image': if (is_numeric($field_value)) { $field_value = wp_get_attachment_url($field_value); } elseif (is_array($field_value)) { $field_value = $field_value['url']; } break; case 'gallery': $v = array(); foreach ($field_value as $key => $item) { $v[] = $item['url']; } $field_value = implode($implode_delimiter, $v); break; case 'location-field': $localion_parts = explode("|", $field_value); if ($is_xml_export) { if (!empty($localion_parts)) { $xmlWriter->beginElement($element_name_ns, $element_name, null); $xmlWriter->startElement('address'); $xmlWriter->writeData($localion_parts[0]); $xmlWriter->endElement(); if (!empty($localion_parts[1])) { $coordinates = explode(",", $localion_parts[1]); if (!empty($coordinates)) { $xmlWriter->startElement('lat'); $xmlWriter->writeData($coordinates[0]); $xmlWriter->endElement(); $xmlWriter->startElement('lng'); $xmlWriter->writeData($coordinates[1]); $xmlWriter->endElement(); } } $xmlWriter->endElement(); } } else { if (!$return_value) { $acfs[$element_name] = array($element_name . '_address', $element_name . '_lat', $element_name . '_lng'); if (!empty($localion_parts)) { $article[$element_name . '_address'] = $localion_parts[0]; if (!empty($localion_parts[1])) { $coordinates = explode(",", $localion_parts[1]); if (!empty($coordinates)) { $article[$element_name . '_lat'] = $coordinates[0]; $article[$element_name . '_lng'] = $coordinates[1]; } } } } else { if (!empty($localion_parts)) { $return_value = array('address' => $localion_parts[0]); if (!empty($localion_parts[1])) { $coordinates = explode(",", $localion_parts[1]); if (!empty($coordinates)) { $return_value['lat'] = $coordinates[0]; $return_value['lng'] = $coordinates[1]; } } } } } $put_to_csv = false; break; case 'paypal_item': if ($is_xml_export) { $xmlWriter->beginElement($element_name_ns, $element_name, null); if (is_array($field_value)) { foreach ($field_value as $key => $value) { $xmlWriter->beginElement($element_name_ns, $key, null); $xmlWriter->writeData($value); $xmlWriter->endElement(); } } $xmlWriter->endElement(); } else { if (!$return_value) { $acfs[$element_name] = array($element_name . '_item_name', $element_name . '_item_description', $element_name . '_price'); if (is_array($field_value)) { foreach ($field_value as $key => $value) { $article[$element_name . '_' . $key] = $value; } } } } $put_to_csv = false; break; case 'google_map': if ($is_xml_export) { $xmlWriter->beginElement($element_name_ns, $element_name, null); $xmlWriter->startElement('address'); $xmlWriter->writeData($field_value['address']); $xmlWriter->endElement(); $xmlWriter->startElement('lat'); $xmlWriter->writeData($field_value['lat']); $xmlWriter->endElement(); $xmlWriter->startElement('lng'); $xmlWriter->writeData($field_value['lng']); $xmlWriter->endElement(); $xmlWriter->endElement(); } else { if (!$return_value) { $acfs[$element_name] = array($element_name . '_address', $element_name . '_lat', $element_name . '_lng'); $article[$element_name . '_address'] = $field_value['address']; $article[$element_name . '_lat'] = $field_value['lat']; $article[$element_name . '_lng'] = $field_value['lng']; } } $put_to_csv = false; break; case 'acf_cf7': case 'gravity_forms_field': if (!empty($field_options['multiple'])) { $field_value = implode($implode_delimiter, $field_value); } break; case 'page_link': if (is_array($field_value)) { $field_value = implode($implode_delimiter, $field_value); } break; case 'post_object': if (!empty($field_options['multiple'])) { $v = array(); foreach ($field_value as $key => $pid) { if (is_numeric($pid)) { $entry = get_post($pid); if ($entry) { $v[] = $entry->post_name; } } else { $v[] = $pid->post_name; } } $field_value = implode($implode_delimiter, $v); } else { if (is_numeric($field_value)) { $entry = get_post($field_value); if ($entry) { $field_value = $entry->post_name; } } else { $field_value = $field_value->post_name; } } break; case 'relationship': $v = array(); foreach ($field_value as $key => $pid) { $entry = get_post($pid); if ($entry) { $v[] = $entry->post_title; } } $field_value = implode($implode_delimiter, $v); break; case 'user': if (!empty($field_options['multiple'])) { $v = array(); foreach ($field_value as $key => $user) { if (is_numeric($user)) { $entry = get_user_by('ID', $user); if ($entry) { $v[] = $entry->user_email; } } else { $v[] = $user['user_email']; } } $field_value = implode($implode_delimiter, $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': if ($is_xml_export) { $xmlWriter->beginElement($element_name_ns, $element_name, null); 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->writeData($entry->name); $xmlWriter->endElement(); } } } else { $entry = get_term($field_value, $field_options['taxonomy']); if ($entry) { $xmlWriter->startElement('term'); $xmlWriter->writeData($entry->name); $xmlWriter->endElement(); } } $xmlWriter->endElement(); $put_to_csv = false; } else { if (!in_array($field_options['field_type'], array('radio', 'select'))) { $v = array(); foreach ($field_value as $key => $tid) { $entry = get_term($tid, $field_options['taxonomy']); if ($entry and !is_wp_error($entry)) { $v[] = $entry->name; } } $field_value = implode($implode_delimiter, $v); } else { $entry = get_term($field_value, $field_options['taxonomy']); 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) { $additional_articles = array(); foreach ($rowValues as $key => $values) { $is_have_subvalues = array_filter(array_keys($values), 'is_numeric'); if (empty($is_have_subvalues)) { foreach ($values as $subkey => $subvalue) { if (!in_array($element_name . '_' . $key . '_' . $subkey, $repeater_sub_field_names)) { $repeater_sub_field_names[] = $element_name . '_' . $key . '_' . $subkey; } // Display each repeater row in its own csv line if (!empty($field_settings) and $field_settings['repeater_field_item_per_line']) { $base_value = array_shift($subvalue); $article[$element_name . '_' . $key . '_' . $subkey] = $preview ? trim(preg_replace('~[\\r\\n]+~', ' ', htmlspecialchars($base_value))) : $base_value; if (!empty($subvalue)) { foreach ($subvalue as $i => $addRowValue) { $additional_articles[$i]['settings'] = $field_settings; $additional_articles[$i]['content'][$element_name . '_' . $key . '_' . $subkey] = $addRowValue; } } } else { $article[$element_name . '_' . $key . '_' . $subkey] = $preview ? trim(preg_replace('~[\\r\\n]+~', ' ', htmlspecialchars(implode($implode_delimiter, $subvalue)))) : implode($implode_delimiter, $subvalue); } } } else { if (!in_array($element_name . '_' . $key, $repeater_sub_field_names)) { $repeater_sub_field_names[] = $element_name . '_' . $key; } // Display each repeater row in its own csv line if (!empty($field_settings) and $field_settings['repeater_field_item_per_line']) { $base_value = array_shift($values); $article[$element_name . '_' . $key] = $preview ? trim(preg_replace('~[\\r\\n]+~', ' ', htmlspecialchars($base_value))) : $base_value; if (!empty($values)) { foreach ($values as $i => $addRowValue) { $additional_articles[$i]['settings'] = $field_settings; $additional_articles[$i]['content'][$element_name . '_' . $key] = $addRowValue; } } } else { $article[$element_name . '_' . $key] = $preview ? trim(preg_replace('~[\\r\\n]+~', ' ', htmlspecialchars(implode($implode_delimiter, $values)))) : implode($implode_delimiter, $values); } } } if (!empty($repeater_sub_field_names)) { $acfs[$element_name] = $repeater_sub_field_names; } if (!empty($additional_articles)) { foreach ($additional_articles as $i => $additional_article) { self::$additional_articles[] = $additional_article; } } } } if ($is_xml_export) { $xmlWriter->endElement(); } $put_to_csv = false; break; case 'flexible_content': $fc_sub_field_names = array(); if ($is_xml_export) { $xmlWriter->beginElement($element_name_ns, $element_name, null); } // 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 = self::acf_get_row(); foreach ($row['field']['layouts'] as $layout) { if ($layout['name'] == $row['value'][$row['i']]['acf_fc_layout']) { if ($is_xml_export) { $xmlWriter->startElement($row['value'][$row['i']]['acf_fc_layout'] . '_' . $row['i']); } foreach ($layout['sub_fields'] as $sub_field) { $layout_field_name = $element_name . '_' . $layout['name'] . '_' . $row['i']; $v = ''; if (isset($row['value'][$row['i']][$sub_field['key']])) { $v = $row['value'][$row['i']][$sub_field['key']]; if ($is_xml_export) { $v = acf_format_value($v, $row['post_id'], $sub_field); } } $sub_field['delimiter'] = $implode_delimiter; $sub_field_values = self::export_acf_field($v, $sub_field, false, $pid, $article, $xmlWriter, $acfs, $is_xml_export ? $sub_field['name'] : $layout_field_name . '_' . $sub_field['name'], $element_name_ns, $fieldSnipped, '', $preview, $is_xml_export ? false : true); if (!$is_xml_export) { switch ($sub_field['type']) { case 'repeater': if (!empty($sub_field_values)) { foreach ($sub_field_values as $key => $values) { $article[$layout_field_name . '_' . $key] = $preview ? trim(preg_replace('~[\\r\\n]+~', ' ', htmlspecialchars(implode($implode_delimiter, $values)))) : implode($implode_delimiter, $values); if (!in_array($layout_field_name . '_' . $key, $fc_sub_field_names)) { $fc_sub_field_names[] = $layout_field_name . '_' . $key; } } } break; default: $article[$layout_field_name . '_' . $sub_field['name']] = $v; if (!in_array($layout_field_name . '_' . $sub_field['name'], $fc_sub_field_names)) { $fc_sub_field_names[] = $layout_field_name . '_' . $sub_field['name']; } break; } } } if ($is_xml_export) { $xmlWriter->endElement(); } } } } } else { // no layouts found } if ($is_xml_export) { $xmlWriter->endElement(); } if (!empty($fc_sub_field_names)) { $acfs[$element_name] = $fc_sub_field_names; } $put_to_csv = false; break; default: break; } } if ($return_value) { return $field_value; } if ($put_to_csv) { $val = apply_filters('pmxe_acf_field', pmxe_filter(!empty($field_value) ? maybe_serialize($field_value) : '', $fieldSnipped), $field_name, $pid); if ($is_xml_export) { $xmlWriter->beginElement($element_name_ns, $element_name, null); $xmlWriter->writeData($val); $xmlWriter->endElement(); } else { // $article[$element_name] = ($preview) ? trim(preg_replace('~[\r\n]+~', ' ', htmlspecialchars($val))) : $val; wp_all_export_write_article($article, $element_name, $preview ? trim(preg_replace('~[\\r\\n]+~', ' ', htmlspecialchars($val))) : $val); if (!isset($acfs[$element_name])) { $acfs[$element_name] = $element_name; } } } }