此包已被放弃,不再维护。作者建议使用 vinkla/extended-acf 包。

使用面向对象的PHP注册高级自定义字段

14.2.1 2024-09-12 09:00 UTC

README

Extended ACF

扩展ACF

使用面向对象的PHP注册高级自定义字段。

扩展ACF提供面向对象的API来注册ACF中的组和字段。如果您在主题中注册字段,可以在与其他开发者合作时安全地依赖版本控制。哦,您不必担心唯一的字段键。

Build Status Monthly Downloads Latest Version

安装

使用Composer在项目的根目录中安装此包。

composer require vinkla/extended-acf

要安装 Advanced Custom Fields Pro 插件,请下载并将其放置在 pluginsmu-plugins 目录中。然后,在WordPress仪表板上激活插件。

了解更多关于使用Composer安装ACF PRO的信息。

用法

要注册新的字段组,请使用 register_extended_field_group() 函数。这扩展了ACF插件中的默认 register_field_group() 函数。将 key 值附加到字段组中。以下是一个字段组的示例。

use Extended\ACF\Fields\Image;
use Extended\ACF\Fields\Text;
use Extended\ACF\Location;

add_action('acf/init', function() {
    register_extended_field_group([
        'title' => 'About',
        'fields' => [
            Image::make('Image'),
            Text::make('Title'),
        ],
        'location' => [
            Location::where('post_type', 'page')
        ],
    ]);
});

设置

有关字段组设置的详细信息,请参阅 官方ACF文档。您还可以在示例目录中找到更多示例。

字段

除克隆字段外,所有字段都有相应的类。每个字段需要一个 label。如果没有指定 name,则将使用 label 作为 snake_case 中的 namename 只能包含字母数字字符和下划线。

use Extended\ACF\Fields\Text;

Text::make('Title', 'heading')
    ->helperText('Add the text value')
    ->required()

大多数字段都有 defaultrequiredwrapper 方法。基本字段还有 prependappendplaceholderreadOnlydisabled 方法。请参阅 非标准 部分中提到的非标准方法。

基本

电子邮件 - 电子邮件字段 创建一个简单的电子邮件输入框。

use Extended\ACF\Fields\Email;

Email::make('Email')
    ->helperText('Add the employees email address.')
    ->required()

数字 - 数字字段 创建一个简单的数字输入框。

use Extended\ACF\Fields\Number;

Number::make('Age')
    ->helperText('Add the employees age.')
    ->min(18)
    ->max(65)
    ->required()

密码 - 密码字段 创建一个简单的密码输入框。

use Extended\ACF\Fields\Password;

Password::make('Password')
    ->helperText('Add the employees secret pwned password.')
    ->required()

范围 - 范围字段 提供了一种交互式选择数值的方式。

use Extended\ACF\Fields\Range;

Range::make('Rate')
    ->helperText('Add the employees completion rate.')
    ->min(0)
    ->max(100)
    ->step(10)
    ->required()

文本字段 - 文本字段创建一个简单的文本输入。

use Extended\ACF\Fields\Text;

Text::make('Name')
    ->helperText('Add the employees name.')
    ->maxLength(100)
    ->required()

多行文本框 - 多行文本框字段创建一个简单的多行文本框。

use Extended\ACF\Fields\Textarea;

Textarea::make('Biography')
    ->helperText('Add the employees biography.')
    ->newLines('br') // br, wpautop
    ->maxLength(2000)
    ->rows(10)
    ->required()

网址 - 网址字段创建一个简单的网址输入。

use Extended\ACF\Fields\URL;

URL::make('Website')
    ->helperText('Add the employees website link.')
    ->required()

内容

文件 - 文件字段允许上传和选择文件。

use Extended\ACF\Fields\File;

File::make('Resturant Menu', 'menu')
    ->helperText('Add the menu **pdf** file.')
    ->acceptedFileTypes(['pdf'])
    ->library('all') // all, uploadedTo
    ->minSize('400 KB')
    ->maxSize(5) // MB if entered as int
    ->format('array') // id, url, array (default)
    ->required()

相册 - 相册字段提供了一种简单直观的界面来管理一系列图片。

use Extended\ACF\Fields\Gallery;

