高级自定义字段acf_add_local_field_group()
打破了WordPress图像编辑器。
我有一个类似于以下类的类被调用,但它导致WordPress图像编辑器无法加载。当我评论出$this->load_acf_fields();
时,WordPress中的图像编辑器可以正常工作。
我知道我可以切换到json格式,但我想知道发生了什么。
<?php
class MyClassCustomFields extends MyClass {
public function __construct() {
parent::__construct();
$this->load_acf_fields();
}
/**
* Load ACF Fields
*/
public function load_acf_fields() {
if( function_exists('acf_add_local_field_group') ):
acf_add_local_field_group(array (
'key' => 'group_c5mzpj3e3kazq',
'title' => 'Home Page Meta',
'fields' => array (
array (
'key' => 'field_q5tdea0fgotbd',
'label' => 'Custom Heading',
'name' => 'home_custom_heading',
'type' => 'text',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
'width' => '',
'class' => '',
'id' => '',
),
'default_value' => '',
'placeholder' => '',
'prepend' => '',
'append' => '',
'maxlength' => '',
),
),
'location' => array (
array (
array (
'param' => 'page_type',
'operator' => '==',
'value' => 'front_page',
),
),
),
'menu_order' => 0,
'position' => 'normal',
'style' => 'seamless',
'label_placement' => 'top',
'instruction_placement' => 'label',
'active' => 1,
'description' => '',
));
endif;
}
}
解决方案是用acf_add_local_field_group
替换所有对register_field_group
的引用。
根据您必须迁移的字段数量,最好使用以下技术将字段迁移到.json格式:https://dev-notes.eu/2017/01/convert-acf-fields-registered-by-php-to-importable-json-format/