PHPackages                             oberonlai/wp-metabox - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. oberonlai/wp-metabox

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

oberonlai/wp-metabox
====================

Adding custom field for WordPress Post Type.

v1.0.7(2y ago)7992MITPHPPHP &gt;=7.2

Since Jun 23Pushed 2y ago2 watchersCompare

[ Source](https://github.com/oberonlai/wp-metabox)[ Packagist](https://packagist.org/packages/oberonlai/wp-metabox)[ Docs](https://github.com/oberonlai/wp-metabox)[ RSS](/packages/oberonlai-wp-metabox/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)DependenciesVersions (9)Used By (0)

WP Metabox v1.0
===============

[](#wp-metabox-v10)

> Simple WordPress Class for metabox forks from [wp-metabox-constructor-class](https://github.com/MatthewKosloski/wp-metabox-constructor-class)

Requirements
------------

[](#requirements)

- PHP &gt;=7.2
- [Composer](https://getcomposer.org/)
- [WordPress](https://wordpress.org) &gt;=5.4

Installation
------------

[](#installation)

#### Install with composer

[](#install-with-composer)

Run the following in your terminal to install with [Composer](https://getcomposer.org/).

```
$ composer require oberonlai/wp-metabox

```

WP Metabox [PSR-4](https://www.php-fig.org/psr/psr-4/) autoloading and can be used with the Composer's autoloader. Below is a basic example of getting started, though your setup may be different depending on how you are using Composer.

```
require __DIR__ . '/vendor/autoload.php';

use ODS\Metabox;

$options = array( ... );

$books = new Metabox( $options );
```

See Composer's [basic usage](https://getcomposer.org/doc/01-basic-usage.md#autoloading) guide for details on working with Composer and autoloading.

Basic Usage
-----------

[](#basic-usage)

Below is a basic example of setting up a simple custom filter with a post meta field.

```
// Require the Composer autoloader.
require __DIR__ . '/vendor/autoload.php';

// Import PostTypes.
use ODS\Metabox;
```

Usage
-----

[](#usage)

To create a metabox, first instantiate an instance of `Metabox`. The class takes one argument, which is an associative array. The keys to the array are similar to the arguments provided to the [add\_meta\_box](https://developer.wordpress.org/reference/functions/add_meta_box/) WordPress function; however, you don't provide `callback` or `callback_args`.

```
$metabox = new Metabox(array(
	'id' => 'metabox_id',
	'title' => 'My awesome metabox',
	'screen' => 'post', // post type
	'context' => 'advanced', // Options normal, side, advanced.
	'priority' => 'default'
));
```

Please add the detection for the WooCommerce order metabox to check whether the HPOS is enabled or not.

```
use Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController;

$screen = wc_get_container()->get( CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
		? wc_get_page_screen_id( 'shop-order' )
		: 'shop_order';

$metabox = new Metabox(
	array(
		'id'       => 'metabox_id',
		'title'    => 'My awesome metabox for WooCommerce order',
		'screen'   => $screen,
		'context'  => 'side',
		'priority' => 'high',
	)
);
```

Available Fields
----------------

[](#available-fields)

After instantiating the above metabox, add a few fields to it. Below is a list of the available fields.

### Text

[](#text)

A simple text input. Nothing special.

```
$metabox->addText(array(
	'id' => 'metabox_text_field',
	'label' => 'Text',
	'desc' => 'An example description paragraph that appears below the label.'
));
```

### Textarea

[](#textarea)

Textareas are used to store a body of text. For a richer experience with HTML, see the [WYSIWYG](https://github.com/MatthewKosloski/wp-metabox-constructor-class#wysiwyg-editor) editor.

```
$metabox->addTextArea(array(
	'id' => 'metabox_textarea_field',
	'label' => 'Textarea',
	'desc' => 'An example description paragraph that appears below the label.'
));
```

### Checkbox

[](#checkbox)

Checkboxes are a great way to facilitate conditional logic.

```
$metabox->addCheckbox(array(
	'id' => 'metabox_checkbox_field',
	'label' => 'Checkbox',
	'desc' => 'An example description paragraph that appears below the label.'
));
```

### Radio

[](#radio)

Radio fields are a great way to choose from a selection of options.

```
$metabox->addRadio(
	array(
		'id' => 'metabox_radio_field',
		'label' => 'Radio',
		'desc' => 'An example description paragraph that appears below the label.',
	),
	array(
		'key1' => 'Value One',
		'key2' => 'Value Two'
	)
);
```

### Select

[](#select)

Select fields are a great way to choose from a selection of options.

```
$metabox->addSelect(
	array(
		'id' => 'metabox_select_field',
		'label' => 'Select',
		'desc' => 'An example description paragraph that appears below the label.',
	),
	array(
		'key1' => 'Value One',
		'key2' => 'Value Two'
	)
);
```

### Html

[](#html)

Add HTML markup to display information.

```
$metabox->addHtml(
	array(
		'id' => 'metabox_html_field',
		'label' => 'html',
		'html' => 'Hello World',
	),
);
```

### Image Upload

[](#image-upload)

Use this to permit users to upload an image within the metabox. Pro tip: use this with the [repeater](https://github.com/MatthewKosloski/wp-metabox-constructor-class#repeater) to dynamically manage the photos within a gallery or slideshow.

```
$metabox->addImage(array(
	'id' => 'metabox_image_field',
	'label' => 'Image Upload',
	'desc' => 'An example description paragraph that appears below the label.'
));
```

### WYSIWYG Editor

[](#wysiwyg-editor)

You can use a WYSIWYG editor to facilitate the management of HTML content.

```
$metabox->addEditor(array(
	'id' => 'metabox_editor_field',
	'label' => 'Editor',
	'desc' => 'An example description paragraph that appears below the label.'
));
```

### Repeater

[](#repeater)

All of the above fields can be added to a repeater to store an array of content with a dynamic length. Here is an example of a repeater block with three fields: text, textarea, and image upload.

Notice: `true` is a second argument to the repeater fields. This is required. Also, the variable, `$metabox_repeater_block_fields[]`, which stores the repeater block's fields, has a pair of brackets `[]` at the end of the variable name. This is required.

```
$metabox_repeater_block_fields[] = $metabox->addText(array(
	'id' => 'metabox_repeater_text_field',
	'label' => 'Photo Title'
), true);

$metabox_repeater_block_fields[] = $metabox->addTextArea(array(
	'id' => 'metabox_repeater_textarea_field',
	'label' => 'Photo Description'
), true);

$metabox_repeater_block_fields[] = $metabox->addImage(array(
	'id' => 'metabox_repeater_image_field',
	'label' => 'Upload Photo'
), true);

$metabox->addRepeaterBlock(array(
	'id' => 'metabox_repeater_block',
	'label' => 'Photo Gallery',
	'fields' => $metabox_repeater_block_fields,
	'desc' => 'Photos in a photo gallery.',
	'single_label' => 'Photo'
));
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~121 days

Recently: every ~210 days

Total

8

Last Release

936d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1587136?v=4)[Oberon Lai](/maintainers/oberonlai)[@oberonlai](https://github.com/oberonlai)

---

Top Contributors

[![oberonlai](https://avatars.githubusercontent.com/u/1587136?v=4)](https://github.com/oberonlai "oberonlai (7 commits)")

### Embed Badge

![Health badge](/badges/oberonlai-wp-metabox/health.svg)

```
[![Health](https://phpackages.com/badges/oberonlai-wp-metabox/health.svg)](https://phpackages.com/packages/oberonlai-wp-metabox)
```

###  Alternatives

[hidehalo/nanoid-php

A copy of nanoid in PHP

8124.1M41](/packages/hidehalo-nanoid-php)[humanmade/hm-gutenberg-tools

Human Made Gutenberg Tools

18997.6k](/packages/humanmade-hm-gutenberg-tools)[monsieurbiz/sylius-menu-plugin

This plugins allows you to manage menus.

1570.2k1](/packages/monsieurbiz-sylius-menu-plugin)[sroze/argument-resolver

A lightweight utility to resolve method arguments based on types and names

1041.4k1](/packages/sroze-argument-resolver)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