Gallery::make('Images')
    ->helperText('Add the gallery images.')
    ->acceptedFileTypes(['jpg', 'jpeg', 'png'])
    ->minHeight(500)
    ->maxHeight(1400)
    ->minWidth(1000)
    ->maxWidth(2000)
    ->minFiles(1)
    ->maxFiles(6)
    ->minSize('400 KB')
    ->maxSize(5) // MB if entered as int
    ->library('all') // all, uploadedTo
    ->format('array') // id, url, array (default)
    ->previewSize('medium') // thumbnail, medium, large
    ->prependFiles()
    ->required()

图片 - 图片字段允许上传和选择图片。

use Extended\ACF\Fields\Image;

Image::make('Background Image')
    ->helperText('Add an image in at least 12000x100px and only in the formats **jpg**, **jpeg** or **png**.')
    ->acceptedFileTypes(['jpg', 'jpeg', 'png'])
    ->minHeight(500)
    ->maxHeight(1400)
    ->minWidth(1000)
    ->maxWidth(2000)
    ->minSize('400 KB')
    ->maxSize(5) // MB if entered as int
    ->library('all') // all, uploadedTo
    ->format('array') // id, url, array (default)
    ->previewSize('medium') // thumbnail, medium, large
    ->required()

oEmbed - oEmbed字段允许轻松嵌入视频、图片、推文、音频和其他内容。

use Extended\ACF\Fields\Oembed;

Oembed::make('Tweet')
    ->helperText('Add a tweet from Twitter.')
    ->required()

所见即所得 - 所见即所得字段创建一个完整的WordPress tinyMCE内容编辑器。

use Extended\ACF\Fields\WYSIWYGEditor;

WYSIWYGEditor::make('Content')
    ->helperText('Add the text content.')
    ->tabs('visual') // all, text, visual (default)
    ->toolbar(['bold', 'italic', 'link']) // aligncenter, alignleft, alignright, blockquote, bold, bullist, charmap, forecolor, formatselect, fullscreen, hr, indent, italic, link, numlist, outdent, pastetext, redo, removeformat, spellchecker, strikethrough, underline, undo, wp_adv, wp_help, wp_more
    ->disableMediaUpload()
    ->lazyLoad()
    ->required()

选择

按钮组 - 按钮组字段创建一个单选按钮列表。

use Extended\ACF\Fields\ButtonGroup;

ButtonGroup::make('Color')
    ->helperText('Select the box shadow color.')
    ->choices(['Forest Green', 'Sky Blue']) // ['forest_green' => 'Forest Green', 'sky_blue' => 'Sky Blue']
    ->default('forest_green')
    ->format('value') // array, label, value (default)
    ->required()

复选框 - 复选框字段创建一个可勾选的输入列表。

use Extended\ACF\Fields\Checkbox;

Checkbox::make('Color')
    ->helperText('Select the border color.')
    ->choices(['Forest Green', 'Sky Blue']) // ['forest_green' => 'Forest Green', 'sky_blue' => 'Sky Blue']
    ->default('forest_green')
    ->format('value') // array, label, value (default)
    ->layout('horizontal') // vertical, horizontal
    ->required()

单选按钮 - 单选按钮字段创建一个可选的输入列表。

use Extended\ACF\Fields\RadioButton;

RadioButton::make('Color')
    ->helperText('Select the text color.')
    ->choices(['Forest Green', 'Sky Blue']) // ['forest_green' => 'Forest Green', 'sky_blue' => 'Sky Blue']
    ->default('forest_green')
    ->format('value') // array, label, value (default)
    ->required()

下拉选择框 - 下拉选择框字段创建一个下拉选择或多个选择的输入。

use Extended\ACF\Fields\Select;

Select::make('Color')
    ->helperText('Select the background color.')
    ->choices(['Forest Green', 'Sky Blue']) // ['forest_green' => 'Forest Green', 'sky_blue' => 'Sky Blue']
    ->default('forest_green')
    ->format('value') // array, label, value (default)
    ->multiple()
    ->nullable()
    ->stylized() // stylized checkbox using select2
    ->lazyLoad() // use AJAX to lazy load choices
    ->required()

是/否 - 是/否字段允许您选择值为1或0的值。

use Extended\ACF\Fields\TrueFalse;

