Skip to content

Repository files navigation

WPify Custom Fields

PHP 8.1+WordPress 6.2+LicensePackagist Version

A developer-oriented WordPress library for custom fields. 59 field types, 15 integration points (metaboxes, options pages, taxonomies, users, Gutenberg blocks, WooCommerce products/orders/coupons, and more), zero PHP dependencies, native WordPress storage — values are plain get_post_meta() / get_option() calls with no proprietary getters.

Quick Start

// Register a metabox with custom fields.wpify_custom_fields()->create_metabox(
array(
'id' => 'project_details',
'title' => __( 'Project Details', 'my-plugin' ),
'post_types' => array( 'post' ),
'items' => array(
'project_name' => array(
'type' => 'text',
'label' => __( 'Project Name', 'my-plugin' ),
'required' => true,
),
'budget' => array(
'type' => 'number',
'label' => __( 'Budget', 'my-plugin' ),
),
'is_featured' => array(
'type' => 'toggle',
'label' => __( 'Featured', 'my-plugin' ),
'title' => __( 'Show on the homepage', 'my-plugin' ),
),
'cover_image' => array(
'type' => 'attachment',
'label' => __( 'Cover Image', 'my-plugin' ),
'conditions' => array(
array( 'field' => 'is_featured', 'value' => true ),
),
),
),
)
);

Reading values — standard WordPress functions, no proprietary API required:

$name = get_post_meta( $post_id, 'project_name', true );
$image = get_post_meta( $post_id, 'cover_image', true ); // Attachment ID.

Why This Library

  • 59 field types in 6 categories — from simple inputs to repeaters, groups, maps, code editors, and more
  • 15 integration points — post metaboxes, options pages, taxonomies, users, comments, menu items, Gutenberg blocks, WooCommerce products/variations/orders/coupons/settings/subscriptions/memberships, multisite
  • Native WordPress storage — uses post_meta, term_meta, options, block attributes; no custom tables, no lock-in
  • Zero PHP dependencies — a single Composer package, nothing extra to manage
  • Modern stack — PHP 8.1+ with strict typing, React 18 UI, container queries, CSS custom properties
  • Conditional logic — show/hide fields with 12 operators, AND/OR groups, nested conditions, dot-notation paths
  • Fluent FieldFactory API — IDE-friendly PHP 8 named parameters with full autocomplete
  • Extensible — register custom field types via PHP filters and JS hooks

Field Types

Simple (22)

TypeDescription
textSingle-line text input
textareaMulti-line text input
numberNumeric input with min/max/step
emailEmail address input
passwordPassword input
telPhone number input
urlURL input
dateDate picker
datetimeDate and time picker
timeTime picker
monthMonth picker
weekWeek picker
date_rangeStart and end date pair
selectDropdown select (sync or async options)
multi_selectMultiple selection dropdown
radioRadio button group
checkboxSingle checkbox
multi_checkboxCheckbox group
toggleOn/off switch
multi_toggleToggle group
colorColor picker
rangeRange slider

Relational (10)

TypeDescription
postSingle post selector
multi_postMultiple post selector
termSingle term selector
multi_termMultiple term selector
attachmentMedia library file picker
multi_attachmentGallery / multiple files
direct_fileDirect file upload (no media library)
multi_direct_fileMultiple direct file uploads
linkLink with URL, title, and target
multi_linkMultiple links

Complex (6)

TypeDescription
groupField group (nested fields)
cloudflareCloudflare zone connection
codeCode editor with syntax highlighting
wysiwygTinyMCE rich text editor
mapyczMapy.cz map with coordinates
inner_blocksGutenberg InnerBlocks

Repeater (14)

TypeDescription
multi_groupRepeatable field group
multi_textRepeatable text
multi_textareaRepeatable textarea
multi_numberRepeatable number
multi_emailRepeatable email
multi_telRepeatable phone
multi_urlRepeatable URL
multi_dateRepeatable date
multi_datetimeRepeatable datetime
multi_timeRepeatable time
multi_monthRepeatable month
multi_weekRepeatable week
multi_date_rangeRepeatable date range
multi_mapyczRepeatable map

