webkinder / wordpress-options-page-api
WordPress 设置 API 抽象类
2.1.2
2024-04-16 12:49 UTC
Requires
- php: >=7.0.0
README
这是一个用于处理 WordPress 设置 API 的 PHP 类包装器。这是一个易于访问的面向对象 API,供开发者在自己的插件中使用。
包安装(通过 Composer)
要安装此包,请编辑您的 composer.json
文件
{ "require": { "webkinder/wordpress-options-page-api": "2.1.1" } }
现在运行
$ composer install
使用示例
注册选项
use WebKinder\SettingsAPI; (new SettingsAPI(['network_settings' => false])) ->set_sections( [ [ 'id' => 'custom_options', 'title' => __('Custom Options'), ], ] ) ->set_fields([ 'custom_options' => [ [ 'name' => 'information_text', 'label' => __('Information Text'), 'type' => 'textarea', ], [ 'name' => 'radio_option', 'label' => __('Radio Option'), 'type' => 'radio', 'options' => [ 'top' => __('Top'), 'bottom' => __('Bottom'), 'bottom-right' => __('Bottom Right'), ], ], [ 'name' => 'checkbox_option', 'label' => __('Checkbox Option'), 'type' => 'checkbox', 'desc' => __('aktivieren'), ], [ 'name' => 'multicheck_option', 'label' => __('Multicheck Options'), 'type' => 'multicheck', 'options' => [ 'top' => __('Top'), 'bottom' => __('Bottom'), 'bottom-right' => __('Bottom Right'), ], ], ], ]) ->register_page('Options page', 'Options page', 'manage_options', 'custom-options-page') ->admin_init() ;
检索保存的选项
/** * Get the value of a settings field * * @param string $option settings field name * @param string $section the section name this field belongs to * @param string $default default text if it's not found * * @return mixed */ function prefix_get_option( $option, $section, $default = '' ) { $options = get_option( $section ); if ( isset( $options[$option] ) ) { return $options[$option]; } return $default; }
这个插件是做什么的?
这是一个 WordPress 设置 API 的 API
致谢
这是 tareq1988 的扩展版本,具有更多功能和有见地的更改和添加。
变更日志
2.1.1 (19 March, 2024)
------------------------
- Update docs
- More dynamic handling
2.1.0 (19 March, 2024)
------------------------
- Add support for network options
2.0.2 (24 April, 2023)
------------------------
- Better check for multilang
2.0.1 (29 March, 2023)
------------------------
- Fix hidden translation fields that were required and could be empty
2.0.0 (28 March, 2023)
------------------------
- Add proper versioning
- Add conditional support for hiding and disabling fields
- Add option for required fields
- Add multilang support (WPML only)
1.0.0 (14 March, 2019)
------------------------
- First version published