name = sanitize_title( $name ); $this->label = __( esc_attr( $label) ); $this->value = $value; $this->default = ''; $this->meta = $meta; $this->defaults = array( 'title', 'caption', 'alt', 'description' ); // WordPress-specific Media meta // TODO: determine how to integrate with custom metadata that was added to Media } /** * Sets the field instance * @param string $instance The instance name * @param Attachments_Field $field The field object */ function set_field_instance( $instance, $field ) { $field->instance = $instance; } /** * Sets the UID, name, and id of the field * @param Attachments_Field $field The field object * @param string $uid Existing UID if applicable */ function set_field_identifiers( $field, $uid = null ) { // we MUST have an instance if ( empty( $field->instance ) ) { return false; } // if we're pulling an existing Attachment (field has a value) we're going to use // a PHP uniqid to set up our array flags but if we're setting up our Underscore // template we need to use a variable flag to be processed later $this->uid = ! is_null( $uid ) ? $uid : '{{ attachments.attachment_uid }}'; // set the name $field->field_name = "attachments[$field->instance][$this->uid][fields][$field->name]"; // set the id $field->field_id = $this->field_name . $this->uid; } /** * Sets the field type of the field * @param string $field_type Registered field type name */ function set_field_type( $field_type ) { $this->type = $field_type; } /** * Sets the WordPress meta attribute to be used as the default * @param string $default One of the approved defauls (title, caption, alt, description) */ function set_field_default( $default = '' ) { if ( is_string( $default ) && ! empty( $default ) && in_array( strtolower( $default ), $this->defaults ) ) { $this->default = strtolower( $default ); } } /** * Outputs the HTML for the field * @param Attachments_Field $field The field object * @return void */ abstract public function html( $field ); /** * Filter the field value to appear within the input as expected * @param string $value The field value * @param Attachments_field $field The field object * @return string The formatted value */ abstract public function format_value_for_input( $value, $field = null ); /** * Fires once per field type per instance and outputs any additional assets (e.g. external JavaScript) * @return void */ abstract public function assets(); /** * Hook into WordPress' init action * @return void */ abstract public function init(); } endif; // class_exists check