Static (5)

TypeDescription
htmlCustom HTML content
buttonAction button
multi_buttonButton group
titleSection title / heading
hiddenHidden input

Visual (2)

TypeDescription
wrapperVisual wrapper around fields
columnsMulti-column layout

Integration Points

WordPress Core

MethodContext
create_metabox()Post / CPT meta box
create_gutenberg_block()Gutenberg block
create_options_page()Admin options page
create_taxonomy_options()Taxonomy term fields
create_user_options()User profile fields
create_comment_metabox()Comment meta fields
create_menu_item_options()Nav menu item fields

WooCommerce

MethodContext
create_product_options()Product data tab
create_product_variation_options()Product variation fields
create_order_metabox()Order meta box (HPOS compatible)
create_woocommerce_settings()WooCommerce settings tab
create_coupon_options()Coupon fields
create_subscription_metabox()Subscription meta box
create_membership_plan_options()Membership plan fields

Multisite

MethodContext
create_site_options()Site options page

All methods are called on the wpify_custom_fields() singleton instance.

Features

Conditional Logic

Show or hide fields based on other field values:

'show_subtitle' => array(
'type' => 'toggle',
'label' => __( 'Show Subtitle', 'my-plugin' ),
),
'subtitle' => array(
'type' => 'text',
'label' => __( 'Subtitle', 'my-plugin' ),
'conditions' => array(
array( 'field' => 'show_subtitle', 'value' => true ),
),
),

Supported operators: ==, !=, >, >=, <, <=, between, contains, not_contains, in, not_in, empty, not_empty. Conditions support AND/OR logic, nested groups, and dot-notation paths for nested fields.

Tabs

Organize fields into a tabbed interface:

wpify_custom_fields()->create_metabox(
array(
'id' => 'my_metabox',
'title' => __( 'Settings', 'my-plugin' ),
'tabs' => array(
'general' => __( 'General', 'my-plugin' ),
'advanced' => __( 'Advanced', 'my-plugin' ),
),
'items' => array(
'title' => array(
'type' => 'text',
'label' => __( 'Title', 'my-plugin' ),
'tab' => 'general',
),
'custom_css' => array(
'type' => 'code',
'label' => __( 'Custom CSS', 'my-plugin' ),
'language' => 'css',
'tab' => 'advanced',
),
),
)
);

Fluent FieldFactory API

Build field definitions with PHP 8 named parameters and full IDE autocomplete:

$f = wpify_custom_fields()->field_factory;
wpify_custom_fields()->create_metabox(
array(
'id' => 'team_metabox',
'title' => __( 'Team', 'my-plugin' ),
'post_types' => array( 'page' ),
'items' => array(
'team_members' => $f->multi_group(
label: __( 'Team Members', 'my-plugin' ),
min: 1,
max: 20,
items: array(
'name' => $f->text( label: __( 'Name', 'my-plugin' ), required: true ),
'role' => $f->text( label: __( 'Role', 'my-plugin' ) ),
'photo' => $f->attachment( label: __( 'Photo', 'my-plugin' ), attachment_type: 'image' ),
),
),
),
)
);

Extensibility

  • PHP filters: wpifycf_sanitize_{type}, wpifycf_wp_type_{type}, wpifycf_default_value_{type}, wpifycf_items
  • JS hooks (@wordpress/hooks): wpifycf_field_{type}, wpifycf_definition, wpifycf_generator_{name}

See the Extending documentation for a full guide on creating custom field types.

Installation

Via Composer (Recommended)

composer require wpify/custom-fields

Include the Composer autoloader in your plugin or theme:

require_once__DIR__ . '/vendor/autoload.php';

As a WordPress Plugin

Download from the Releases page, upload to /wp-content/plugins/, and activate.

Requirements

  • PHP 8.1+
  • WordPress 6.2+
  • ext-json
  • Modern browser (Chrome, Firefox, Safari, Edge)
  • WooCommerce 8.0+ (optional, for WooCommerce integrations)

Documentation

License

WPify Custom Fields is released under the GPL-3.0-or-later license.

About

No description, website, or topics provided.

Resources

Stars

13 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages