我有一個目前沒有功能的插件。這是目前的結構:在自定義插件類中使用Carbon字段
<?php
class Test
{
public function __construct()
{
}
}
$wpTest = new Test();
我想使用Carbon Fields WordPress插件。安裝完成後,我根據網站的說明改變了結構,只適應OOP。
<?php
use Carbon_Fields\Container;
use Carbon_Fields\Field;
class Test
{
public function __construct()
{
add_action('carbon_fields_register_fields', array($this, 'crb_attach_theme_options'));
add_action('after_setup_theme', array($this , 'crb_load'));
}
public function crb_load()
{
require_once('vendor/autoload.php');
\Carbon_Fields\Carbon_Fields::boot();
}
public function crb_attach_theme_options()
{
Container::make('theme_options', __('Plugin Options', 'crb'))
->add_fields(array(
Field::make('text', 'crb_text', 'Text Field'),
));
}
}
$wpTest = new Test();
它不起作用。我如何解決它?
請說明您預期的結果是什麼,你的意思是什麼「它不工作」。它不是在做你期望的嗎?你有錯誤嗎?這可能有助於審查[我如何問一個好問題](https://stackoverflow.com/help/how-to-ask),所以你給我們提供我們需要的信息來幫助你。 – FluffyKitten
@FluffyKitten最終結果應該是WordPress的管理面板中的自定義字段。沒有錯誤或通知。因此,我問了一個稍微含糊的問題,尋求幫助。 –
請在您的wp-config.php中啓用「WP_DEBUG」並再次檢查錯誤。你是否肯定這個代碼包含在functions.php中?另外,你確定包含'vendor/autoload.php'嗎? –