TrueFalse::make('Social Media', 'display_social_media')
    ->helperText('Select whether to display social media links or not.')
    ->default(false)
    ->stylized(on: 'Yes', off: 'No') // optional on and off text labels
    ->required()

关系

链接 - 链接字段提供了一种简单的方式来选择或定义链接(网址、标题、目标)。

use Extended\ACF\Fields\Link;

Link::make('Read More Link')
    ->format('array') // url, array (default)
    ->required()

页面链接 - 页面链接字段允许选择1个或多个帖子、页面或自定义帖子类型。

use Extended\ACF\Fields\PageLink;

PageLink::make('Contact Link')
    ->postTypes(['contact'])
    ->postStatus(['publish']) // draft, future, pending, private, publish
    ->taxonomies(['category:city'])
    ->disableArchives()
    ->nullabel()
    ->multiple()
    ->required()

帖子对象 - 帖子对象字段创建一个选择字段,其中选项包括您的页面 + 帖子 + 自定义帖子类型。

use Extended\ACF\Fields\PostObject;

PostObject::make('Animal')
    ->helperText('Select an animal')
    ->postTypes(['animal'])
    ->postStatus(['publish']) // draft, future, pending, private, publish
    ->nullabel()
    ->multiple()
    ->format('object') // id, object (default)
    ->required()

关系 - 关系字段创建了一个非常吸引人的帖子对象字段的版本。

use Extended\ACF\Fields\Relationship;

Relationship::make('Contacts')
    ->helperText('Add the contacts.')
    ->postTypes(['contact'])
    ->postStatus(['publish']) // draft, future, pending, private, publish
    ->filters([
        'search', 
        'post_type',
        'taxonomy'
    ])
    ->elements(['featured_image'])
    ->minPosts(3)
    ->maxPosts(6)
    ->format('object') // id, object (default)
    ->required()

分类法 - 分类法字段允许选择1个或多个分类术语。

use Extended\ACF\Fields\Taxonomy;

Taxonomy::make('Cinemas')
    ->helperText('Select one or more cinema terms.')
    ->taxonomy('cinema')
    ->appearance('checkbox') // checkbox, multi_select, radio, select
    ->format('id') // object, id (default)
    ->create(false) // false or true (default)
    ->load(true) // true or false (default)
    ->save(true) // true or false (default)x
    ->format('id'), // object or id (default)

用户 - 用户字段为您创建一个选择字段。

use Extended\ACF\Fields\User;

User::make('User')
    ->roles(['administrator', 'editor']) // administrator, author, contributor, editor, subscriber
    ->format('array'), // id, object, array (default)

高级

颜色选择器 - 颜色选择器字段允许通过JavaScript弹出窗口选择颜色。

use Extended\ACF\Fields\ColorPicker;

ColorPicker::make('Text Color')
    ->helperText('Add the text color.')
    ->default('#4a9cff')
    ->opacity()
    ->format('string') // array, string (default)
    ->required()

日期选择器 - 日期选择器字段创建一个jQuery日期选择弹出窗口。

use Extended\ACF\Fields\DatePicker;

DatePicker::make('Birthday')
    ->helperText('Add the employee\'s birthday.')
    ->displayFormat('d/m/Y')
    ->format('d/m/Y')
    ->required()

图标选择器 - 图标选择器字段允许您轻松选择Dashicon、媒体库图片或图像或SVG的网址。

use Extended\ACF\Fields\IconPicker;

IconPicker::make('Icon')
    ->helperText('Add the icon.')
    ->format('string') // array, string (default)
    ->tabs(['dashicons']) // [dashicons, media_library, url] (default)
    ->required()

时间选择器 - 时间选择器字段创建一个jQuery时间选择弹出窗口。

use Extended\ACF\Fields\TimePicker;

TimePicker::make('Start Time', 'time')
    ->helperText('Add the start time.')
    ->displayFormat('H:i')
    ->format('H:i')
    ->required()

日期时间选择器 - 日期时间选择器字段创建一个jQuery日期和时间选择弹出窗口。

use Extended\ACF\Fields\DateTimePicker;

