Documentation

attachment.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.

Table of Contents

Functions

wp_rml_get_attachments()  : null|array<string|int, int>
Reads content of a folder.
wp_attachment_folder()  : int|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.
wp_attachment_order_update()  : bool
(Pro only) Moves an attachment before another given attachment in the order table.
wp_rml_move()  : bool|array<string|int, string>
Move or create shortcuts of a set of attachments to a specific folder.
wp_rml_create_shortcuts()  : bool|array<string|int, 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.
wp_rml_created_shortcuts_last_ids()  : array<string|int, int>
If you create shortcuts you can get the ids for those shortcuts with this function.
wp_attachment_ensure_source_file()  : int|WP_Post
Checks if a given attachment has already a shortcut in a given folder id or has generally shortcuts.
wp_attachment_has_shortcuts()  : bool
Checks if a given attachment has already a shortcut in a given folder id or has generally shortcuts.
wp_attachment_get_shortcuts()  : mixed
Checks if a given attachment ID has shortcut and returns the shortcut IDs as array.
wp_attachment_is_shortcut()  : bool|int
Checks if a given attachment is a shortcut, use the $returnSourceId parameter to get the source attachment id.
_wp_rml_synchronize_attachment()  : bool
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.

Functions

wp_rml_get_attachments()

Reads content of a folder.

wp_rml_get_attachments(int $fid[, string $order = null ][, string $orderby = null ]) : null|array<string|int, int>
Parameters
$fid : int

The folder id

$order : string = null

The order statement

$orderby : string = null

The order by statement

Return values
null|array<string|int, int>

Null if folder not exists or array of post ids

wp_attachment_folder()

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.

wp_attachment_folder(int $attachmentId[, int $default = null ]) : int|mixed
Parameters
$attachmentId : int

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

$default : int = null

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

Return values
int|mixed

Folder ID or $default or Array

wp_attachment_order_update()

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

wp_attachment_order_update(int $folderId, int $attachmentId, int|false $nextId[, int $lastIdInView = false ]) : bool
Parameters
$folderId : int

The folder id where the attachment exists

$attachmentId : int

The attachment which should be moved

$nextId : int|false

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

$lastIdInView : int = false

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

Return values
bool

True or array with error strings

wp_rml_move()

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

wp_rml_move(int $to, array<string|int, int> $ids[, bool $supress_validation = false ][, bool $isShortcut = false ]) : bool|array<string|int, string>

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

Parameters
$to : int

Folder ID

$ids : array<string|int, int>

Array of attachment ids

$supress_validation : bool = false

Supress the permission validation

$isShortcut : bool = false

Determines, if the ID's are copies

Return values
bool|array<string|int, string>

True or Array with errors

wp_rml_create_shortcuts()

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.

wp_rml_create_shortcuts(int $to, array<string|int, int> $ids[, bool $supress_validation = false ]) : bool|array<string|int, string>

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

Parameters
$to : int

Folder ID, if folder not exists then root will be

$ids : array<string|int, int>

Array of attachment ids

$supress_validation : bool = false

Supress the permission validation

Return values
bool|array<string|int, string>

True or Array with errors

wp_rml_created_shortcuts_last_ids()

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

wp_rml_created_shortcuts_last_ids() : array<string|int, int>
Return values
array<string|int, int>

wp_attachment_ensure_source_file()

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

wp_attachment_ensure_source_file(int|WP_Post $post) : int|WP_Post
Parameters
$post : int|WP_Post

The attachment id or a WP_Post object

Return values
int|WP_Post

wp_attachment_has_shortcuts()

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

wp_attachment_has_shortcuts(int $postId[, int $fid = false ]) : bool
Parameters
$postId : int

The attachment id

$fid : int = false

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

Return values
bool

wp_attachment_get_shortcuts()

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

wp_attachment_get_shortcuts(int $postId[, int $fid = false ][, bool $extended = false ]) : mixed
Parameters
$postId : int

The attachment id

$fid : int = false

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

$extended : bool = false

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

wp_attachment_is_shortcut()

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

wp_attachment_is_shortcut(int|WP_Post $post[, bool $returnSourceId = false ]) : bool|int
Parameters
$post : int|WP_Post

The attachment id or a WP_Post object

$returnSourceId : bool = false

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

Return values
bool|int

_wp_rml_synchronize_attachment()

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.

_wp_rml_synchronize_attachment(int $postId, int $fid[, bool $isShortcut = false ]) : bool

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

Parameters
$postId : int

The post ID

$fid : int

The folder ID

$isShortcut : bool = false

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

Return values
bool

        
On this page

Search results