You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Field Factory provides a fluent, IDE-friendly PHP API for building field definition arrays. Instead of writing associative arrays by hand, you can use named parameters with full autocomplete and type checking in your IDE.
Overview
The Field Factory is a stateless helper that exposes one method per field type. Each method returns a plain array that is fully compatible with the existing items structure. You can mix Field Factory calls with hand-written arrays freely.
Getting Started
Access the Field Factory via the field_factory property on the main CustomFields instance:
$custom_fields = new \Wpify\CustomFields\CustomFields();
$f = $custom_fields->field_factory;
Or using the helper function:
$f = wpify_custom_fields()->field_factory;
Common Parameters
Every field method accepts these common parameters in addition to its type-specific ones:
Parameter
Type
Description
label
string|null
Field label displayed in the admin interface
description
string|null
Help text displayed below the field
required
bool|null
Whether the field must have a value
default
mixed
Default value for the field
disabled
bool|null
Whether the field is disabled
tab
string|null
Tab identifier for organizing fields
class_name
string|null
CSS class name (mapped to className in output)
conditions
array|null
Conditional display rules
attributes
array|null
HTML attributes for the field element
unfiltered
bool|null
Whether to skip sanitization
render_options
array|null
Options for customizing field rendering
generator
string|null
Generator identifier (e.g. 'uuid')
Parameters set to null are omitted from the output array, so only explicitly set values are included.
Accepts type-specific parameters first, followed by common parameters.
Calls build_field() which assembles a plain array with 'type' => '{type}' plus all non-null parameters.
Uses extract_common() to separate type-specific from common parameters and remap snake_case PHP names to camelCase JS keys (e.g., class_name → className, force_modal → forceModal).
Uses a sentinel value for the default parameter to distinguish "not passed" from "passed as null".
Notes
Field Factory returns plain arrays — the output is fully compatible with existing array-based definitions and can be mixed freely.
Only explicitly set parameters are included in the output. Passing null (the default for most parameters) omits the key entirely.
Use PHP 8.0+ named arguments for the best developer experience. Positional arguments also work but are less readable.
The $f->group() and $f->multi_group() methods require the items parameter.