@wordpress/fields

This package provides core elements for the DataView library, designed to simplify the creation and management of data display elements in WordPress.

Installation

Install the module

npm install @wordpress/fields --save

Setup

This package requires CSS from this package and from multiple dependency packages.

Within WordPress

To ensure proper load order, add the wp-components stylesheet as a dependency of your plugin’s stylesheet. See wp_enqueue_style documentation for how to specify dependencies.

WordPress registers no handle for this package’s own stylesheet, so load it with your plugin’s script:

import '@wordpress/fields/build-style/style.css';

Outside WordPress

Install and load these stylesheets in your application:

npm install @wordpress/fields @wordpress/theme @wordpress/components
import '@wordpress/theme/design-tokens.css';
import '@wordpress/components/build-style/style.css';
import '@wordpress/fields/build-style/style.css';

RTL versions of the stylesheets are available in the same paths, but with -rtl appended to the filename (style-rtl.css). The design tokens stylesheet is universal and does not have a separate RTL version.

Usage

authorField

Author field for BasePost.

BasePost

Undocumented declaration.

BasePostWithEmbeddedAuthor

Undocumented declaration.

commentStatusField

Comment status field for BasePost.

CreateTemplatePartModal

A React component that renders a modal for creating a template part. The modal displays a title and the contents for creating the template part. This component should not live in this package, it should be moved to a dedicated package responsible for managing template.

Parameters

  • props { modalTitle?: string; } & CreateTemplatePartModalContentsProps: The component props.
  • props.modalTitle { modalTitle?: string; } & CreateTemplatePartModalContentsProps[ 'modalTitle' ]:

dateField

Date field for BasePost.

deletePost

Delete action for Templates, Patterns and Template Parts.

descriptionField

Description field for templates.

discussionField

Discussion field for BasePost with custom render logic.

duplicatePattern

Duplicate action for Pattern.

duplicatePost

Duplicate action for BasePost.

duplicateTemplatePart

Duplicate action for TemplatePart.

excerptField

Excerpt field for BasePost.

exportPattern

Export action as JSON for Pattern.

featuredImageField

Featured Image field for BasePostWithEmbeddedFeaturedMedia.

formatField

Format field for BasePost.

lastEditedDateField

Last edited date field for BasePost.

MediaEdit

A media edit control component that provides a media picker UI with upload functionality for selecting WordPress media attachments. Supports both the traditional WordPress media library and the experimental DataViews media modal.

This component is intended to be used as the Edit property of a field definition when registering fields with registerEntityField from @wordpress/editor.

Usage