vinkla/extended-acf

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

14.2.1 2024-09-12 09:00 UTC

README

Extended ACF

Extended ACF

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

Extended 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()

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

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()

关系

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

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 的 URL。

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()

谷歌地图 - 谷歌地图字段 创建一个可以放置标记的交互式地图。

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

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('€')

TrueFalse 字段上,将 stylisedUi 方法重命名为 stylized

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

Select 字段上,将 stylisedUi 方法拆分为两个方法 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

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

12

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

use Extended\ACF\Location;

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

更新日志:请参阅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