\MatthiasWeb\RealMediaLibrary\apiIFolder

This interface provides elementary getter and setter methods for folder objects. All folder types (Folder, Collection, Gallery, .

..) have implemented this interface. Also the root ("Unorganized") is a folder and implements this interface. Usually, the root acts as "-1" but you should use the _wp_rml_root function to get the root id. If this interface does not provide an expected method, yet, have a look at the other API files. For example to create a folder use wp_rml_create.

Check if a variable is surely a IFolder interface object:

$folder = wp_rml_get_object_by_id(5);
if (is_rml_folder($folder)) {
     // It is an interface implementation of IFolder
}

Register own folder type:

You can create your own implementation of a folder type (Gallery, Collection, Root, ...) just have a look at the wp-content/plugins/real-media-library/inc/folder files.

Also have a look at the wp_rml_register_creatable function to register your class (RML_TYPE_FOLDER is an unique defined integer for your folder type):

wp_rml_register_creatable(Folder::class, RML_TYPE_FOLDER);

Summary

Methods
Constants
read()
relocate()
orderSubfolders()
resetSubfolderOrder()
reindexChildrens()
insert()
updateThisAndChildrensAbsolutePath()
setVisible()
setRestrictions()
setParent()
setName()
contentOrder()
contentOrderBy()
contentIndex()
contentReindex()
contentEnableOrder()
contentDeleteOrder()
contentRestoreOldCustomNr()
isContentCustomOrderAllowed()
getContentCustomOrder()
forceContentCustomOrder()
postsClauses()
getAttachmentNextTo()
getContentAggregationNr()
getContentNrOf()
getContentOldCustomNrCount()
anyParentHas()
anyParentHasMetadata()
anyChildrenHas()
anyChildrenHasMetadata()
hasChildren()
getType()
getAllowedChildrenTypes()
getId()
getParent()
getAllParents()
getName()
getSlug()
getPath()
getOwner()
getAbsolutePath()
getCnt()
getChildren()
getOrder()
getMaxOrder()
getRestrictions()
getRestrictionsCount()
getPlain()
getRowData()
getTypeName()
getTypeDescription()
is()
isVisible()
isRestrictFor()
isValidChildrenType()
No constants found
No protected methods found
N/A
No private methods found
N/A

Methods

read()

read(string  $order = null,string  $orderby = null): array<mixed,integer>

Fetch all attachment ids currently in this folder. It uses the default WP_Query to fetch the ids. You can also use the WP_Query like: ```php $query = new \WP_Query([ 'post_status' => 'inherit', 'post_type' => 'attachment', 'rml_folder' => 4, 'rml_include_children' => false // (optional) Include files of subfolder, you have to use wp_rml_all_children_sql_supported(false, 'function') for checking support ]); ```

Parameters

string $order

The order "ASC" or "DESC"

string $orderby

Use "rml" to get ids ordered by custom order

Returns

array<mixed,integer> —

Post ids

relocate()

relocate(integer  $parentId,integer  $nextFolderId = false): boolean|array<mixed,string>

Relocate a folder to a given place in the folder structure.

Parameters

integer $parentId

The parent id

integer $nextFolderId

The next folder id it should be prepend or false for the end

Throws

\MatthiasWeb\RealMediaLibrary\api\Exception

Returns

boolean|array<mixed,string> —

true or array with errors

orderSubfolders()

orderSubfolders(string  $orderby,boolean  $writeMetadata = true): boolean

(Pro only) Start to order the given folder subfolders by a given order type.

Parameters

string $orderby

The order type key

boolean $writeMetadata

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

boolean

resetSubfolderOrder()

resetSubfolderOrder(): boolean

(Pro only) Reset the subfolders order'.

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

boolean

reindexChildrens()

reindexChildrens(boolean  $resetData = false): boolean

(Pro only) Reindex the children folders so the "ord" number is set right.

Parameters

boolean $resetData

If true, the structure is reset

Returns

boolean

insert()

insert(array<mixed,integer>  $ids,boolean  $supress_validation = false,boolean  $isShortcut = false): true

