chandrapatel / wp-custom-settings
允许开发人员使用设置 API 创建自定义管理菜单页面,而不必为每个设置部分和字段注册回调。
0.1
2020-10-24 11:14 UTC
Requires
- php: >=7
- composer/installers: ^1.2
This package is not auto-updated.
Last update: 2024-09-23 05:01:52 UTC
README
允许开发人员使用设置 API 创建自定义管理菜单页面,而不必为每个设置部分和字段注册回调。
支持的表单元素和输入类型
- 文本区域
- 选择框
- 输入类型
- 文本
- 密码
- 电子邮件
- 网址
- 电话
- 数字
- 颜色
- 日期
- 日期时间
- 月份
- 星期
- 时间
安装
此插件作为 Composer 包 提供。
composer require chandrapatel/wp-custom-settings
注意:如果您不使用 Composer,建议将 WP Custom Settings 的主文件添加到您的主题或插件中,而不是将其作为独立插件添加。这样,您可以按照需要修改它,并避免依赖。
用法
您需要创建一个 WP_Custom_Settings
类的实例,它接受三个参数来创建菜单页面、注册设置以及部分和字段。
请查看 example.php 文件。
$custom_settings = new WP_Custom_Settings( // Arguments to add menu page. Following arguments are same as add_menu_page() function arguments. // Callback argument does not needed. [ 'page_title' => __( 'Custom Settings', 'wp-custom-settings' ), 'menu_title' => __( 'Custom Settings', 'wp-custom-settings' ), 'capability' => 'manage_options', 'menu_slug' => 'wp-custom-settings-page', 'icon_url' => '', 'position' => null, ], // Arguments to register setting. Following arguments are same as register_setting() function arguments. [ 'option_group' => 'wp_custom_settings_group', 'option_name' => 'wp_custom_settings_options', 'args' => array( 'type' => 'array', 'description' => 'Description of Custom Settings.', 'show_in_rest' => true, 'default' => array(), 'sanitize_callback' => null, ), ], // Arguments to add sections and fields. [ new WP_Custom_Settings_Section( 'wp_custom_settings_section', // ID. __( 'Section Title.', 'wp-custom-settings' ), // Title. __( 'Section Description.', 'wp-custom-settings' ), // Description. [ new WP_Custom_Settings_Field( 'text', // Field type. 'wp_custom_settings_field', // ID. Also, it will used for "name" attribute. __( 'Field Title', 'wp-settings-api-wrapper' ), // Title. [ // Pass additional arguments. 'description' => 'Description of Custom Settings.', 'label_for' => 'wp_custom_settings_field', 'class' => 'regular-text', ] ), ] ), ] );