This is a WordPress plugin. [Official download available on WordPress.org](http://wordpress.org/extend/plugins/attachments/). ## [Docs TOC](TOC.md) / Usage Attachments is based on *instances* which correlate directly with the meta boxes that appear on edit screens of Posts, Pages, and Custom Post Types. By default Attachments ships with a single meta box that appears *only on Posts and Pages*. It has two fields: one for Title and one for Caption. If you would like to disable or customize the default instance, or you'd like to create additional instances with custom fields for different post types, please see [Setting Up Instances](#setting-up-instances). ### Disable Settings Screen Attachments ships with a `Settings` screen (found under the `Settings` menu in the main WordPress admin navigation) that facilitates data migration from version 1.x and also offers some code snippets. If you would like to **disable the Settings screen** add the following to your theme's `functions.php`: ```php define( 'ATTACHMENTS_SETTINGS_SCREEN', false ); // disable the Settings screen ``` ### Setting Up Instances When Attachments is first activated, a default instance is created titled Attachments. It has two fields: 1. Title 1. Caption #### Disable the Default Instance If you would like to *disable the default instance* (meta box titled 'Attachments' with a 'Title' and 'Caption' field) add the following to your `wp-config.php` *before* `require_once(ABSPATH . 'wp-settings.php');`: ```php define( 'ATTACHMENTS_DEFAULT_INSTANCE', false ); ``` #### Create Custom Instances You may create instances with your own custom fields by using the `attachments_register` action. To create your own instance add the following to your theme's `functions.php` or your own plugin: ```php 'title', // unique field name 'type' => 'text', // registered field type 'label' => __( 'Title', 'attachments' ), // label to display 'default' => 'title', // default value upon selection ), array( 'name' => 'caption', // unique field name 'type' => 'textarea', // registered field type 'label' => __( 'Caption', 'attachments' ), // label to display 'default' => 'caption', // default value upon selection ), ); $args = array( // title of the meta box (string) 'label' => 'My Attachments', // all post types to utilize (string|array) 'post_type' => array( 'post', 'page' ), // meta box position (string) (normal, side or advanced) 'position' => 'normal', // meta box priority (string) (high, default, low, core) 'priority' => 'high', // allowed file type(s) (array) (image|video|text|audio|application) 'filetype' => null, // no filetype limit // include a note within the meta box (string) 'note' => 'Attach files here!', // by default new Attachments will be appended to the list // but you can have then prepend if you set this to false 'append' => true, // text for 'Attach' button in meta box (string) 'button_text' => __( 'Attach Files', 'attachments' ), // text for modal 'Attach' button (string) 'modal_text' => __( 'Attach', 'attachments' ), // which tab should be the default in the modal (string) (browse|upload) 'router' => 'browse', // fields array 'fields' => $fields, ); $attachments->register( 'my_attachments', $args ); // unique instance name } add_action( 'attachments_register', 'my_attachments' ); ``` #### Fields Reference At this time there are **four** field types available: 1. `text` 1. `textarea` 1. `select` 1. `wysiwyg` When declaring fields for your instance, you'll be composing an array of fields, each with an array of parameters that set the various attributes of each field. Here is a full example of all available parameters for all available fields: ```php /** * Fields for the instance are stored in an array. Each field consists of * an array with three required keys: name, type, label * and one optional key: meta * * name - (string) The field name used. No special characters. * type - (string) The registered field type. * Fields available: text, textarea, wysiwyg, select * label - (string) The label displayed for the field. * default - (string) The default WordPress metadata to use when initially adding the Attachment * Defaults available: title, caption, alt, description * meta - (array) The field-specific parameters that apply only to that field type */ $fields = array( array( 'name' => 'title', // unique field name 'type' => 'text', // registered field type 'label' => __( 'Title', 'attachments' ), // label to display 'default' => 'title', // default value upon selection ), array( 'name' => 'caption', // unique field name 'type' => 'textarea', // registered field type 'label' => __( 'Caption', 'attachments' ), // label to display 'default' => 'caption', // default value upon selection ), array( 'name' => 'option', // unique field name 'type' => 'select', // registered field type 'label' => __( 'Option', 'attachments' ), // label to display 'meta' => array( // field-specific meta as defined by field class 'allow_null' => true, // allow null value? (adds 'empty'