Insert an amount of post ID's (attachments) to this folder.

Parameters

array<mixed,integer> $ids

Array of post ids

boolean $supress_validation

Suppress the permission validation

boolean $isShortcut

Determines, if the post's should be "copied" to the folder (no physical copy)

Throws

\Exception

Returns

true

updateThisAndChildrensAbsolutePath()

updateThisAndChildrensAbsolutePath()

Iterate all children of this folder recursively and update the absolute path. Use this function with caution because it can be time intensive.

setVisible()

setVisible(boolean  $visible)

Sets the folders visibility to the user.

Parameters

boolean $visible

setRestrictions()

setRestrictions(array<mixed,string>  $restrictions = array()): boolean

Set restrictions for this folder. Allowed restrictions for folders:

  • par Restrict to change the parent id
  • rea Restrict to rearrange the hierarchical levels of all subfolders (it is downwards all subfolders!) and cannot be inherited
  • cre Restrict to create new subfolders
  • ins Restrict to insert/upload new attachments, automatically moved to root if upload
  • ren Restrict to rename the folder
  • del Restrict to delete the folder
  • mov Restrict to move files outside the folder

You can append a ">" after each permission so it is inherited in each created subfolder: "cre>", "ins>", ...

Parameters

array<mixed,string> $restrictions

Array with restrictions

Returns

boolean

setParent()

setParent(integer  $id,integer  $ord = -1,boolean  $force = false): boolean

Changes the parent folder of this folder.

Parameters

integer $id

The new parent (use -1 for root)

integer $ord

The order number

boolean $force

If true no permission checks are executed

Throws

\Exception

Returns

boolean

setName()

setName(string  $name,boolean  $supress_validation = false): boolean

Renames a folder and then checks, if there is no duplicate folder in the parent folder.

Parameters

string $name

String New name of the folder

boolean $supress_validation

Suppress the permission validation

Throws

\Exception

Returns

boolean

contentOrder()

contentOrder(integer  $attachmentId,integer  $nextId,integer|boolean  $lastIdInView = false): true

(Pro only) See API function for more information.

Parameters

integer $attachmentId
integer $nextId
integer|boolean $lastIdInView

Throws

\Exception
\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

true

contentOrderBy()

contentOrderBy(string  $orderby,boolean  $writeMetadata = true): boolean

(Pro only) Start to order the given folder content by a given order type.

Parameters

string $orderby

The order type key

boolean $writeMetadata

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

boolean

contentIndex()

contentIndex(boolean  $delete = true): boolean

(Pro only) Index the order table.

Parameters

boolean $delete

Delete the old order

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

boolean

contentReindex()

contentReindex(): boolean

(Pro only) This function retrieves the order of the order table and removes empty spaces, for example: <pre>0 1 5 7 8 9 10 => 0 1 2 3 4 5 6</pre>

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

boolean

contentEnableOrder()

contentEnableOrder(): boolean

(Pro only) Enable the order functionality for this folder.

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

boolean

contentDeleteOrder()

contentDeleteOrder(): boolean

(Pro only) Deletes the complete order for this folder.

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

boolean

contentRestoreOldCustomNr()

contentRestoreOldCustomNr(): boolean

(Pro only) Restore the current order number to the old custom order number.

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

boolean

isContentCustomOrderAllowed()

isContentCustomOrderAllowed(): boolean

Checks if the folder is allowed to use custom content order.

Returns

boolean

getContentCustomOrder()

getContentCustomOrder(): integer

The content custom order defines the state of the content order functionality:

0 = No content order defined
1 = Content order is enabled
2 = Custom content order is not allowed

Returns

integer —

The content custom order value

forceContentCustomOrder()

forceContentCustomOrder(): boolean

Override this functionality to force the content custom order in the posts_clauses.

Returns

boolean

postsClauses()

postsClauses(array  $pieces): boolean

Override the default posts_clauses join and orderby instead of the RML standard.

This can be useful if you want to take the order from another relationship. You have to return true if you have overwritten it.

Parameters

