golchha/wp-plugin-boilerplate 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

golchha/wp-plugin-boilerplate

Composer 安装命令:

composer require golchha/wp-plugin-boilerplate

包简介

An opinionated WordPress plugin boilerplate for building long-lived plugins with explicit structure and predictable lifecycle behavior.

README 文档

README

A structured WordPress plugin boilerplate with a schema-driven field engine, MetaBox system, and deterministic plugin architecture.

PHP Version Downloads

An opinionated WordPress plugin boilerplate for building long-lived plugins with explicit structure and predictable lifecycle behavior.

This project does not provide user-facing features and does not try to replace WordPress conventions, Git workflows, or existing development practices.

It exists to provide a constrained starting point for plugins that are expected to grow over time - where admin configuration, settings, frontend behavior, and lifecycle concerns tend to blur and accumulate accidental complexity.

Documentation

Goal Document
Build a plugin from this boilerplate HOW-TO-USE.md
Look up a field type or schema key FIELDS.md
Understand architectural decisions ADVANCED-TOPICS.md
Contribute a change CONTRIBUTING.md
See what changed CHANGELOG.md

Built-in Examples

The repository includes working reference implementations demonstrating how the field engine, settings system, and MetaBox integration are intended to be used.

Examples demonstrate:

  • Settings tab definitions
  • Field schema structure
  • Repeater field usage
  • Conditional field visibility
  • Media field configuration
  • MetaBox field integration

See the example modules in:

  • src/Settings/Tabs
  • src/MetaBox/Boxes

These examples are intentionally simple and serve as a baseline for building more complex plugins.

Core Principles

  • Clear separation between admin, settings, and public runtime
  • Settings treated as a domain boundary
  • Predictable lifecycle behavior
  • Minimal magic and no hidden side effects
  • Constraints designed for long-term maintainability

Hook Registration (v1.6.3+)

The boilerplate uses a centralized Loader to register WordPress hooks.

Feature classes do not call add_action() or add_filter() directly.

Instead, hooks can be declared using one of two approaches.

Declarative Hooks

Classes may define a hooks() method.

Example:

    public function hooks(): array
    {
        return [
            'action' => [
                ['admin_init', 'boot'],
                ['admin_menu', 'register_menus'],
            ],

            'filter' => [
                ['plugin_action_links_' . plugin_basename(Plugin::file()), 'add_settings_link'],
            ],
        ];
    }

The Loader reads this method and registers the hooks automatically.

Manual Wiring

For dynamic hooks or external handlers, classes may still register hooks explicitly:

    public function register(Loader $loader): void
    {
        $loader->action("admin_post_{$prefix}reset", [new ResetSettings(), 'handle']);
    }

Both approaches can be used together.

Design Goals

This boilerplate is intentionally opinionated.

It is designed to help developers build long-lived plugins without accumulating architectural debt.

The project prioritizes:

  • deterministic behavior over convenience
  • explicit configuration over hidden automation
  • long-term maintainability over rapid prototyping
  • stable storage structures over dynamic schemas

The goal is not to replace WordPress patterns, but to provide a structured starting point for plugins that are expected to evolve over time.

Settings System (v1.3+)

The settings layer is now a structured, extensible system.

Field Architecture

  • Schema-driven FieldDefinition
  • Centralized FieldRenderer
  • Deterministic sanitization per field
  • Nested option handling
  • Extensible field pattern

MetaBox Support (v1.3+)

The field engine now powers both Settings and MetaBox modules.

  • Shared rendering layer
  • Shared sanitization pipeline
  • Field-type-aware save logic
  • Stable nested meta structure
  • Repeater fully supported in MetaBox context
  • Deterministic meta key namespacing per MetaBox
  • Registry-level ID validation
  • Template-scoped MetaBox registration

Meta and Settings use the same core field abstraction.

MetaBoxRepository (v1.5+)

MetaBox persistence must go through MetaBoxRepository.

Direct use of get_post_meta() or manual meta key construction is not supported.

Meta keys are automatically namespaced as:

{PREFIX}{BOX_ID}{FIELD_KEY}

Repository guarantees deterministic key ownership and collision safety.

Supported Fields

