fryiee/acf-helper
Composer 安装命令:
composer require fryiee/acf-helper
包简介
A composer package for programmatically adding ACF fields to your Wordpress site.
关键字:
README 文档
README
A composer package for programmatically adding ACF fields to your Wordpress site.
Why use this package?
Elliott Condon's Advanced Custom Fields is an amazing plugin for enhancing the content on a Wordpress site. However, programmatically adding fields is a cumbersome process, requiring writing multiple nested arrays, or creating the field group first in the plugin itself then exporting the code (with the end result still being a huge web of arrays).
This package aims to reduce the amount of field boilerplate diluting your theme's code by simplifying the process of registering field groups and fields programmatically.
Requirements
- Composer
- Advanced Custom Fields Wordpress plugin
- Advanced Custom Fields Pro or the Field Type addon plugins if you plan to use premium field types.
Installation
You can use Composer to add the package to your project by using composer require fryiee/acf-repeater:0.1.* or
adding fryiee/acf-repeater:0.1.* directly to the composer.json.
Add the package to your functions.php or similar theme file (such as a TimberSite class file) by adding
use Fryiee\ACF\Helper as ACFHelper to the top of the file.
Basic Example
$fieldGroup = ACFHelper::createFieldGroup('Example Field Group', '_a_suffix_to_the_group_key');
$fieldGroup->addLocation('post_type', '==', 'post');
$field = ACFHelper::createField('text', 'Example Field', ['required' => 1], '_a_suffix_to_the_field_key');
$fieldGroup->addField($field);
ACFHelper::enqueue($fieldGroup);
Classes & Methods
Helper
The \Fryiee\ACF\Helper package is the main entry point of the Helper package. This is where you will generate all your
field groups and fields, as well as enqueue them.
Helper::createFieldGroup($title, $keySuffix = '', $args = []);
This static method creates an instance of \Fryiee\ACF\FieldGroup. It takes the title of the Field Group as an
argument, optionally a key suffix, and optionally additional arguments. By default, the helper class will set the field
group's key to group_slugified_title, with the key suffix being added if it is not empty.
The $args argument takes any of the existing arguments for fields. See here:
https://www.advancedcustomfields.com/resources/register-fields-via-php/
REMINDER: Changing your field group's title or key suffix will mean that existing data is no longer connected unless it is altered in the database.
Helper::createField($type, $label, $args, $keySuffix = '')
This static method creates an instance of \Fryiee\ACF\Field. It takes the type of the field, the label, any
additional arguments as an array, and optionally a key suffix. By default, the helper class will set the field's name
to the slug of the label, and set the key to field_slugified_label, with the key suffix being added if it is not
empty. This can be overrided by providing a 'name' attribute in the $args array.
TBA List of field type slugs.
REMINDER: Changing your field's label or key suffix will mean that existing data is no longer connected unless it is altered in the database.
The $args argument takes any of the existing arguments for fields. See here:
https://www.advancedcustomfields.com/resources/register-fields-via-php/
TBA List of arguments for each field type.
Helper::enqueue($fieldGroup)
This static method enqueues the field group using ACF's built in register_field_group() function for compatibility
with both ACF and ACF PRO. It takes an instance of \Fryiee\ACF\FieldGroup as an argument.
FieldGroup
$fieldGroup->addLocation($param, $operator, $value)
This method adds a location parameter to the field group.
TBA Add support for multiple locations
$fieldGroup->addField($field)
This method adds a field to the field group. It takes an instance of \Fryiee\ACF\Field as an argument.
$fieldGroup->generate()
TBA
Field
$field->generate()
TBA
fryiee/acf-helper 适用场景与选型建议
fryiee/acf-helper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.99k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 07 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「wordpress」 「acf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fryiee/acf-helper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fryiee/acf-helper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fryiee/acf-helper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple set of helper functions for ACF Fluent auto-loaded with Composer using generic function names.
Drag and drop file upload for ACF-Fields.
Register advanced custom fields with object oriented PHP
Post type selector for Advanced Custom Fields.
A Gutenberg like color palette field for ACF.
An install helper for Advanced Custom Fields PRO
统计信息
- 总下载量: 2.99k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-04