array $pieces

The posts_clauses $pieces parameter

Returns

boolean

getAttachmentNextTo()

getAttachmentNextTo(integer  $attachmentId): array

(Pro only) Get the next attachment row for a specific attachment. It returns false if the attachment is at the end or the folder has no custom content order.

Parameters

integer $attachmentId

The attachment id

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

array —

or null

getContentAggregationNr()

getContentAggregationNr(string  $function = 'MAX'): integer

(Pro only) Gets the biggest order number;

Parameters

string $function

The SQL aggregation function (MIN or MAX)

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

integer

getContentNrOf()

getContentNrOf(integer  $attachmentId): integer|boolean

(Pro only) Get the order number for a specific attachment in this folder.

Parameters

integer $attachmentId

The attachment id

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

integer|boolean

getContentOldCustomNrCount()

getContentOldCustomNrCount(): integer

(Pro only) Get the old custom order number count so we can decide if already available.

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

integer

anyParentHas()

anyParentHas(string  $column,mixed  $value = null,string  $valueFormat = '%s',boolean  $includeSelf = false,integer  $until = null): array

Get all parents which meets a given column value or column value is not empty.

Parameters

string $column

The column name for the wp_realmedialibrary SQL table. "slug", "name", "absolutePath", ... This string is not escaped when you pass it through this function

mixed $value

The value the column should have

string $valueFormat

The value format for $value ($wpdb->prepare) This string is not escaped when you pass it through this function

boolean $includeSelf

Set true to add self to list

integer $until

The highest allowed folder id. If null _wp_rml_root() is used

Returns

array —

folderId => columnValue, first id is the first found parent

anyParentHasMetadata()

anyParentHasMetadata(string  $meta_key,mixed  $meta_value = null,string  $valueFormat = '%s',boolean  $includeSelf = false,integer  $until = null): array

Get all parents which meets a given meta key value or meta key value is not empty.

Parameters

string $meta_key

The meta key name for the wp_realmedialibrary_meta SQL table. This string is not escaped when you pass it through this function

mixed $meta_value

The value the meta key should have

string $valueFormat

The value format for $value ($wpdb->prepare) This string is not escaped when you pass it through this function

boolean $includeSelf

Set true to add self to list

integer $until

The highest allowed folder id. If null _wp_rml_root() is used

Returns

array —

Array with keys: id (meta_id), folderId, value (meta_value), first id is the first found parent

anyChildrenHas()

anyChildrenHas(string  $column,mixed  $value = null,string  $valueFormat = '%s',boolean  $includeSelf = false): array

Get all children which meets a given column value or column value is not empty.

Parameters

string $column

The column name for the wp_realmedialibrary SQL table. "slug", "name", "absolutePath", ... This string is not escaped when you pass it through this function

mixed $value

The value the column should have

string $valueFormat

The value format for $value ($wpdb->prepare) This string is not escaped when you pass it through this function

boolean $includeSelf

Set true to add self to list

Returns

array —

folderId => columnValue, first id is the first found child

anyChildrenHasMetadata()

anyChildrenHasMetadata(string  $meta_key,mixed  $meta_value = null,string  $valueFormat = '%s',boolean  $includeSelf = false): array

Get all chilren which meets a given meta key value or meta key value is not empty.

Parameters

string $meta_key

The meta key name for the wp_realmedialibrary_meta SQL table. This string is not escaped when you pass it through this function

mixed $meta_value

The value the meta key should have

string $valueFormat

The value format for $value ($wpdb->prepare) This string is not escaped when you pass it through this function

boolean $includeSelf

Set true to add self to list

Returns

array —

Array with keys: id (meta_id), folderId, value (meta_value), first id is the first found child

hasChildren()

hasChildren(string  $name,boolean  $returnObject = false): boolean

Checks if this folder has a children with a given name.

Parameters

string $name

Name of folder

boolean $returnObject

If set to true and a children with this name is found, then return the object for this folder

Returns

boolean

getType()

getType(): integer

Return the type for the given folder. For example: 0 = Folder, 1 = Collection, 2 = Gallery

