Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 4.35 KB

File metadata and controls

72 lines (51 loc) · 4.35 KB

WebberZone Settings API

A reusable, namespaced wrapper around the native WordPress Settings API that powers the admin interfaces across WebberZone plugins. It ships with opinionated helpers for:

  • Building tabbed settings pages with reusable field renderers.
  • Managing sanitization, defaults, upgrades, and Help tabs from a single configuration array.
  • Rendering meta boxes that reuse the same field definitions as your settings screens.
  • Providing setup wizards, CSS/JS assets, and an extendable Hook Registry utility.

Use the package as-is or as a reference implementation when building complex plugin settings screens.

Repository structure

Settings_API/
├── class-settings.php           # Example settings-controller implementation
├── class-metabox.php            # Example post meta box integration
├── sidebar.php                  # Default help/CTA sidebar partial
├── util/
│   └── class-hook-registry.php  # Lightweight registry for actions/filters
└── settings/
    ├── class-settings-api.php        # Core Settings API wrapper
    ├── class-settings-form.php       # Field renderer callbacks
    ├── class-settings-sanitize.php   # Sanitization helpers per field type
    ├── class-settings-wizard-api.php # Optional multi-step setup wizard
    ├── class-metabox-api.php         # Meta box helper using the same fields
    ├── css/                          # Admin styles (tabs, wizard, RTL variants)
    └── js/                           # Admin scripts (media, CodeMirror glue, etc.)

Everything is namespaced under WebberZone\Settings_API\Admin (or ...\Admin\Settings). Update the namespace to match your plugin if you integrate the code directly into your project root.

Getting started

  1. Copy the files. Bring the entire settings directory plus the example class-settings.php, class-metabox.php, sidebar.php, and util/class-hook-registry.php into your plugin (adjust paths to suit your structure).

  2. Autoload the classes. Either map the WebberZone\Settings_API namespace via Composer/PSR-4 or require_once the files before usage.

  3. Update identifiers. Replace the sample prefix (ata), option key (ata_settings), text domain (add-to-all), post types, and URLs with values from your plugin.

  4. Wire into WordPress. Instantiate your customized Settings class on plugins_loaded/admin_init so it can register menus, fields, and assets:

    add_action( 'plugins_loaded', function () {
        $settings = new \WebberZone\Settings_API\Admin\Settings();
        $settings->initialise_settings();
    } );
  5. Hook sanitization + upgrades. Each settings prefix registers filters such as {$prefix}_settings_sanitize and {$prefix}_translation_strings so your plugin can inject or adjust data.

Customising the example settings class

class-settings.php is a full implementation showing how to:

  • Define translation strings, admin menus, sections, and fields via dedicated methods.
  • Inject the Settings_API class with arrays generated by those methods.
  • Extend the UI with help tabs, contextual sidebars, and custom admin footer text.

Copy the class into your plugin’s namespace, rename the class (e.g. SettingsPlugin_Settings), and edit the arrays returned by methods such as get_registered_settings() to match your data.

Using the Metabox API

class-metabox.php and settings/class-metabox-api.php illustrate how to reuse the same field definitions within meta boxes. Supply the field array via get_registered_settings() and the API will render/save the data with nonce and capability checks.

Sidebar partial

The repo includes two sidebar templates (sidebar.php at the root and settings/sidebar.php). Replace the copy with content relevant to your plugin (support links, upsells, etc.) and include it through the help_sidebar argument passed to Settings_API.

Contributing / support

If you ship this code in your plugin, please keep the copyright headers intact and share improvements back via pull requests.