Class: Attachments

wp.media.model. Attachments


new Attachments( [models] [, options])

wp.media.model.Attachments A collection of attachments. This collection has no persistence with the server without supplying 'options.props.query = true', which will mirror the collection to an Attachments Query collection - @see wp.media.model.Attachments.mirror().
Parameters:
Name Type Argument Description
models array <optional>
Models to initialize with the collection.
options object <optional>
Options hash for the collection.
Properties
Name Type Argument Description
props string <optional>
Options hash for the initial query properties.
Properties
Name Type Argument Description
order string <optional>
Initial order (ASC or DESC) for the collection.
orderby string <optional>
Initial attribute key to order the collection by.
query string <optional>
Whether the collection is linked to an attachments query.
observe string <optional>
filters string <optional>
Source:

Extends

  • Backbone.Collection

Namespaces

filters

Members


model :wp.media.model.Attachment

Type:
Source:

Methods


<static> comparator(a, b, options)

A function to compare two attachment models in an attachments collection. Used as the default comparator for instances of wp.media.model.Attachments and its subclasses. @see wp.media.model.Attachments._changeOrderby().
Parameters:
Name Type Description
a Backbone.Model
b Backbone.Model
options Object
Source:
Returns:
-1 if the first model should come before the second, 0 if they are of the same rank and 1 if the first model should come after.
Type
Number

hasMore()

Whether there are more attachments that haven't been sync'd from the server that match the collection's query. Only works if the collection is mirroring a Query Attachments collection, and forwards to its `hasMore` method. This collection class doesn't have server persistence by itself.
Source:
Returns:
Type
boolean

initialize( [models] [, options])

Parameters:
Name Type Argument Default Description
models Array <optional>
[] Array of models used to populate the collection.
options Object <optional>
{}
Source:

mirror(The)

Start mirroring another attachments collection, clearing out any models already in the collection.
Parameters:
Name Type Description
The wp.media.model.Attachments attachments collection to mirror.
Source:
Returns:
Returns itself to allow chaining
Type
wp.media.model.Attachments

more(options)

Retrieve more attachments from the server for the collection. Only works if the collection is mirroring a Query Attachments collection, and forwards to its `more` method. This collection class doesn't have server persistence by itself.
Parameters:
Name Type Description
options object
Source:
Returns:
Type
Promise

observe(The)

Start observing another attachments collection change events and replicate them on this collection.
Parameters:
Name Type Description
The wp.media.model.Attachments attachments collection to observe.
Source:
Returns:
Returns itself to allow chaining.
Type
wp.media.model.Attachments

parse(resp, xhr)

A custom AJAX-response parser. See trac ticket #24753
Parameters:
Name Type Description
resp Object | Array The raw response Object/Array.
xhr Object
Source:
Returns:
The array of model attributes to be added to the collection
Type
Array

saveMenuOrder()

If this collection is sorted by `menuOrder`, recalculates and saves the menu order to the database.
Source:
Returns:
Type
undefined | Promise

unmirror()

Stop mirroring another attachments collection.
Source:

unobserve(The)

Stop replicating collection change events from another attachments collection.
Parameters:
Name Type Description
The wp.media.model.Attachments attachments collection to stop observing.
Source:
Returns:
Returns itself to allow chaining
Type
wp.media.model.Attachments

validate(attachment, options)

Add or remove an attachment to the collection depending on its validity.
Parameters:
Name Type Description
attachment wp.media.model.Attachment
options Object
Source:
Returns:
Returns itself to allow chaining
Type
wp.media.model.Attachments

validateAll(attachments [, options])

Add or remove all attachments from another collection depending on each one's validity.
Parameters:
Name Type Argument Default Description
attachments wp.media.model.Attachments
options object <optional>
{}
Source:
Fires:
  • wp.media.model.Attachments#event:reset
Returns:
Returns itself to allow chaining
Type
wp.media.model.Attachments

validator(attachment)

Checks whether an attachment is valid.
Parameters:
Name Type Description
attachment wp.media.model.Attachment
Source:
Returns:
Type
Boolean