Returns

integer

getAllowedChildrenTypes()

getAllowedChildrenTypes(): boolean|array<mixed,integer>

Get all allowed children folder types.

Returns

boolean|array<mixed,integer> —

Array with allowed types or TRUE for all types allowed

getId()

getId(): integer

Get the folder id.

Returns

integer

getParent()

getParent(): integer

Get the parent folder id.

Returns

integer

getAllParents()

getAllParents(integer  $until = null,integer  $colIdx): array<mixed,integer>

Get all parents of this folder.

Parameters

integer $until

The highest allowed folder id. If null _wp_rml_root() is used

integer $colIdx

The index returning for the wp_rml_create_all_parents_sql() query

Returns

array<mixed,integer> —

Folder ids, first id is the first parent

getName()

getName(boolean  $htmlentities = false): string

Get the folder name.

Parameters

boolean $htmlentities

If true the name is returned htmlentitied for output

Returns

string

getSlug()

getSlug(boolean  $force = false,boolean  $fromSetName = false): string

Returns a sanitized title for the folder. If the slug is empty or forced to, it will be updated in the database, too.

Parameters

boolean $force

Forces to regenerate the slug

boolean $fromSetName

For internal usage only

Returns

string

getPath()

getPath(string  $implode = '/',callable  $map = 'htmlentities',callable  $filter = null): string

Creates a absolute path without slugging' the names.

// Get valid physical folder name
$folder->getPath("/", "_wp_rml_sanitize_filename");

Parameters

string $implode

Delimiter for the folder names

callable $map

Map the names with this function. Pass null to skip this map function

callable $filter

Filter folders

Returns

string —

htmlentitied path

getOwner()

getOwner(): integer

Get the creator/owner of the folder.

Returns

integer —

ID of the user

getAbsolutePath()

getAbsolutePath(boolean  $force = false,boolean  $fromSetName = false): string

Creates a absolute path. If the absolute path is empty or forced to, it will be updated in the database, too.

Parameters

boolean $force

Forces to regenerate the absolute path

boolean $fromSetName

For internal usage only

Returns

string

getCnt()

getCnt(boolean  $forceReload = false): integer

Gets the count of the files in this folder.

Parameters

boolean $forceReload

If true the count cache gets reloaded

Returns

integer

getOrder()

getOrder(): integer

Get the order number.

Returns

integer

getMaxOrder()

getMaxOrder(): integer

Get the maximal order number of the children.

Returns

integer —

Max order number

getRestrictions()

getRestrictions(): array<mixed,string>

Get the restrictions of this folder.

Returns

array<mixed,string>

getRestrictionsCount()

getRestrictionsCount(): integer

Get the count of the restrictions.

Returns

integer

getPlain()

getPlain(boolean  $deep = false): array

Gets a plain array with folder properties.

Parameters

boolean $deep

Return the children as plain object array

Returns

array —

or null when not visible

getRowData()

getRowData(string  $field = null): mixed

Get the full row of the SQL query.

Parameters

string $field

The field name

Returns

mixed —

Any object or false

getTypeName()

getTypeName(string  $default = null): string

Get the type name for this folder. For example: Folder, Collection, Gallery, Unorganized.

Parameters

string $default

The default (if null "Folder" is used as default)

Returns

string

getTypeDescription()

getTypeDescription(string  $default = null): string

Get the type description for this folder.

Parameters

string $default

The default (if null folder description is used as default)

Returns

string

is()

is(integer  $folder_type): boolean

Check if the folder object is a given type.

Parameters

integer $folder_type

The folder type

Returns

boolean

isVisible()

isVisible(): boolean

Check if the folder object is visible to the user.

Returns

boolean

isRestrictFor()

isRestrictFor(string  $restriction): boolean

Checks if this folder has a special restriction.

Parameters

string $restriction

The restriction to check

Returns

boolean

isValidChildrenType()

isValidChildrenType(integer  $type): boolean

Checks if a given folder type is allowed in this folder.

Parameters

integer $type

The type

Returns

boolean