当前位置: 首页>>代码示例>>PHP>>正文


PHP acf_get_local_fields函数代码示例

本文整理汇总了PHP中acf_get_local_fields函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_get_local_fields函数的具体用法?PHP acf_get_local_fields怎么用?PHP acf_get_local_fields使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了acf_get_local_fields函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: check_sync

 function check_sync()
 {
     // message
     if ($ids = acf_maybe_get($_GET, 'acfsynccomplete')) {
         // explode
         $ids = explode(',', $ids);
         $total = count($ids);
         if ($total == 1) {
             acf_add_admin_notice(sprintf(__('Field group synchronised. %s', 'acf'), '<a href="' . get_edit_post_link($ids[0]) . '">' . get_the_title($ids[0]) . '</a>'));
         } else {
             acf_add_admin_notice(sprintf(_n('%s field group synchronised.', '%s field groups synchronised.', $total, 'acf'), $total));
         }
     }
     // vars
     $groups = acf_get_field_groups();
     // bail early if no field groups
     if (empty($groups)) {
         return;
     }
     // find JSON field groups which have not yet been imported
     foreach ($groups as $group) {
         // vars
         $local = acf_maybe_get($group, 'local', false);
         $modified = acf_maybe_get($group, 'modified', 0);
         $private = acf_maybe_get($group, 'private', false);
         // ignore DB / PHP / private field groups
         if ($local !== 'json' || $private) {
             // do nothing
         } elseif (!$group['ID']) {
             $this->sync[$group['key']] = $group;
         } elseif ($modified && $modified > get_post_modified_time('U', true, $group['ID'], true)) {
             $this->sync[$group['key']] = $group;
         }
     }
     // bail if no sync needed
     if (empty($this->sync)) {
         return;
     }
     // import field group
     if ($key = acf_maybe_get($_GET, 'acfsync')) {
         // disable JSON
         // - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance
         acf_update_setting('json', false);
         // validate
         check_admin_referer('bulk-posts');
         // append fields
         if (acf_have_local_fields($key)) {
             $this->sync[$key]['fields'] = acf_get_local_fields($key);
         }
         // import
         $field_group = acf_import_field_group($this->sync[$key]);
         // redirect
         wp_redirect(admin_url($this->url . '&acfsynccomplete=' . $field_group['ID']));
         exit;
     } elseif (acf_maybe_get($_GET, 'action2') === 'acfsync') {
         // validate
         check_admin_referer('bulk-posts');
         // get ids
         $keys = acf_maybe_get($_GET, 'post');
         if (!empty($keys)) {
             // disable JSON
             // - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance
             acf_update_setting('json', false);
             // vars
             $new_ids = array();
             foreach ($keys as $key) {
                 // append fields
                 if (acf_have_local_fields($key)) {
                     $this->sync[$key]['fields'] = acf_get_local_fields($key);
                 }
                 // import
                 $field_group = acf_import_field_group($this->sync[$key]);
                 // append
                 $new_ids[] = $field_group['ID'];
             }
             // redirect
             wp_redirect(admin_url($this->url . '&acfsynccomplete=' . implode(',', $new_ids)));
             exit;
         }
     }
     // filters
     add_filter('views_edit-acf-field-group', array($this, 'list_table_views'));
 }
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:83,代码来源:field-groups.php

示例2: acf_get_fields

function acf_get_fields($parent = false)
{
    // allow $parent to be a field group ID
    if (!is_array($parent)) {
        $parent = acf_get_field_group($parent);
    }
    // bail early if no parent
    if (!$parent) {
        return false;
    }
    // vars
    $fields = array();
    // try JSON before DB to save query time
    if (acf_have_local_fields($parent['key'])) {
        $fields = acf_get_local_fields($parent['key']);
    } else {
        $fields = acf_get_fields_by_id($parent['ID']);
    }
    // filter
    $fields = apply_filters('acf/get_fields', $fields, $parent);
    // return
    return $fields;
}
开发者ID:coreymargulis,项目名称:karenmargulis,代码行数:23,代码来源:api-field.php

示例3: import

 function import()
 {
     // validate
     if (empty($_FILES['acf_import_file'])) {
         acf_add_admin_notice(__("No file selected", 'acf'), 'error');
         return;
     }
     // vars
     $file = $_FILES['acf_import_file'];
     // validate error
     if ($file['error']) {
         acf_add_admin_notice(__('Error uploading file. Please try again', 'acf'), 'error');
         return;
     }
     // validate type
     if (pathinfo($file['name'], PATHINFO_EXTENSION) !== 'json') {
         acf_add_admin_notice(__('Incorrect file type', 'acf'), 'error');
         return;
     }
     // read file
     $json = file_get_contents($file['tmp_name']);
     // decode json
     $json = json_decode($json, true);
     // validate json
     if (empty($json)) {
         acf_add_admin_notice(__('Import file empty', 'acf'), 'error');
         return;
     }
     // if importing an auto-json, wrap field group in array
     if (isset($json['key'])) {
         $json = array($json);
     }
     // vars
     $ids = array();
     $keys = array();
     $imported = array();
     // populate keys
     foreach ($json as $field_group) {
         // append key
         $keys[] = $field_group['key'];
     }
     // look for existing ids
     foreach ($keys as $key) {
         // attempt find ID
         $field_group = _acf_get_field_group_by_key($key);
         // bail early if no field group
         if (!$field_group) {
             continue;
         }
         // append
         $ids[$key] = $field_group['ID'];
     }
     // enable local
     acf_enable_local();
     // reset local (JSON class has already included .json field groups which may conflict)
     acf_reset_local();
     // add local field groups
     foreach ($json as $field_group) {
         // add field group
         acf_add_local_field_group($field_group);
     }
     // loop over keys
     foreach ($keys as $key) {
         // vars
         $field_group = acf_get_local_field_group($key);
         // attempt get id
         $id = acf_maybe_get($ids, $key);
         if ($id) {
             $field_group['ID'] = $id;
         }
         // append fields
         if (acf_have_local_fields($key)) {
             $field_group['fields'] = acf_get_local_fields($key);
         }
         // import
         $field_group = acf_import_field_group($field_group);
         // append message
         $imported[] = array('ID' => $field_group['ID'], 'title' => $field_group['title'], 'updated' => $id ? 1 : 0);
     }
     // messages
     if (!empty($imported)) {
         // vars
         $links = array();
         $count = count($imported);
         $message = sprintf(_n('Imported 1 field group', 'Imported %s field groups', $count, 'acf'), $count) . '.';
         // populate links
         foreach ($imported as $import) {
             $links[] = '<a href="' . admin_url("post.php?post={$import['ID']}&action=edit") . '" target="_blank">' . $import['title'] . '</a>';
         }
         // append links
         $message .= ' ' . implode(', ', $links);
         // add notice
         acf_add_admin_notice($message);
     }
 }
开发者ID:Garth619,项目名称:Femi9,代码行数:95,代码来源:settings-tools.php


注:本文中的acf_get_local_fields函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。