本文整理汇总了PHP中acf_get_fields函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_get_fields函数的具体用法?PHP acf_get_fields怎么用?PHP acf_get_fields使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_get_fields函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_field_group
function update_field_group($field_group)
{
// vars
$path = acf_get_setting('save_json');
$file = $field_group['key'] . '.json';
// remove trailing slash
$path = untrailingslashit($path);
// bail early if dir does not exist
if (!is_writable($path)) {
//error_log( 'ACF failed to save field group to .json file. Path does not exist: ' . $path );
return;
}
// load fields
$fields = acf_get_fields($field_group);
// prepare fields
$fields = acf_prepare_fields_for_export($fields);
// add to field group
$field_group['fields'] = $fields;
// extract field group ID
$id = acf_extract_var($field_group, 'ID');
// write file
$f = fopen("{$path}/{$file}", 'w');
fwrite($f, acf_json_encode($field_group));
fclose($f);
}
示例2: vc_gitem_template_attribute_acf
/**
* Get ACF data
*
* @param $value
* @param $data
*
* @return string
*/
function vc_gitem_template_attribute_acf($value, $data)
{
$label = '';
/**
* @var null|Wp_Post $post ;
* @var string $data ;
*/
extract(array_merge(array('post' => null, 'data' => ''), $data));
if (strstr($data, 'field_from_group_')) {
$group_id = preg_replace('/(^field_from_group_|_labeled$)/', '', $data);
$fields = function_exists('acf_get_fields') ? acf_get_fields($group_id) : apply_filters('acf/field_group/get_fields', array(), $group_id);
$field = is_array($fields) && isset($fields[0]) ? $fields[0] : false;
if (is_array($field) && isset($field['key'])) {
$data = $field['key'] . (strstr($data, '_labeled') ? '_labeled' : '');
}
}
$label = '';
if (preg_match('/_labeled$/', $data)) {
$data = preg_replace('/_labeled$/', '', $data);
$field = get_field_object($data);
$label = is_array($field) && isset($field['label']) ? '<span class="vc_gitem-acf-label">' . $field['label'] . ':</span> ' : '';
}
$value = '';
if ($data) {
$value = do_shortcode('[acf field="' . $data . '" post_id="' . $post->ID . '"]');
}
return $label . apply_filters('vc_gitem_template_attribute_acf_value', $value);
}
示例3: get_visible_acf_fields
/**
* Get the visible ACF fields.
* @return array
*/
public function get_visible_acf_fields($widget_id = null)
{
global $wp_registered_widgets;
$visible_fields = array();
// build field group filters required for current screen
$filter = $this->get_acf_field_group_filters();
if (count($filter) === 0) {
return $visible_fields;
}
// widgets need some special handling since they
// require multiple acf_get_field_group_visibility()
// calls in order to return all the visible fields
if (acf_is_screen('widgets') || acf_is_screen('customize')) {
if ($widget_id) {
$filter['widget'] = _get_widget_id_base($widget_id);
} else {
// process each widget form individually for any visible fields
foreach ($wp_registered_widgets as $widget) {
$visible_fields += $this->get_visible_acf_fields($widget['id']);
}
return $visible_fields;
}
}
$supported_field_types = array('email', 'text', 'textarea', 'repeater', 'flexible_content', 'qtranslate_file', 'qtranslate_image', 'qtranslate_text', 'qtranslate_textarea', 'qtranslate_wysiwyg');
foreach (acf_get_field_groups($filter) as $field_group) {
$fields = acf_get_fields($field_group);
foreach ($fields as $field) {
if (in_array($field['type'], $supported_field_types)) {
$visible_fields[] = array('id' => 'acf-' . $field['key']);
}
}
}
return $visible_fields;
}
示例4: vc_gitem_template_attribute_acf
/**
* Get ACF data
*
* @param $value
* @param $data
*
* @return string
*/
function vc_gitem_template_attribute_acf($value, $data)
{
$label = '';
/**
* @var null|Wp_Post $post ;
* @var string $data ;
*/
extract(array_merge(array('post' => null, 'data' => ''), $data));
if (strstr($data, 'field_from_group_')) {
$group_id = preg_replace('/(^field_from_group_|_labeled$)/', '', $data);
$fields = function_exists('acf_get_fields') ? acf_get_fields($group_id) : apply_filters('acf/field_group/get_fields', array(), $group_id);
$field = is_array($fields) && isset($fields[0]) ? $fields[0] : false;
if (is_array($field) && isset($field['key'])) {
$data = $field['key'] . (strstr($data, '_labeled') ? str_replace($data, '', '_labeled') : '');
}
}
if (preg_match('/_labeled$/', $data)) {
$data = preg_replace('/_labeled$/', '', $data);
$field = apply_filters('acf/load_field', array(), $data);
$label = is_array($field) ? '<span class="vc_gite-acf-label">' . $field['label'] . ':</span> ' : '';
}
if (get_field($data)) {
$value = apply_filters('vc_gitem_template_attribute_acf_value', get_field($data, $post->ID));
}
return strlen($value) > 0 ? $label . $value : '';
}
示例5: load_field
function load_field($field)
{
// bail early if no field layouts
if (empty($field['layouts'])) {
return $field;
}
// vars
$sub_fields = acf_get_fields($field);
// loop through layouts, sub fields and swap out the field key with the real field
foreach (array_keys($field['layouts']) as $i) {
// extract layout
$layout = acf_extract_var($field['layouts'], $i);
// validate layout
$layout = $this->get_valid_layout($layout);
// append sub fields
if (!empty($sub_fields)) {
foreach (array_keys($sub_fields) as $k) {
// check if 'parent_layout' is empty
if (empty($sub_fields[$k]['parent_layout'])) {
// parent_layout did not save for this field, default it to first layout
$sub_fields[$k]['parent_layout'] = $layout['key'];
}
// append sub field to layout,
if ($sub_fields[$k]['parent_layout'] == $layout['key']) {
$layout['sub_fields'][] = acf_extract_var($sub_fields, $k);
}
}
}
// append back to layouts
$field['layouts'][$i] = $layout;
}
// return
return $field;
}
示例6: getCustomFieldDefinitions
/**
* @return array multidimensional list of custom fields definitions
*/
public function getCustomFieldDefinitions()
{
$fieldGroups = acf_get_field_groups();
$customFields = array();
foreach ($fieldGroups as $fieldGroup) {
$fields = acf_get_fields($fieldGroup);
$customFields[] = array('id' => $fieldGroup['key'], 'label' => $fieldGroup['title'], 'type' => 'group', 'field_definitions' => $this->getFieldDefinitions($fields));
}
return $customFields;
}
示例7: load_field
function load_field($field)
{
// vars
$sub_fields = acf_get_fields($field);
// append
if ($sub_fields) {
$field['sub_fields'] = $sub_fields;
}
// return
return $field;
}
示例8: update_field_group
function update_field_group($field_group)
{
// validate
if (!acf_get_setting('json')) {
return;
}
// get fields
$field_group['fields'] = acf_get_fields($field_group);
// save file
acf_write_json_field_group($field_group);
}
示例9: widget
function widget($args, $instance)
{
$instance = (object) $instance;
foreach (acf_get_field_groups(array('widget' => $this->identifier)) as $field_group) {
foreach (acf_get_fields($field_group) as $field) {
$name = $field['name'];
$instance->{$name} = get_field($name, "widget_{$this->id}");
}
}
if (!empty($this->has_title)) {
$instance->title = apply_filters('widget_title', empty($instance->title) ? '' : $instance->title, $instance, $this->id_base);
}
$this->render_widget($instance, $args);
}
示例10: load_field
function load_field($field)
{
// min/max
$field['min'] = (int) $field['min'];
$field['max'] = (int) $field['max'];
// vars
$sub_fields = acf_get_fields($field);
// append
if ($sub_fields) {
$field['sub_fields'] = $sub_fields;
}
// return
return $field;
}
示例11: acf_pull
/**
* Import (overwrite) field groups into DB
* @param string $params['name']
* @param string $params['group']
* @param string $params['old_value'] The previous settings data
* @param string $params['new_value'] The new settings data
*/
function acf_pull($params)
{
$field_group = $params['new_value'];
if ($existing_group = acf_get_field_group($field_group['key'])) {
$field_group['ID'] = $existing_group['ID'];
$existing_fields = acf_get_fields($existing_group);
// Remove fields
foreach ($existing_fields as $field) {
wp_delete_post($field['ID'], true);
}
}
// extract fields
$fields = acf_extract_var($field_group, 'fields');
// format fields
$fields = acf_prepare_fields_for_import($fields);
// save field group
$field_group = acf_update_field_group($field_group);
// add to ref
$ref[$field_group['key']] = $field_group['ID'];
// add to order
$order[$field_group['ID']] = 0;
// add fields
foreach ($fields as $index => $field) {
// add parent
if (empty($field['parent'])) {
$field['parent'] = $field_group['ID'];
} else {
if (isset($ref[$field['parent']])) {
$field['parent'] = $ref[$field['parent']];
}
}
// add field menu_order
if (!isset($order[$field['parent']])) {
$order[$field['parent']] = 0;
}
$field['menu_order'] = $order[$field['parent']];
$order[$field['parent']]++;
// save field
$field = acf_update_field($field);
// add to ref
$ref[$field['key']] = $field['ID'];
}
}
示例12: display_settings
public function display_settings()
{
$groups = acf_get_field_groups(false);
$options = array();
foreach ($groups as $group_id => $group) {
$fields = acf_get_fields($group);
foreach ($fields as $field) {
if (in_array($field['type'], array('tab'))) {
continue;
}
if ('image_crop' == $field['type']) {
$options[$field['key']] = $field['label'];
}
}
}
if ($options) {
$this->display_field_select('cropper_field', 'Field', $options, '');
}
}
示例13: get_json
static function get_json()
{
if (!function_exists('acf_get_field_group')) {
echo 'You need ACF activated to use this screen';
exit;
}
$keys = isset($_GET['generate-template-id']) ? array($_GET['generate-template-id']) : array();
//print_r($keys);
//exit;
//$keys = $_GET['acf_export_keys'];
//$keys = array('group_55e23ad63ecc3');
//$keys = array('group_55d38b033048e');
//$keys = array('group_55d26a506a990');
// validate
if (empty($keys)) {
return false;
}
// vars
$json = array();
// construct JSON
foreach ($keys as $key) {
// load field group
$field_group = acf_get_field_group($key);
// validate field group
if (empty($field_group)) {
continue;
}
// load fields
$field_group['fields'] = acf_get_fields($field_group);
// prepare fields
$field_group['fields'] = acf_prepare_fields_for_export($field_group['fields']);
// extract field group ID
$id = acf_extract_var($field_group, 'ID');
// add to json array
$json[] = $field_group;
}
// return
return $json;
}
示例14: load_field
public function load_field($field)
{
global $wp_widget_factory;
$widget = isset($field['value']) && isset($field['value']['the_widget']) ? $field['value']['the_widget'] : $field['widget'];
// This is a chance for plugins to replace missing widgets
$the_widget = !empty($wp_widget_factory->widgets[$widget]) ? $wp_widget_factory->widgets[$widget] : false;
if (empty($the_widget)) {
return $field;
}
// get any ACF field groups attached to the widget.
$field_groups = acf_get_field_groups(array('widget' => $the_widget->id_base));
$field['sub_fields'] = array();
if (!empty($field_groups)) {
foreach ($field_groups as $group) {
$these_subfields = acf_get_fields($group);
foreach ($these_subfields as $the_subfield) {
$field['sub_fields'][] = $the_subfield;
}
}
}
return $field;
}
示例15: load_field
function load_field($field)
{
$field['sub_fields'] = acf_get_fields($field);
// return
return $field;
}