There’s a new post on Make WordPress Core announcing a meeting to gather the requirements for a new plugin that will provide APIs for developers to define and manage post meta data. I’ve tried to reply to this post three times. Each time my response seems to have disappeared into the bit bucket. So here we go again…
Background
- WordPress provides some basic APIs that allow programmers to manage meta data related to a post.
- There are a number of plugins that provide generic solutions enabling developers to provide “fields” of specific “types” which can be associated with any WordPress post type.
- Other plugins use meta data to store information that is required in one part of the system but not necessarily displayed to end users.
- There are also plugins that allow manipulation of fields through the UI.
- But there is not a common solution.
Functional Requirements
In my opinion the functional requirements for a core post meta plugin are:
- Provide APIs to register fields and associate them to post types
- Provide APIs to display and save post meta data
- Provide APIs for custom column display, filtering and sorting
- Deliver an extensible architecture – allowing any number of different field types to be created
- Provide the ability to extend or alter post types and fields created by other plugins
- Allow fields to be displayed in multiple contexts e.g. as input fields on forms (admin and front-end), as read only output on a website, in the contents of an email, etcetera
- Support fields associated with post types including attachments, users, taxonomies and possibly even comments
- Support grouping of fields, using multiple meta boxes, if required
- Support repeatable fields
oik-plugins approach
The oik base plugin provides
- Simple generic APIs for registering fields and associating them to post types.
- Generic APIs to display and save post meta data ( admin )
The oik-fields plugin, dependent upon oik, provides
- APIs and shortcodes to display fields in the front-end
- APIs and shortcodes to display and process front-end forms
- A basic set of field “types”
The oik-types plugin, dependent upon oik-fields, provides a UI to allow an admin user to
- define new post types
- alter the definition of existing post types
- define fields
- define taxonomies
- define field and taxonomy relationships to post types
Other plugins, e.g. oik user, implement the oik-fields APIs and hooks to extend the field types; oik-user provides the “userref” field type.
Non functional requirements
Include, but not limited to.
- Easy to use, generic APIs, with well defined, sensible defaults
- Highly performant:
- do not waste time doing work that is not required. e.g. Leave l10n until the translated text is actually required.
- minimum database access
- Secure: nonce checking, validation and sanitization
- Any user defined definitions to be exportable and importable
- Support WordPress Multisite
- Use serialized data when necessary
Further reading
APIs
- bw_register_field() – Register a field named $field_name of type $field_type with title $field_title and additional values $args
- bw_register_field_for_object_type() – Register a field named $field_name for object type $object_type
- bw_effort_box() – Create fields in the meta box to accept data for the fields
- bw_effort_save_postdata() – Saves the custom fields for this post when called for the ‘save_post’ action
- bw_form_field() – Display a field in a form for the user to enter/choose a value
- bw_theme_field() – Theme a custom field
Shortcodes
Plugins
Original post and comments
http://make.wordpress.org/core/2013/11/25/post-meta-team-introductory-meeting/