# wpfy **Repository Path**: kuapinginternet/wpfy ## Basic Information - **Project Name**: wpfy - **Description**: wpfy是快速Wordpress主题开发框架 - **Primary Language**: PHP - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-29 - **Last Updated**: 2026-06-13 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # WPFY \- 是一个专门为WordPress主题和插件开发设计的、简单且轻量级的选项框架(Options Framework) **WPFY** 是一款面向对象、轻量级且功能强大的 WordPress 选项框架,帮助开发者告别手动编写重复的后台表单代码,以优雅高效的方式为 WordPress 主题或插件构建专业的设置界面。 --- ## 特性一览 - **30\+ 内置字段类型**:覆盖文本、图片上传、颜色选择器、重复器(Repeater)、代码编辑器等 - **多场景集成**:支持后台菜单页、文章元数据框(Metabox)、分类法选项、主题定制器、小工具 - **字段条件依赖**:根据其他字段的值自动显示/隐藏,无需手写 JavaScript - **AJAX 异步保存**:无刷新提交,操作体验流畅 - **一键导入/导出**:支持配置备份、迁移与重置 - **多语言支持**:完全本地化,可适配任意语言 - **代码优雅**:面向对象架构,低耦合,易于扩展 - **轻量高效**:按需加载,对服务器资源消耗极低 --- ## 环境要求 |组件|版本要求| |---|---| |WordPress|5\.0\+| |PHP|7\.4\+| |MySQL|5\.6\+| --- ## 快速开始 ### 1\. 引入框架 将 WPFY 文件夹放入你的主题或插件目录中,目录示例如下: ```plain text your-theme/ ├── inc/ │ └── wpfy/ └── functions.php ``` 在 `functions.php` 中引入框架核心文件: ```php require_once get_template_directory() . '/inc/wpfy/wpfy.php'; ``` ### 2\. 创建设置页面 ```php // 初始化一个选项页 WPFY::createOptions('theme_options', [ 'menu_title' => '主题设置', 'page_title' => '主题选项', 'menu_slug' => 'theme-options', 'menu_type' => 'menu', 'menu_icon' => 'dashicons-admin-settings', 'menu_position'=> 60, ]); // 添加一个设置区块 WPFY::createSection('theme_options', [ 'title' => '基础设置', 'fields' => [ [ 'id' => 'site_logo', 'type' => 'image', 'title' => '网站 Logo', 'desc' => '建议尺寸 200x60 像素', ], [ 'id' => 'primary_color', 'type' => 'color', 'title' => '主题主色', 'default' => '#0073aa', ], [ 'id' => 'show_social', 'type' => 'switcher', 'title' => '显示社交图标', 'default' => true, ], ], ]); ``` ### 3\. 获取保存的值 ```php // 获取 Logo 图片 URL $logo = wpfy_get_option('site_logo', 'theme_options', '默认值'); // 获取主题主色 $primary_color = wpfy_get_option('primary_color', 'theme_options', '#0073aa'); // 判断开关状态 if (wpfy_get_option('show_social', 'theme_options', false)) { // 显示社交图标 } ``` --- ## 字段类型大全 |分类|字段类型| |---|---| |基础类|text, textarea, select, checkbox, radio, switcher| |媒体类|image, gallery, file, media| |样式类|color, background, border, spacing, typography| |高级类|repeater, group, date, code\_editor, icon, link| |其他类|heading, subheading, content, notice, separator| --- ## 常见集成场景 ### 文章元数据框(Metabox) ```php WPFY::createMetabox('page_options', [ 'title' => '页面设置', 'post_type' => 'page', 'context' => 'normal', 'priority' => 'high', 'fields' => [ [ 'id' => 'hide_title', 'type' => 'switcher', 'title' => '隐藏页面标题', ], [ 'id' => 'sidebar_position', 'type' => 'select', 'title' => '侧边栏位置', 'options' => [ 'left' => '左侧', 'right' => '右侧', 'none' => '无侧边栏', ], ], ], ]); ``` ### 分类法选项 ```php WPFY::createTaxonomyOptions('category_options', [ 'taxonomy' => 'category', 'fields' => [ [ 'id' => 'cat_icon', 'type' => 'icon', 'title' => '分类图标', ], [ 'id' => 'cat_banner', 'type' => 'image', 'title' => '分类横幅', ], ], ]); ``` ### 主题定制器 ```php WPFY::createCustomizeOptions('theme_customize', [ 'priority' => 30, 'fields' => [ [ 'id' => 'footer_text', 'type' => 'text', 'title' => '底部版权文字', 'default' => '© 2025 你的网站', ], ], ]); ``` --- ## 目录结构 ```plain text wpfy/ ├── wpfy.php # 框架入口文件 ├── classes/ # 核心类库 ├── fields/ # 所有字段类型的实现 ├── admin/ # 后台界面相关 ├── assets/ # 前端资源(JS/CSS) └── languages/ # 多语言翻译文件 ``` --- ## 常见问题 **Q:WPFY 会影响网站性能吗?** A:不会。WPFY 按需加载资源,只在后台相关页面加载 JS/CSS,对前台访问几乎没有性能影响。 > (注:文档部分内容可能由 AI 生成)