wordpress-plugins/real-media-library/src/inc/apiattachment.php

In this file you will find attachment relevant functions.

DEFINED POST TYPES

 define('RML_TYPE_FOLDER', 0);
 define('RML_TYPE_COLLECTION', 1);
 define('RML_TYPE_GALLERY', 2);

==========================================

Example scenario #1:

  1. User navigates to /rml/collection1

  2. Use wp_rml_get_by_absolute_path("/collection1") to get the api\IFolder Object

  3. (Additional check) $folder->is(RML_TYPE_COLLECTION) to check, if it is a collection.

  4. Iterate the childrens with foreach ($folder->getChildren() as $value) { }

  5. In collection can only be other collections or galleries.

  6. (Additional check) $value->is(RML_TYPE_GALLERY) to check, if it is a gallery.

  7. Fetch the IDs with $value->read();

==========================================

If you want to use more functions look into the attachment\Structure Class. You easily get it with attachment\Structure::getInstance() (Singleton).

Meaning: Root = Unorganized Pictures

==========================================

ORDER QUERY

Using the custom order of galleries: In your get_posts() query args use the option "orderby" => "rml" to get the images ordered by custom user order.

==========================================

CUSTOM FIELDS FOR FOLDERS, COLLECTIONS, GALLERIES, ....

You want create your own custom fields for a rml object? Have a look at the metadata\Meta class.

Functions

wp_rml_get_attachments()

wp_rml_get_attachments(integer  $fid,string  $order = null,string  $orderby = null): null|array<mixed,integer>

Reads content of a folder.

Parameters

integer $fid

The folder id

string $order

The order statement

string $orderby

The order by statement

Returns

null|array<mixed,integer> —

Null if folder not exists or array of post ids

wp_attachment_folder()

wp_attachment_folder(integer  $attachmentId,integer  $default = null): integer|mixed

Returns the folder id of an given attachment or more than one attachment (array). If you pass an array as attachment ids, then the default value does not work, only for single queries. When you pass a shortcut attachment id, the folder id for the shortcut is returned.

Parameters

integer $attachmentId

The attachment ID, if you pass an array you get an array of folder IDs

integer $default

If no folder was found for this, this value is returned for the attachment

Returns

integer|mixed —

Folder ID or $default or Array

wp_attachment_order_update()

wp_attachment_order_update(integer  $folderId,integer  $attachmentId,integer  $nextId,integer  $lastIdInView = false): boolean

(Pro only) Moves an attachment before another given attachment in the order table.

Parameters

integer $folderId

The folder id where the attachment exists

integer $attachmentId

The attachment which should be moved

integer $nextId

The attachment next to the currentId, if it is false the currentId should be moved to the end of table.

integer $lastIdInView

If you have pagination, you can pass the last id from this view

Returns

boolean —

True or array with error strings

wp_rml_move()

wp_rml_move(integer  $to,array<mixed,integer>  $ids,boolean  $supress_validation = false,boolean  $isShortcut = false): boolean|array<mixed,string>

Move or create shortcuts of a set of attachments to a specific folder.

If you copy attachments, the action called is also "RML/Item/Move"... but there is a paramter $isShortcut.

Parameters

integer $to

Folder ID

array<mixed,integer> $ids

Array of attachment ids

boolean $supress_validation

Supress the permission validation

boolean $isShortcut

Determines, if the ID's are copies

Returns

boolean|array<mixed,string> —

True or Array with errors

wp_rml_create_shortcuts()

wp_rml_create_shortcuts(integer  $to,array<mixed,integer>  $ids,boolean  $supress_validation = false): boolean|array<mixed,string>

Link/Copy a set of attachments to a specific folder. When the folder has already a given shortcut, the movement for the given attachment will be skipped.

If you want to receive the last created shortcut ID's you can use the wp_rml_created_shortcuts_last_ids() function.

Parameters

integer $to

Folder ID, if folder not exists then root will be

array<mixed,integer> $ids

Array of attachment ids

boolean $supress_validation

Supress the permission validation

Returns

boolean|array<mixed,string> —

True or Array with errors

wp_rml_created_shortcuts_last_ids()

wp_rml_created_shortcuts_last_ids(): array<mixed,integer>

If you create shortcuts you can get the ids for those shortcuts with this function.

Returns

array<mixed,integer>

wp_attachment_ensure_source_file()

wp_attachment_ensure_source_file(integer|\WP_Post  $post): integer|\WP_Post

Checks if a given attachment has already a shortcut in a given folder id or has generally shortcuts.

Parameters

integer|\WP_Post $post

The attachment id or a WP_Post object

Returns

integer|\WP_Post

wp_attachment_has_shortcuts()

wp_attachment_has_shortcuts(integer  $postId,integer  $fid = false): boolean

Checks if a given attachment has already a shortcut in a given folder id or has generally shortcuts.

Parameters

integer $postId

The attachment id

integer $fid

The folder id, if false, it checks if there generally exists shortcuts

Returns

boolean

wp_attachment_get_shortcuts()

wp_attachment_get_shortcuts(integer  $postId,integer  $fid = false,boolean  $extended = false): mixed

Checks if a given attachment ID has shortcut and returns the shortcut IDs as array.

Parameters

integer $postId

The attachment id

integer $fid

The folder id, if false, it checks if there generally exists shortcuts

boolean $extended

If true the result is an array with all information about the associated folder

Returns

mixed

wp_attachment_is_shortcut()

wp_attachment_is_shortcut(integer|\WP_Post  $post,boolean  $returnSourceId = false): boolean|integer

Checks if a given attachment is a shortcut, use the $returnSourceId parameter to get the source attachment id.

Parameters

integer|\WP_Post $post

The attachment id or a WP_Post object

boolean $returnSourceId

If true, the return will be the source attachment id or 0 if it is no shortcut

Returns

boolean|integer

_wp_rml_synchronize_attachment()

_wp_rml_synchronize_attachment(integer  $postId,integer  $fid,boolean  $isShortcut = false): boolean

Synchronizes a result with the realmedialibrary_posts table so on this base there can be made the folder content. It also creates shortcuts, if the given $isShortcut parameter is true.

Do not use this directly, instead use the wp_rml_move function.

Parameters

integer $postId

The post ID

integer $fid

The folder ID

boolean $isShortcut

true = Is shortcut in the given folder, false = Is no shortcut, mainly in this folder

Returns

boolean