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 )
- 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”
- define new post types
- alter the definition of existing post types
- define fields
- define taxonomies
- define field and taxonomy relationships to post types
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