PHPackages                             gebruederheitz/wp-meta-fields - 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. gebruederheitz/wp-meta-fields

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

gebruederheitz/wp-meta-fields
=============================

Dependency-less helpers for a faster Wordpress metaboxes setup.

v1.6.0(2y ago)01.1k↓50%[1 issues](https://github.com/gebruederheitz/wp-meta-fields/issues)2GPL-3.0-onlyPHPPHP &gt;=7.3

Since Jan 31Pushed 2y ago1 watchersCompare

[ Source](https://github.com/gebruederheitz/wp-meta-fields)[ Packagist](https://packagist.org/packages/gebruederheitz/wp-meta-fields)[ RSS](/packages/gebruederheitz-wp-meta-fields/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (21)Used By (2)

Wordpress Meta Fields
=====================

[](#wordpress-meta-fields)

*Dependency-less helpers for a faster Wordpress metaboxes setup.*

---

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

[](#installation)

via composer:

```
> composer require gebruederheitz/wp-meta-fields
```

Make sure you have Composer autoload or an alternative class loader present.

Usage
-----

[](#usage)

Use these helpers anywhere in the WP administration backend where you want to render "metaboxes", or input fields for editors.

WP-Meta-Fields comes with no frontend dependencies – no extra stylesheets or client-side scripts that could cause trouble with installation. This also means, however, that it doesn't come with fancy features like asnyc search, validation or fancy styles for the various input types. It merely provides an intuitive interface to create DRY code when creating metaboxes.

```
use Gebruederheitz\Wordpress\MetaFields\MetaForms;

function render($value)
{
    // Use the "render{$type}" static methods:
    MetaForms::renderTextInputField('ghwp_favourite_color', $value, 'Favourite color');
    // ...or the more verbose "make{$type}" methods, which support chaining:
    MetaForms::makeTextInputField()
        ->setName('ghwp_favourite_food')
        ->setValue($value)
        ->setLabel('Your favourite food')
        ->render();
}
```

### Label i18n

[](#label-i18n)

Labels are automatically translated using Wordpress' `__()` internationalisation function. By default, the namespace "ghwp" is applied. To customize this text domain, call one of the setter method on the singleton:

```
MetaForms::updateTextDomain('my-textdomain');
// or
MetaForms::getInstance()->setTextDomain('my-textdomain');
```

### Inputs API

[](#inputs-api)

All field require at least one name attribute (as noted for each type below) to be set, otherwise an `InvalidFieldConfigurationException` will be thrown.

#### TextInput

[](#textinput)

For rendering a regular text input field.

##### `MetaForms::renderTextInputField(string $name, string $label, $value = '', bool $required = false)`

[](#metaformsrendertextinputfieldstring-name-string-label-value---bool-required--false)

ParameterTypeDescriptionnamestringIdentifier for the field. You will use this value to read the $\_POSTed data back from the form. Required.labelstringA short description for the site editor about the field's expected content. [Auto-translated](#label-i18n). Required.value?stringThe current value of this field. Will be escaped with Wordpress' own `esc_attr()`. Default `''` (empty string).requiredbooleanWhether to mark the field as required. An asterisk will be appended to the label and the `` element will have a `required` attribute set. Default `false`.#### NumberInput

[](#numberinput)

For rendering a an ``.

##### `MetaForms::renderNumberInputField()`

[](#metaformsrendernumberinputfield)

same as [TextInput](#metaformsrendertextinputfieldstring-name-string-label-value---bool-required--false)

#### TextArea

[](#textarea)

Renders a ``.

##### `MetaForms::renderTextArea()`

[](#metaformsrendertextarea)

same as [TextInput](#metaformsrendertextinputfieldstring-name-string-label-value---bool-required--false)

#### MediaPicker

[](#mediapicker)

Renders the inputs required for a Wordpress media picker, with a preview of the currently selected medium.

For this to work, make sure the WP media scripts are enqueued. If you're using [`gebruederheitz/wp-easy-cpt`](https://packagist.org/packages/gebruederheitz/wp-easy-cpt)this is easily achieved by setting `protected $withMedia = true;` on your `PostType` implementation. Otherwise you will need to add a callback to the appropriate action hook:

```
class UsesMetaForms
{
    public function __construct()
    {
        add_action('admin_enqueue_scripts', [$this, 'onAdminEnqueueScripts']);
    }

    public function onAdminEnqueueScripts()
    {
        wp_enqueue_media();
    }
}
```

##### `MetaForms::renderMediaPicker()`

[](#metaformsrendermediapicker)

ParameterTypeDescriptionidFieldNamestringIdentifier for the field, storing the attachment ID of the selected media. You will use this value to read the $\_POSTed data back from the form. Required.idFieldValue?intAttachment ID of the selected media.urlFieldNameIdentifier for the field, storing the public URL for the selected media. You will use this value to read the $\_POSTed data back from the form. Required.urlFieldValue?stringPublic URL of the selected media.labelstringText content of the associated `` element. Default `'Image'`.showLabelbooleanWhether to display the label or not. Default `true`.### Using custom templates

[](#using-custom-templates)

You can override the default templates provided by simply putting a template file with the correct name into `template-parts/meta/forms/` within your theme's root directory:

Input typeTemplate nameText / Default`input-field-text.php`Number`input-field-text.php`Textarea`textarea.php`Media picker`media-picker.php`#### Customizing the template override location

[](#customizing-the-template-override-location)

If you want to use a custom location (other than `template-parts/meta/forms/`) you can provide your own override base path using one of the singleton's setter methods. You can not change the names of the template files.

```
// Make sure to end with a trailing slash
MetaForms::updateOverridePath('partials/vendor/gebruederheitz/meta-forms/override/')
// or
MetaForms::getInstance()->setOverridePath('partials/vendor/gebruederheitz/meta-forms/override/');
```

Development
-----------

[](#development)

### Dependencies

[](#dependencies)

- PHP &gt;= 7.4
- [Composer 2.x](https://getcomposer.org)
- [NVM](https://github.com/nvm-sh/nvm) and nodeJS LTS (v16.x)
- Nice to have: GNU Make (or drop-in alternative)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.2% 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 ~39 days

Recently: every ~0 days

Total

19

Last Release

855d ago

PHP version history (2 changes)v1.0.0PHP ^7.3

v1.0.2PHP &gt;=7.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/d2a201d58341e3ed71321bcb66cb375a8c6efffce7d8fe33244e821afc087c78?d=identicon)[mediocrity](/maintainers/mediocrity)

---

Top Contributors

[![AndreasMaros](https://avatars.githubusercontent.com/u/25008845?v=4)](https://github.com/AndreasMaros "AndreasMaros (41 commits)")[![MrMediocresTestAccount](https://avatars.githubusercontent.com/u/63109795?v=4)](https://github.com/MrMediocresTestAccount "MrMediocresTestAccount (6 commits)")

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gebruederheitz-wp-meta-fields/health.svg)

```
[![Health](https://phpackages.com/badges/gebruederheitz-wp-meta-fields/health.svg)](https://phpackages.com/packages/gebruederheitz-wp-meta-fields)
```

###  Alternatives

[ycodetech/valet-windows

A more enjoyable local development experience for Windows. A Windows port of the popular Laravel Valet and a fork of cretueusebiu/valet-windows, with new features.

451.6k](/packages/ycodetech-valet-windows)[log1x/acf-move-wp-editor

A simple ACF Field that moves the WordPress content editor of a post or page to the location of this field.

361.1k](/packages/log1x-acf-move-wp-editor)

PHPackages © 2026

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