Text-based

  • text, email, url, password, hidden
  • textarea
  • date, time, datetime-local
  • editor (wp_editor powered)

Numeric & Boolean

  • number
  • range
  • checkbox

Choice

  • select
  • multiselect
  • radio

Rich

  • color (WP Color Picker)
  • media / image / file / document / audio / video / archive
  • media with multiple: true (ordered gallery — drag sort, per-item remove)
  • repeater (nested structured fields, all types)

Editor Field

The editor field is powered by WordPress wp_editor().

As of v1.6.4 the editor field is supported inside repeater rows.

The field engine automatically manages TinyMCE lifecycle events to ensure:

  • unique editor IDs per repeater row
  • safe initialization when rows are created or duplicated
  • stable behavior during drag sorting

Repeater Field

The repeater allows structured, sortable nested data.

Features

  • Collapsible rows (collapsed by default)
  • Drag & drop sorting with order persistence
  • Duplicate row support
  • Min / max limits
  • Independent row sanitization
  • Template-based rendering
  • Dashicon controls
  • Conditional field support

Repeaters always store ordered arrays and never leak template markup into the runtime DOM.

Storage Guarantees (v1.3+)

  • Template placeholder rows (__index__) are never persisted
  • Completely empty rows are removed automatically
  • Rows are reindexed numerically before persistence
  • Nested data structure remains deterministic and stable

Media Field

Stores attachment IDs only.

Supports:

  • Single selection (integer)
  • Multiple selection (ordered array)
  • Drag sorting (multiple mode)
  • Per-item removal (multiple mode)
  • Duplicate prevention in multiple mode
  • MIME type restriction support
  • Square preview layout

Behavior adapts automatically based on multiple: true.

Admin validation uses WordPress core notice styles to report duplicate selections or invalid file types. Storage format remains unchanged.

Admin UI System

The admin interface is:

  • Fully scoped under .wppb-admin
  • Built on a 12-column CSS Grid layout
  • Powered by semantic design tokens
  • Safe from wp-admin style conflicts
  • Field type is injected as a CSS class on field wrappers

Example:

'class' => 'width-6',

Available widths:

  • width-1 → width-12
  • Default: width-4 for most fields; width (full) for editor, media, and repeater

Folder Responsibilities

Directory Responsibility
src/Admin Admin UI, menus, and admin-only modules
src/Settings Settings tabs and option persistence
src/MetaBox MetaBox definitions, registry, and repository
src/Frontend Frontend/runtime behavior
src/Core Field engine, definitions, rendering, and support utilities
src/Lifecycle Activation and deactivation logic
assets CSS, JavaScript, and static assets
vendor Bundled Composer dependencies

Each directory represents a deliberate architectural boundary.

Stability Guarantees

Starting with v1.0:

  • Public behavior is registered unconditionally
  • Admin configuration flows cleanly into runtime
  • Lifecycle behavior is predictable
  • Uninstall cleans up plugin-owned data
  • Plugin renaming does not break behavior
  • Distributed as a self-contained package

Breaking these guarantees requires a major version bump.

Versioning

Semantic Versioning is followed:

  • Patch → internal fixes
  • Minor → new features or backward-compatible structural improvements
  • Major → breaking changes to storage, APIs, or architectural guarantees

Changelog

Please see CHANGELOG for more information on recent changes.

Security

If you discover any security-related issues, please email vardhans@ulhas.net instead of using the issue tracker.

Credits

See also the list of contributors.

License

This project is licensed under the GNU General Public License v2.0 or later (GPL-2.0-or-later).

WordPress is licensed under the GPL, and any plugin that runs within WordPress and uses its APIs is required to be GPL-compatible.

You are free to use, modify, and distribute this software under the terms of the GPL. See the LICENSE file for details.

If this boilerplate has been useful to you, you can support its development here: Buy me a coffee

golchha/wp-plugin-boilerplate 适用场景与选型建议

golchha/wp-plugin-boilerplate 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 11, 最近一次更新时间为 2026 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 golchha/wp-plugin-boilerplate 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 golchha/wp-plugin-boilerplate 我们能提供哪些服务?
定制开发 / 二次开发

基于 golchha/wp-plugin-boilerplate 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 22
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-or-later
  • 更新时间: 2026-02-04