acf-custom-field-type
/acf-custom-field-type
Builds and reviews custom Advanced Custom Fields field types on the Free acf_field extension API. Covers acf/include_field_types registration, initialize metadata, settings and input rendering, dynamic input names, validation, load/update/format transforms, field-aware HTML escaping, assets, REST visibility, and repeater-compatible JavaScript initialization. Use when a built-in ACF field cannot represent the editor control or stored value, when extending acf_field, or when a custom field saves correctly but formats, validates, repeats, or renders unsafely.
- Author
- Lonsdale201 ↗
- Repository
- wp-agent-skills ↗
- Licence
- MIT
- Last repository change
- 20.10.2026
Assessment and security
- Files in this package
- 2
- Scripts
- 0
- HTML comments
- 0
- URLs in SKILL.md
- 4
No signals detected. Repository changed on 20.10.2026, without references to retired models or APIs.
MIT, open: use and modify while retaining author attribution.
What it does and when to use it
Builds and reviews custom Advanced Custom Fields field types on the Free acf_field extension API. Covers acf/include_field_types registration, initialize metadata, settings and input rendering, dynamic input names, validation, load/update/format transforms, field-aware HTML escaping, assets, REST visibility, and repeater-compatible JavaScript initialization. Use when a built-in ACF field cannot represent the editor control or stored value, when extending acf_field, or when a custom field saves correctly but formats, validates, repeats, or renders unsafely.
Original author description
Builds and reviews custom Advanced Custom Fields field types on the Free acf_field extension API. Covers acf/include_field_types registration, initialize metadata, settings and input rendering, dynamic input names, validation, load/update/format transforms, field-aware HTML escaping, assets, REST visibility, and repeater-compatible JavaScript initialization. Use when a built-in ACF field cannot represent the editor control or stored value, when extending acf_field, or when a custom field saves correctly but formats, validates, repeats, or renders unsafely.
How it works
- Register after the field API exists
- Define the field contract
- Separate the value stages
- HTML escaping support
- Assets and dynamic inputs
- Verify the field type
- Cross-references
- References
SKILL.md preview
---
name: acf-custom-field-type
description: >-
Builds and reviews custom Advanced Custom Fields field types on the Free
acf_field extension API. Covers acf/include_field_types registration,
initialize metadata, settings and input rendering, dynamic input names,
validation, load/update/format transforms, field-aware HTML escaping, assets,
REST visibility, and repeater-compatible JavaScript initialization. Use when a
built-in ACF field cannot represent the editor control or stored value, when
extending acf_field, or when a custom field saves correctly but formats,
validates, repeats, or renders unsafely.
metadata:
wp-skills-author: "Soczó Kristóf"
wp-skills-contact: "https://github.com/Lonsdale201"
wp-skills-plugin: "advanced-custom-fields"
wp-skills-plugin-version-tested: "6.8.10"
wp-skills-wp-version-tested: "7.1.2"
wp-skills-php-min: "7.4"
wp-skills-last-updated: "2026-09-26"
---
# ACF custom field type
The `acf_field` extension API is available in ACF Free and PRO. A custom field
type should solve a distinct input/value contract, not merely restyle a Text or
Select field. Prefer a built-in field plus targeted filters when its raw value,
validation, and return format already fit.
## Register after the field API exists
```php
add_action( 'acf/include_field_types', static function ( $api_version ): void {
if ( ! class_exists( 'acf_field' ) ) {
return;
}
require_once __DIR__ . '/includes/class-acme-acf-field-json.php';
acf_register_field_type( 'Acme_ACF_Field_JSON' );
} );
```
Keep registration idempotent and feature-detect ACF. The hook receives ACF's
field API version; do not confuse it with the plugin version.
In ACF 6.8.10 the base constructor calls `initialize()`. Set properties there
instead of replacing `__construct()` and accidentally skipping base hook
registration.
## Define the field contract
```php
final class Acme_ACF_Field_JSON extends acf_field {
public function initialize() {
$this->name = 'acme_json';
$this->label = __( 'JSON object', 'acme-addon' );
$this->category = 'advanced';
$this->description = __( 'Stores a validated JSON object.', 'acme-addon' );
$this->defaults = array(
'rows' => 8,
);
$this->show_in_rest = true;
}
public function render_field_settings( $field ) {
acf_render_field_setting( $field, array(
'label' => __( 'Rows', 'acme-addon' ),
'name' => 'rows',
'type' => 'number',
'min' => 3,
) );
}
public function render_field( $field ) {
$value = is_array( $field['value'] )
? wp_json_encode( $field['value'], JSON_PRETTY_PRINT )
: (string) $field['value'];
printf(
'<textarea name="%s" rows="%d">%s</textarea>',
esc_attr( $field['name'] ),
max( 3, (int) $field['rows'] ),
esc_textarea( $value )
);
}
public function validate_value( $valid, $value, $field, $input ) {
if ( true !== $valid || '' === $value || is_array( $value ) ) {
return $valid;
}
json_decode( (string) $value, true );
return JSON_ERROR_NONE === json_last_error()
? true
: __( 'Enter valid JSON.', 'acme-addon' );
}
public function update_value( $value, $post_id, $field ) {
if ( is_array( $value ) || '' === $value || null === $value ) {
return $value;
}
$decoded = json_decode( (string) $value, true );
return JSON_ERROR_NONE === json_last_error() ? $decoded : null;
}
}
```
Always use `$field['name']` in the input. ACF rewrites it for Group, Repeater,
Flexible Content, Clone, AJAX append, and row indexes. A hardcoded input name or
DOM ID works once at top level and then silently collides in nested fields.
## Separate the value stages
| Method | Stage | Appropriate work |
|---|---|---|
| `validate_value()` | before save acceptance | reject invalid input with `true` or a translated error string |
| `update_value()` | before raw storage | normalize to the canonical database shape |
| `load_value()` | after raw load | compatibility repair for historical raw values; keep it cheap |
| `format_value()` | template/API formatting | return the documented consumer shape; honor `$escape_html` if supported |
| `delete_value()` | after deletion | remove auxiliary rows owned only by this field type |
Keep these methods pure where possible. A formatter can run more than once and
is cached by ACF per request. Do not send HTTP requests, mutate other content, or
perform unbounded queries while formatting a value.
The base ACF value pipeline stores the field's raw value and hidden field-key
reference after `update_value()` runs. A custom type normally should not call
`update_post_meta()` itself. If the type owns auxiliary rows, namespace them and
delete them consistently for posts, users, terms, comments, and options—not just
post meta.
## HTML escaping support
Set `$this->supports['escaping_html'] = true` only when `format_value()` returns a
safe value whenever its fourth `$escape_html` argument is true.
```php
public function initialize() {
// Other properties...
$this->supports = array(
'escaping_html' => true,
'required' => true,
);
}
public function format_value( $value, $post_id, $field, $escape_html = false ) {
$value = (string) $value;
return $escape_html ? acf_esc_html( $value ) : $value;
}
```
Do not mark support merely because `render_field()` escapes admin markup. The
flag describes frontend/template formatting of stored values, including values
modified directly in the database.
## Assets and dynamic inputs
Register and enqueue admin assets in `input_admin_enqueue_scripts()`, with unique
handles and a real plugin version. Scope CSS to the field wrapper. JavaScript
must initialize fields appended after page load by Repeaters, Flexible Content,
Clone, modals, and AJAX; use ACF's field lifecycle instead of a one-time document
ready scan. Destroy third-party widgets when rows are removed to prevent leaked
listeners and duplicate instances.
Do not enqueue frontend assets unless the field's formatted output actually
needs them. A field editor control and its frontend presentation are separate
features.
## Verify the field type
1. Create, edit, clear, and delete the value on a normal post.
2. Repeat on every supported location: user, term, comment, or options.
3. Test valid, invalid, empty, array, and historical raw values.
4. Insert multiple field instances and nested Repeater/Group/Clone instances.
5. Duplicate, reorder, append, and remove dynamic rows in the editor.
6. Compare raw metadata, formatted `get_field()`, and escaped reads.
7. Test REST only when `show_in_rest` is intended.
8. Verify behavior with ACF Free and PRO separately when both are supported.
The `acf-value-storage-frontend` smoke example includes a minimal custom JSON
field and verifies its `update_value()` and formatted read on ACF PRO 6.8.10.
## Cross-references
- `acf-value-storage-frontend` for the base storage/reference pipeline.
- `acf-field-group-development` for definitions that consume the new type.
- `acf-pro-complex-fields` for nested dynamic-field behavior under PRO fields.
## References
- [Official custom field type guide](https://www.advancedcustomfields.com/resources/creating-a-new-field-type/).
- [Official example field type repository](https://github.com/AdvancedCustomFields/acf-example-field-type).
- [Official HTML escaping guide](https://www.advancedcustomfields.com/resources/html-escaping/).
- Verified ACF 6.8.10 source paths:
- `acf.php`
- `includes/fields.php`
- `includes/fields/class-acf-field.php`
- `includes/acf-value-functions.php`
- `includes/validation.php`
Files in this package (2)
- SKILL.md 8 KB
- agents/openai.yaml 1 KB
Versions
The database has no other skills named acf-custom-field-type.
Database snapshot: 13.11.2026 · package version 1ec0df5b07b6 (SHA-256 digest of the entire package)
Downloads in the last 30 days: 0 · ranking
Similar skills
- 90wordpress-acf-ops
Use when reading or updating Advanced Custom Fields (ACF) values on a WordPress site: custom fields, field groups, custom post types and taxonomies over the REST API. - 100acf-field-group-development
Builds and reviews Advanced Custom Fields field groups defined in PHP or Local JSON. Covers stable group and field keys, storage names, acf/init timing, location rules, REST exposure, plugin-owned JSON paths, deployment, and Free versus PRO field availability. Use when adding a… - 100wp-acf-and-content-modeling
WordPress ACF and content modeling review. Use when reviewing Advanced Custom Fields usage, field group architecture, CPT and taxonomy design, options pages, repeaters, flexible content, block-bound field groups, meta storage patterns, or when user mentions "ACF", "field… - 100acf-value-storage-frontend
Implements and diagnoses Advanced Custom Fields value storage, programmatic writes, database inspection, and frontend rendering. Covers the value row plus hidden field-key reference, post/user/term/comment/options targets, field-key first writes, raw versus formatted get_field… - 100acf-native
Use when building or reviewing ACF field behaviour or the post save flow - validate before publish, required/maxlength settings, hiding a field (conditional_logic), dynamic choices, running code after save - acf/validate_value, acf/load_field, acf/prepare_field, acf/save_post,… - 90wp-acf-and-content-modeling
WordPress ACF and content modeling review for Codex. Use when reviewing ACF field groups, CPT and taxonomy design, options pages, repeaters, flexible content, relationship fields, ACF JSON sync, and meta-heavy content architecture.