DateTimePicker::make('Event Date', 'date')
    ->helperText('Add the event\'s start date and time.')
    ->displayFormat('d-m-Y H:i')
    ->format('d-m-Y H:i')
    ->firstDayOfWeek(1) // Sunday is 0, Monday is 1, or use `weekStartsOnMonday` or `weekStartsOnSunday`
    ->required()

Google 地图 - Google 地图字段 可创建一个交互式地图,并能够放置标记。

use Extended\ACF\Fields\GoogleMap;

GoogleMap::make('Address', 'address')
    ->helperText('Add the Google Map address.')
    ->center(57.456286, 18.377716)
    ->zoom(14)
    ->required()

布局

手风琴 - 手风琴字段 用于将字段组织到可折叠的面板中。

use Extended\ACF\Fields\Accordion;

Accordion::make('Address')
    ->open()
    ->multiExpand(),

// Allow accordion to remain open when other accordions are opened.
// Any field after this accordion will become a child.

Accordion::make('Endpoint')
    ->endpoint()
    ->multiExpand(),

// This field will not be visible, but will end the accordion above.
// Any fields added after this will not be a child to the accordion.

克隆 - 克隆字段 允许您选择和展示预存在的字段或组。此字段没有自定义字段类。相反,您可以为字段创建一个新文件,并在需要时使用 require 语句导入它。

// fields/email.php
use Extended\ACF\Fields\Email;

return Email::make('Email')->required();

// employee.php
register_extended_field_group([
    'fields' => [
        require __DIR__.'/fields/email.php';
    ]
]);

灵活内容 - 灵活内容字段 像一块空白画布,您可以在上面添加无限数量的布局,并完全控制顺序。

use Extended\ACF\Fields\FlexibleContent;
use Extended\ACF\Fields\Layout;
use Extended\ACF\Fields\Text;

FlexibleContent::make('Blocks')
    ->helperText('Add the page blocks.')
    ->button('Add Component')
    ->layouts([
        Layout::make('Image')
            ->layout('block')
            ->fields([
                Text::make('Description')
            ])
    ])
    ->minLayouts(1)
    ->maxLayouts(10)
    ->required()

分组 - 分组 允许您创建一组子字段。

use Extended\ACF\Fields\Group;
use Extended\ACF\Fields\Image;
use Extended\ACF\Fields\Text;

Group::make('Hero')
    ->helperText('Add a hero block with title, content and image to the page.')
    ->fields([
        Text::make('Title'),
        Image::make('Background Image'),
    ])
    ->layout('row')
    ->required()

消息 - 消息字段允许您显示文本消息。

use Extended\ACF\Fields\Message;

Message::make('Heading')
    ->body('George. One point twenty-one gigawatts.')
    ->escapeHtml(),

重复器 - 重复器字段 允许您创建一组子字段,在编辑内容时可以重复使用!

use Extended\ACF\Fields\Image;
use Extended\ACF\Fields\Repeater;
use Extended\ACF\Fields\Text;

Repeater::make('Employees')
    ->helperText('Add the employees.')
    ->fields([
        Text::make('Name'),
        Image::make('Profile Picture'),
    ])
    ->minRows(2)
    ->maxRows(10)
    ->collapsed('name')
    ->button('Add employee')
    ->paginated(10)
    ->layout('table') // block, row, table
    ->required()

标签 - 标签字段 将字段分组到标签页中。在标签之后添加的字段成为其子项。在标签上启用 endpoint 将创建一个新的标签组。

use Extended\ACF\Fields\Tab;

Tab::make('Tab 1'),
Tab::make('Tab 2'),
Tab::make('Tab 3')
    ->placement('top') // top, left
    ->selected() // specify which tab should be selected by default
    ->endpoint(), // This will make a break in the tabs and create a new group of tabs

位置

Location 类允许您在不指定 nameoperatorvalue 键的情况下编写自定义位置规则。如果没有提供 operator,它将使用 operator 作为 value。有关自定义位置规则的详细信息,请访问 此链接

use Extended\ACF\Location;

Location::where('post_type', 'post')->and('post_type', '!=', 'post') // available operators: ==, !=

注意

版本 12 中将 if 方法重命名为 where,请参阅 升级指南

条件逻辑

条件类帮助您编写条件逻辑 而不必知道 字段键。

use Extended\ACF\ConditionalLogic;
use Extended\ACF\Fields\File;
use Extended\ACF\Fields\Select;
use Extended\ACF\Fields\URL;
use Extended\ACF\Fields\Textarea;
use Extended\ACF\Fields\Text;

Select::make('Type')
    ->choices([
        'document' => 'Document',
        'link' => 'Link to resource',
        'embed' => 'Embed',
    ]),
File::make('Document', 'file')
    ->conditionalLogic([
        ConditionalLogic::where('type', '==', 'document') // available operators: ==, !=, >, <, ==pattern, ==contains, ==empty, !=empty
    ]),
URL::make('Link', 'url')
    ->conditionalLogic([
        ConditionalLogic::where('type', '==', 'link')
    ]),

// "and" condition
Textarea::make('Embed Code')
    ->conditionalLogic([
        ConditionalLogic::where('type', '!=', 'document')->and('type', '!=', 'link')
    ]),

// use multiple conditional logic for "or" condition
Text::make('Title')
    ->conditionalLogic([
        ConditionalLogic::where('type', '!=', 'document'),
        ConditionalLogic::where('type', '!=', 'link')
    ]),

// conditional logic that relies on another field from a different field group
Text::make('Sub Title')
    ->conditionalLogic([
      ConditionalLogic::where(
        group: 'other-group',
        name: 'enable_highlight', 
        operator: '==', 
        value: 'on', 
      )
    ]),

非标准

helperText

helperText 方法支持以下元素的 Markdown

Text::make('Title')
    ->helperText('__strong__ **strong** _italic_ *italic* `code` [link](https://example.com)')

column 属性在 ACF 中不是标准。它用作设置字段包装器宽度的快捷方式。您可以提供一个介于 0 和 100 之间的数字作为其值。

Text::make('Text')
    ->column(50) // shorthand for ->wrapper(['width' => 50])

dddump

dddump 方法是非标准的,在 ACF 中不可用。这些方法用于调试。

Text::make('Name')
    ->dd()
    ->dump()

要使用 dddump 方法,您需要安装 symfony/var-dumper

composer require symfony/var-dumper --dev

key 方法允许您定义自定义字段键。键应仅由字母数字字符和下划线组成,并且必须以 field_layout_ 开头。

Text::make('Text')
    ->key('field_123abc')

您可以使用 key 参数在 条件逻辑 中提供自定义字段键。

ConditionalLogic::where(
  name: 'color', 
  operator: '==', 
  value: 'red'
  key: 'field_123abc', 
)

重要

除非您彻底理解它们,否则请避免使用自定义字段键。字段键在您使用 register_extended_field_group 函数时自动生成。

withSettings

当您想添加自定义设置时,withSettings 方法将覆盖字段上现有的任何设置。

Text::make('Name')
	->withSettings(['my-new-setting' => 'value'])
	->required()

添加自定义设置的另一个选项是扩展包中提供的字段类。请参阅 自定义字段 部分。

namespace App\Fields;

use Extended\ACF\Fields\Select as Field;

class Select extends Field
{
    public function myNewSetting(string $value): static
    {
        $this->settings['my-new-setting'] = $value;

        return $this;
    }
}

自定义字段

要创建自定义字段类,您可以扩展基础字段类[基础字段类]。此外,您还可以导入可用的设置特性,以添加常见的功能,如requiredhelperText

namespace App\Fields;

use Extended\ACF\Fields\Field;
use Extended\ACF\Fields\Settings\HelperText;
use Extended\ACF\Fields\Settings\Required;

class OpenStreetMap extends Field
{
    use HelperText;
    use Required;

    protected $type = 'open_street_map';

    public function latitude(float $latitude): static
    {
        $this->settings['latitude'] = $latitude;

        return $this;
    }
    
    public function longitude(float $longitude): static
    {
        $this->settings['longitude'] = $longitude;

        return $this;
    }
    
    public function zoom(float $zoom): static
    {
        $this->settings['zoom'] = $zoom;

        return $this;
    }
}

准备好后,您可以使用自己的字段,就像使用这个库中的任何其他字段一样。

use App\Fields\OpenStreetMap;

OpenStreetMap::make('Map')
    ->latitude(56.474)
    ->longitude(11.863)
    ->zoom(10)

升级指南

升级指南提供了关于此包中破坏性更改的信息,现在命名为vinkla/extended-acf。如果您有12版或更低的版本,您可以通过在您的composer.json文件中替换包名来更新。这确保了一切都能按预期工作,并且您会收到更新。

-"wordplate/acf": "^12.0",
+"vinkla/extended-acf": "^12.0"

14

Url类已重命名为URL

-use Extended\ACF\Fields\Url;
+use Extended\ACF\Fields\URL;

-Url::make('GitHub URL')
+URL::make('GitHub URL')

WysiwygEditor类已重命名为WYSIWYGEditor

-use Extended\ACF\Fields\WysiwygEditor;
+use Extended\ACF\Fields\WYSIWYGEditor;

-WysiwygEditor::make('Content')
+WYSIWYGEditor::make('Content')

defaultValue方法已重命名为default

-Text::make('Name')->defaultValue('Jeffrey Way')
+Text::make('Name')->default('Jeffrey Way')

instructions方法已重命名为helperText

-Text::make('Title')->instructions('Add the title text.')
+Text::make('Title')->helperText('Add the title text.')

allowMultiple方法已重命名为multiple

-Select::make('Colors')->allowMultiple()
+Select::make('Colors')->multiple()

allowNull方法已重命名为nullable

-Select::make('Features')->allowNull()
+Select::make('Features')->nullable()

characterLimit方法已重命名为maxLength

-Textarea::make('Description')->characterLimit(100)
+Textarea::make('Description')->maxLength(100)

pagination方法已重命名为paginated

-Repeater::make('Dogs')->pagination(10)
+Repeater::make('Dogs')->paginated(10)

buttonLabel方法已重命名为button

-Repeater::make('Cats')->buttonLabel('Add Cat')
+Repeater::make('Cata')->button('Add Cat')

weekStartsOn方法已重命名为firstDayOfWeek

-DatePicker::make('Date')->weekStartsOn(1)
+DatePicker::make('Date')->firstDayOfWeek(1) // or use `weekStartsOnMonday` or `weekStartsOnSunday`

prepend方法已重命名为prefix

-Number::make('Price')->prepend('$')
+Number::make('Price')->prefix('$')

append方法已重命名为suffix

-Number::make('Price')->append('€')
+Number::make('Price')->suffix('€')

stylisedUi方法在TrueFalse字段上已重命名为stylized

-TrueFalse::make('Disabled')->stylisedUi(onText: 'Yes')
+TrueFalse::make('Disabled')->stylized(on: 'Yes')

stylisedUi方法在Select字段上已拆分为两个方法:stylizedlazyLoad

-Select::make('Friends')->stylisedUi()
+Select::make('Friends')->stylized()

-Select::make('Friends')->stylisedUi(true)
+Select::make('Friends')->lazyLoad()

fileSize方法已拆分为两个方法:minSizemaxSize

-Image::make('Background')->fileSize('400 KB', 5)
+Image::make('Background')->minSize('400 KB')->maxSize(5)

height方法已拆分为两个方法:minHeightmaxHeight

-Gallery::make('Carousel')->height(100, 1000)
+Gallery::make('Carousel')->minHeight(100)->maxHeight(1000)

width方法已拆分为两个方法:minWidthmaxWidth

-Image::make('Product Image')->width(100, 1000)
+Image::make('Product Image')->minWidth(100)->maxWidth(1000)

insert方法已重命名为prependFiles

-Gallery::make('Downloads')->insert('prepend')
+Gallery::make('Downloads')->prependFiles()

Gallery字段上,minmax方法已重命名为minFilesmaxFiles

-Gallery::make('Files')->min(1)->max(10)
+Gallery::make('Files')->minFiles(1)->maxFiles(10)

Relationship字段上,minmax方法已重命名为minPostsmaxPosts

-Relationship::make('Posts')->min(1)->max(10)
+Relationship::make('Posts')->minPosts(1)->maxPosts(10)

Repeater字段上,minmax方法已重命名为minRowsmaxRows

-Repeater::make('Items')->min(1)->max(10)
+Repeater::make('Items')->minRows(1)->maxRows(10)

FlexibleContent字段上,minmax方法已重命名为minLayoutsmaxLayouts

