Ape*_*eli 2 wordpress ninja-forms
我正在尝试向 Ninja Forms (v. 3.3) 添加自定义字段。在任何地方都找不到完整的示例。
通过代码挖掘似乎过滤器“ninja_forms_register_fields”可以解决问题,但我无法让它在任何地方运行。
以下是如何创建/添加新的 Ninja Forms 字段类型(请记住,此代码应移至单独的 WordPress 插件中)。
首先,我们需要挂钩ninja_forms_register_fields:
add_filter( 'ninja_forms_register_fields', array($this, 'register_fields'));
Run Code Online (Sandbox Code Playgroud)
然后定义方法register_fields(在插件类中):
public function register_fields($actions) {
$actions['blah'] = new NF_CustomPlugin_Fields_Blah();
return $actions;
}
Run Code Online (Sandbox Code Playgroud)
最后一步是声明NF_CustomPlugin_Fields_Blah类:
class NF_CustomPlugin_Fields_Blah extends NF_Fields_Textbox {
protected $_name = 'blah';
protected $_section = 'common'; // section in backend
protected $_type = 'textbox'; // field type
protected $_templates = 'textbox'; // template; it's possible to create custom field templates
public function __construct() {
parent::__construct();
$this->_nicename = __( 'Blah Field', 'ninja-forms' );
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2028 次 |
最近记录: |