youniwemi / wp-settings-kit
WP Settings Kit 是一个轻量级的库,可以轻松创建 WordPress 设置页面和文章元框。
1.1.4
2024-03-15 18:09 UTC
Requires
- php: >=7.3
Requires (Dev)
README
WordPress 设置工具包 - 轻量级库,轻松创建 WordPress 设置页面和文章元框
是否想要在您的 WordPress 插件或主题内部构建自定义设置(或元框),并且不喜欢通过 WordPress API 创建自定义设置和元框的非 DRY 方法?这个包就是为了解决这个问题。🎊
屏幕截图
COMPOSER 安装
- 您可以使用 composer 安装此库
composer require youniwemi/wp-settings-kit
- 在包含 vendor/autoload.php 之后,您将能够使用 WP_Settings_Kit 类
用法
设置页面用法
- 准备一个选项数组,然后实例化 WP_Settings_Kit
$options = [ 'name' => 'MY_AWESOME_FEATURE', 'title' => 'My Awesome Feature', 'description' => "My Awesome Feature description", 'side_panel' => "<p>A side Panel content : to add some explanations if necessary</p>", 'fields' => [ [ 'id' => 'ACTIVE', 'type' => 'checkbox', 'title' => 'The feature is active' , ], [ 'id' => 'FIRST_SETTING', 'type' => 'number', 'title' => 'First setting' , 'default' => 0 , // This setting will be included only if the first checkbox is checked 'show_if' => function(){ return defined('MY_AWESOME_FEATURE_ACTIVE') && MY_AWESOME_FEATURE_ACTIVE == 'on'; } ] ] ]; $setting = new WP_Settings_Kit($options);
- 一旦选项保存,常量 MY_AWESOME_FEATURE_ACTIVE 就会可用,并且可以设置第一个设置 MY_AWESOME_FEATURE_FIRST_SETTING
文章元框用法
- 准备一个选项数组以及元框定义,然后实例化 WP_Settings_Kit
$options = [ 'name' => 'MY_AWESOME_FEATURE', 'title' => 'My Awesome Feature', 'fields' => [ [ 'id' => 'ACTIVE', 'type' => 'checkbox', 'title' => 'The feature is active' , ], [ 'id' => 'FIRST_SETTING', 'type' => 'number', 'title' => 'First setting' , 'default' => 0 , // This field will be included only if the first checkbox is checked 'show_if' => function(){ return defined('MY_AWESOME_FEATURE_ACTIVE') && MY_AWESOME_FEATURE_ACTIVE == 'on'; } ] ] ]; $metabox = [ 'id' => 'my_metabox', 'title' => 'My Awesome Metabox', 'post_types' => ['post'], // Post types to display meta box 'context' => 'advanced', 'priority' => 'default', ]; $metabox = new WP_Settings_Kit($options , $metabox);
- 一旦元框保存,字段将作为文章元数据保存:MY_AWESOME_FEATURE_FIRST_ACTIVE 和 MY_AWESOME_FEATURE_FIRST_SETTING
待办事项
- 基本设置页面
- 带有 JS 的设置页面标签
- 带有 JS 的设置页面标签
- 代码工作流程的文档
- 创建字段:
text
- 创建字段:
textarea
- 创建字段:
url
- 创建字段:
number
- 创建字段:
checkbox
- 创建字段:
multicheck
- 创建字段:
radio
- 创建字段:
select
- 创建字段:
html
- 创建字段:
wysiwyg
- 创建字段:
file
- 创建字段:
image
- 创建字段:
password
- 创建字段:
color
- 创建字段:
email
- 创建字段:
date
- 创建字段(使用回调生成的内容):
content
- 创建字段:
range
- 支持文章元框
- 使用 WP 标准重构代码
- 教程
- 博客文章
- 文档
许可
在 GNU GPL v2.0 下发布
致谢
此包是基于 @tareq1988 的工作 https://github.com/tareq1988/wordpress-settings-api-class 的分支,基于 https://github.com/ahmadawais/WP-OOP-Settings-API
@AhmadAwais, @deviorobert, @MaedahBatool AND @WordPress, @tareq1988, @royboy789, @twigpress, @rahal.
🙌 Youniwemi
以下所列的杰出企业帮助维护此开源分支
此包在以下 WordPress 插件中使用
对于其他任何问题,请 tweet 至 @rahalaboulfeth