-FlexibleContent::make('Blocks')->min(1)->max(10)
+FlexibleContent::make('Blocks')->minLayouts(1)->maxLayouts(10)

Layout字段上,minmax方法已重命名为minInstancesmaxInstances

-Layout::make('Testimonials')->min(1)->max(10)
+Layout::make('Testimonials')->minInstances(1)->maxInstances(10)

mimeTypes方法已重命名为acceptedFileTypes

-File::make('Manual')->mimeTypes(['pdf'])
+File::make('Manual')->acceptedFileTypes(['pdf'])

enableOpacity方法已重命名为opacity

-ColorPicker::make('Background')->enableOpacity()
+ColorPicker::make('Background')->opacity()

delay方法已重命名为lazyLoad

-WysiwygEditor::make('Biography')->delay()
+WYSIWYGEditor::make('Biography')->lazyLoad()

mediaUpload方法已重命名为disableMediaUpload

-WysiwygEditor::make('Narrative')->mediaUpload(false)
+WYSIWYGEditor::make('Narrative')->disableMediaUpload()

message方法已重命名为body

-Message::make('Heading')->message('Text')
+Message::make('Heading')->body('Text')

allowArchives方法已重命名为disableArchives

-PageLink::make('Link')->allowArchives(false)
+PageLink::make('Link')->disableArchives()

addTermloadTermssaveTerms方法已重命名为createloadsave

-Taxonomy::make('Category')->addTerm()->loadTerms()->saveTerms()
+Taxonomy::make('Category')->create()->load()->save()

returnFormat方法在所有字段上已重命名为format

-Select::make('Superhero')->returnFormat('value')
+Select::make('Superhero')->format('value')

Instructions特性已重命名为HelperText

-use Extended\ACF\Fields\Settings\Instructions;
+use Extended\ACF\Fields\Settings\HelperText;

MimeTypes特性已重命名为FileTypes

-use Extended\ACF\Fields\Settings\MimeTypes;
+use Extended\ACF\Fields\Settings\FileTypes;

CharacterLimit特性已重命名为MaxLength

-use Extended\ACF\Fields\Settings\CharacterLimit;
+use Extended\ACF\Fields\Settings\MaxLength;

Pending特性已重命名为Affixable

-use Extended\ACF\Fields\Settings\Pending;
+use Extended\ACF\Fields\Settings\Affixable;

Writable 特性重命名为 Immutable

-use Extended\ACF\Fields\Settings\Writable;
+use Extended\ACF\Fields\Settings\Immutable;

SubFields 特性重命名为 Fields

-use Extended\ACF\Fields\Settings\SubFields;
+use Extended\ACF\Fields\Settings\Fields;

已移除 MessageReturnFormat 特性。

-use Extended\ACF\Fields\Settings\Message;
-use Extended\ACF\Fields\Settings\ReturnFormat;

更新日志:[查看 13.0.0...14.0.0](https://github.com/vinkla/extended-acf/compare/13.0.0...14.0.0)

13

如果您正在升级到版本 13,您还需要更新您的导入。命名空间已更改为 Extended\ACF

-use WordPlate\Acf\Fields\Text;
-use WordPlate\Acf\Fields\Number;
+use Extended\ACF\Fields\Text;
+use Extended\ACF\Fields\Number;

更新日志:[查看 12.0.0...13.0.0](https://github.com/vinkla/extended-acf/compare/12.0.0...13.0.0)

12

将查询方法 if 替换为 where。请相应地更新您的字段组。

use Extended\ACF\Location;

-Location::if('post_type', 'post')
+Location::where('post_type', 'post')

更新日志:[查看 11.0.0...12.0.0](https://github.com/vinkla/extended-acf/compare/11.0.0...12.0.0)

11

字段名称现在自动格式化为 snake_case,而不是 kebab-case。

-Text::make('Organization Number') // organization-number
+Text::make('Organization Number') // organization_number

Radio 字段重命名为 RadioButton

-Radio::make('Color')
+RadioButton::make('Color')

Wysiwyg 字段重命名为 WysiwygEditor

-Wysiwyg::make('Text')
+WysiwygEditor::make('Text')

更新日志:[查看 10.0.0...11.0.0](https://github.com/vinkla/extended-acf/compare/10.0.0...11.0.0)