一个强大、可扩展的 WordPress 主题选项框架。
- 🎨 多种字段类型支持
- 📱 响应式后台界面
- 🔧 易于扩展和自定义
- 🌐 支持国际化
- 💾 自动保存和恢复
text- 单行文本输入textarea- 多行文本输入number- 数字输入color- 颜色选择器image- 图片上传
select- 下拉选择radio- 单选按钮checkbox- 单个复选框checkbox_group- 多选复选框组switch- 开关按钮
slider- 滑块控制code_editor- 代码编辑器group- 字段分组
content- 显示静态内容/说明文本heading- 显示标题/分隔符submessage- 显示提示信息(支持多种样式)
add_action('init', function () {
fox_framework()->add_options([
[
'id' => 'site_title',
'title' => '网站标题',
'type' => 'text',
'default' => '',
],
]);
});Content 字段用于显示静态内容、说明文字等,不会保存到数据库:
[
'id' => 'info_notice',
'type' => 'content',
'content' => '<p>这里可以放置说明文字、帮助信息或者 HTML 内容。</p>',
]Heading 字段用于显示标题和分隔不同的设置区域:
[
'id' => 'heading_general',
'type' => 'heading',
'content' => '常规设置',
]Submessage 字段用于显示提示信息,支持 5 种样式:
// 普通样式
[
'id' => 'msg_info',
'type' => 'submessage',
'style' => 'normal',
'content' => '这是一条普通提示信息。',
]
// 信息样式
[
'id' => 'msg_info',
'type' => 'submessage',
'style' => 'info',
'content' => '这是一条信息提示。',
]
// 成功样式
[
'id' => 'msg_success',
'type' => 'submessage',
'style' => 'success',
'content' => '操作成功!',
]
// 警告样式
[
'id' => 'msg_warning',
'type' => 'submessage',
'style' => 'warning',
'content' => '<strong>警告:</strong>请谨慎操作!',
]
// 错误样式
[
'id' => 'msg_error',
'type' => 'submessage',
'style' => 'error',
'content' => '<strong>错误:</strong>配置有误,请检查。',
]add_action('init', function () {
fox_framework()->add_options([
// 添加标题分隔
[
'id' => 'heading_basic',
'type' => 'heading',
'content' => '基本设置',
],
// 添加说明内容
[
'id' => 'info_basic',
'type' => 'content',
'content' => '<p>这里是基本设置区域,可以配置网站的基础信息。</p>',
],
// 添加警告提示
[
'id' => 'warning_basic',
'type' => 'submessage',
'style' => 'info',
'content' => '所有更改都会立即生效,请确保正确填写。',
],
// 添加实际的设置字段
[
'id' => 'site_logo',
'title' => '网站 Logo',
'type' => 'image',
'default' => '',
],
[
'id' => 'site_title',
'title' => '网站标题',
'type' => 'text',
'default' => '',
],
]);
});在主题中获取保存的选项值:
// 获取选项值
$logo = Fox_Options::get('site_logo', '默认值');
// 设置选项值
Fox_Options::set('site_logo', 'https://example.com/logo.png');id(必需) - 字段唯一标识符title(可选) - 字段标题(content/heading/submessage 不需要)type(必需) - 字段类型default(可选) - 默认值
content(必需) - 要显示的内容(支持 HTML)
content(必需) - 标题文本
content(必需) - 提示内容(支持 HTML)style(可选) - 样式类型:normal、info、success、warning、error
- 版本: 1.0.0
- 作者: Fox Framework Team
- 许可: GPL-2.0+
- ✨ 新增 content 字段类型
- ✨ 新增 heading 字段类型
- ✨ 新增 submessage 字段类型(支持 5 种样式)
- 🐛 修复重复代码问题
- 🎨 优化 CSS 样式
- 📝 完善文档说明