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

Functions

wp_rml_debug()

wp_rml_debug(mixed|string  $message,string  $methodOrFunction = null)

This function is recommend for RML add-ons. You can use this function to generate log entries in the database when Settings > Media > Debug is enabled.

Parameters

mixed|string $message

The message

string $methodOrFunction

METHOD or FUNCTION

is_rml_folder()

is_rml_folder(integer|\MatthiasWeb\RealMediaLibrary\api\IFolder  $obj): boolean

Checks, if a given variable is an implementation of the IFolder interface.

Parameters

integer|\MatthiasWeb\RealMediaLibrary\api\IFolder $obj

Object or int (ID)

Returns

boolean

wp_rml_get_parent_id()

wp_rml_get_parent_id(integer  $id): integer

Get the parent ID of a given folder id.

Parameters

integer $id

The id of the folder, collection, ...

Returns

integer —

or null

wp_rml_objects()

wp_rml_objects(): array<mixed,\MatthiasWeb\RealMediaLibrary\api\IFolder>

Get all available folders, collections, galleries, .

..

Returns

array<mixed,\MatthiasWeb\RealMediaLibrary\api\IFolder>

wp_rml_root_childs()

wp_rml_root_childs(): array<mixed,\MatthiasWeb\RealMediaLibrary\api\IFolder>

Gets the first level childs of the media library.

Returns

array<mixed,\MatthiasWeb\RealMediaLibrary\api\IFolder>

wp_rml_create()

wp_rml_create(string  $name,integer  $parent,integer  $type,array<mixed,string>  $restrictions = array(),boolean  $supress_validation = false,boolean  $return_existing_id = false): integer|array<mixed,string>

Creates a folder. At first it checks if a folder in parent already exists.

Then it checks if the given type is allowed in the parent.

It is highly recommend, to use wp_rml_structure_reset after you created your folders.

Parameters

string $name

String Name of the folder

integer $parent

int ID of the parent (_wp_rml_root() for root)

integer $type

integer 0|1|2, Folder.inc

array<mixed,string> $restrictions

Restrictions for this folder

boolean $supress_validation

Supress the permission validation

boolean $return_existing_id

If true and the folder already exists, then return the ID of the existing folder

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

integer|array<mixed,string> —

int (ID) when successfully array with error strings

wp_rml_create_p()

wp_rml_create_p(string  $name,integer  $parent,integer  $type,array<mixed,string>  $restrictions = array(),boolean  $supress_validation = false): integer|array<mixed,string>

(Pro only) Creates multiple folders like "test/test2". At first it checks if a folder in parent already exists.

Then it checks if the given type is allowed in the parent.

It is highly recommend, to use wp_rml_structure_reset after you created your folders.

Parameters

string $name

String Name of the folder

integer $parent

int ID of the parent (_wp_rml_root() for root)

integer $type

integer 0|1|2, Folder.inc

array<mixed,string> $restrictions

Restrictions for this folder, it is only applied to first folder

boolean $supress_validation

Supress the permission validation

Throws

\MatthiasWeb\RealMediaLibrary\exception\OnlyInProVersionException

Returns

integer|array<mixed,string> —

int (ID) when successfully array with error strings

wp_rml_create_or_return_existing_id()

wp_rml_create_or_return_existing_id(string  $name,integer  $parent,integer  $type,array<mixed,string>  $restrictions = array(),boolean  $supress_validation = false): integer|array<mixed,string>

Wrapper function for wp_rml_create.

Parameters

string $name

String Name of the folder

integer $parent

int ID of the parent (_wp_rml_root() for root)

integer $type

integer 0|1|2, Folder.inc

array<mixed,string> $restrictions

Restrictions for this folder

boolean $supress_validation

Supress the permission validation

Returns

integer|array<mixed,string> —

int (ID) when successfully array with error strings

wp_rml_rename()

wp_rml_rename(string  $name,integer  $id,boolean  $supress_validation = false): boolean|array<mixed,string>

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

integer $id

The ID of the folder

boolean $supress_validation

Suppress the permission validation

Returns

boolean|array<mixed,string> —

true or array with error strings

wp_rml_delete()

wp_rml_delete(integer  $id,boolean  $supress_validation = false): boolean|array<mixed,string>

Deletes a folder by ID.

Parameters

integer $id

The ID of the folder

boolean $supress_validation

Supress the permission validation

Returns

boolean|array<mixed,string> —

True or array with error string

wp_rml_update_count()

wp_rml_update_count(array<mixed,integer>  $folders = null,array<mixed,integer>  $attachments = null,boolean  $onlyReturn = false): string|null

Handle the count cache for the folders. This should avoid a lack SQL subquery which loads data from the postmeta table.

Parameters

array<mixed,integer> $folders

Array of folders ID, if null then all folders with cnt NULL are updated

array<mixed,integer> $attachments

Array of attachments ID, is merged with $folders if given

boolean $onlyReturn

Set to true if you only want the SQL query

Returns

string|null

wp_rml_selector()

wp_rml_selector(array  $options = array()): string

This function returns a HTML code (input[type="hidden"]) which gets nicely rendered via Javascript (FolderSelector). If you need a more complex implementation have a look at FolderSelector.js module.

$options:

  • mixed selected=Root The selected item, "" => "None", _wp_rml_root() => "Root", int => Folder ID
  • int[] disabled Which folder types are disabled
  • boolean nullable=false Defines if null ('') is allowed as value
  • boolean editable=true Define if the selector is editable
  • string name Name for the input
  • string title Title in the modal dialog

Parameters

array $options

Returns

string

wp_rml_dropdown()

wp_rml_dropdown(mixed  $selected,array<mixed,integer>  $disabled,boolean  $useAll = true): string

This functions returns a HTML formatted string which contains options-tag elements with all folders, collections and galleries.

This function should only be used if you want to provide

Parameters

mixed $selected

The selected item, "" => "All Files", _wp_rml_root() => "Root", int => Folder ID. Can also be an array for multiple select (since 3.1.2)

array<mixed,integer> $disabled

Which folder types are disabled. Default disabled is RML_TYPE_COLLECTION

boolean $useAll

boolean Defines, if "All Files" should be showed

Returns

string

wp_rml_dropdown_collection()

wp_rml_dropdown_collection(mixed  $selected): string

This functions returns a HTML formatted string which contains `<options>` elements with all folders, collections and galleries.

Note: Only COLLECTIONS are SELECTABLE!

This function should only be used if you want to provide

Parameters

mixed $selected

The selected item, "" => "All Files", _wp_rml_root() => "Root", int => Folder ID. Can also be an array for multiple select (since 3.1.2)

Returns

string

wp_rml_dropdown_gallery()

wp_rml_dropdown_gallery(mixed  $selected): string

This functions returns a HTML formatted string which contains option-tag elements with all folders, collections and galleries.

Note: Only GALLERIES are SELECTABLE!

This function should only be used if you want to provide

Parameters

mixed $selected

The selected item, "" => "All Files", _wp_rml_root() => "Root", int => Folder ID. Can also be an array for multiple select (since 3.1.2)

Returns

string

wp_rml_dropdown_gallery_or_collection()

wp_rml_dropdown_gallery_or_collection(mixed  $selected): string

This functions returns a HTML formatted string which contains option-tag elements with all folders, collections and galleries.

Note: Only GALLERIES AND COLLECTIONS are SELECTABLE!

Parameters

mixed $selected

The selected item, "" => "All Files", _wp_rml_root() => "Root", int => Folder ID. Can also be an array for multiple select (since 3.1.2)

Returns

string

wp_rml_is_type()

wp_rml_is_type(\MatthiasWeb\RealMediaLibrary\api\IFolder|integer  $folder,array<mixed,integer>  $allowed): boolean

Determines if a Folder is a special folder type.

Parameters

\MatthiasWeb\RealMediaLibrary\api\IFolder|integer $folder

The folder object

array<mixed,integer> $allowed

Which folder types are allowed

Returns

boolean

wp_rml_get_object_by_id()

wp_rml_get_object_by_id(integer  $id,array<mixed,integer>  $allowed = null): \MatthiasWeb\RealMediaLibrary\api\IFolder

A shortcut function for the wp_rml_get_by_id function that ensures, that a IFolder object is returned. For -1 the root instance is returned.

Parameters

integer $id
array<mixed,integer> $allowed

Returns

\MatthiasWeb\RealMediaLibrary\api\IFolder

wp_rml_get_by_id()

wp_rml_get_by_id(integer  $id,array<mixed,integer>  $allowed = null,boolean  $mustBeFolderObject = false,boolean  $nullForRoot = true): \MatthiasWeb\RealMediaLibrary\api\IFolder

This functions checks if a specific folder exists by ID and is a given allowed RML Folder Type. If the given folder is _wp_rml_root you will get the first level folders.

Parameters

integer $id

Folder ID

array<mixed,integer> $allowed

Which folder types are allowed. If null all folder types are allowed.

boolean $mustBeFolderObject

Defines if the function may return the wp_rml_root_childs result

boolean $nullForRoot

If set to false and $id == -1 then the Root instance is returned

Returns

\MatthiasWeb\RealMediaLibrary\api\IFolder

wp_rml_get_by_absolute_path()

wp_rml_get_by_absolute_path(string  $path,array<mixed,integer>  $allowed = null): \MatthiasWeb\RealMediaLibrary\api\IFolder

This functions checks if a specific folder exists by absolute path and is a given allowed RML Folder Type.

Parameters

string $path

Folder Absolute Path

array<mixed,integer> $allowed

Which folder types are allowed. If null all folder types are allowed.

Returns

\MatthiasWeb\RealMediaLibrary\api\IFolder

wp_rml_register_creatable()

wp_rml_register_creatable(string  $qualified,integer  $type,boolean  $onRegister = false)

Register a new folder type for RML. It does not check if the creatable type is already registered.

Parameters

string $qualified

The qualified name of the class representing the creatable

integer $type

The type of the creatable. It must be the same as in yourClass::getType is returned

boolean $onRegister

Calls the yourClass::onRegister function

_wp_rml_root()

_wp_rml_root(): integer

Get the parent root folder for a given blog id.

Returns

integer —

Folder id

wp_rml_active()

wp_rml_active(): boolean

Checks if RML is active for the current user.

Returns

boolean

_wp_rml_sanitize()

_wp_rml_sanitize(string  $name,boolean  $database = false,integer  $exclude = -1): string

Sanitize to a valid slug name for a given folder name. If the passed folder name contains only invalid characters, then it falls back to the base64 encode.

Parameters

string $name

The name of the folder

boolean $database

If true the name is generated unique from the database slugs

integer $exclude

Returns

string

_wp_rml_sanitize_filename()

_wp_rml_sanitize_filename(  $name)

Parameters

$name

wp_rml_structure_reset()

wp_rml_structure_reset(integer  $root = null,boolean  $fetchData = true,integer  $returnId = false): \MatthiasWeb\RealMediaLibrary\api\IFolder

Resets the structure. This function must be called when you create a new folder for example and to register it to the structure.

ATTENTION: This function will be declared as deprecated soon, because it is planned to automatically reset the structure data / reset folder data (lazy loading of Folder objects).

Parameters

integer $root

The root folder to read the structure

boolean $fetchData

Determine if the data should be re-fetched

integer $returnId

If set this folder is returned

Returns

\MatthiasWeb\RealMediaLibrary\api\IFolder

If $returnId is set

wp_rml_structure()

wp_rml_structure(): \IStructure

Get the main working structure.

Returns

\IStructure

wp_rml_create_all_parents_sql()

wp_rml_create_all_parents_sql(\MatthiasWeb\RealMediaLibrary\api\IFolder|integer  $folder,boolean  $includeSelf = false,integer  $until = null,array  $options = null): string|boolean

Returns a SQL query to get all parents for a folder id.

The first result for this SQL statement is the first parent and so on... Use rmltmp.lvl field for the depth number upwards. To avoid performance lacks you should figure out if there is already an action available to search for a meta_key in the action RML/$action/AnyParentHasMeta.

$options parameters:

"fields"    => (string) SELECT fields (default: "rmldata.*, rmltmp.lvl AS lvlup")
"join"      => (string) JOIN statement (default: "")
"where"     => (string) Replace WHERE statement, it is preferred to use afterWhere (default: "rmltmp.lvl > " . ($includeSelf === true ? "-1" : "0"))
"afterWhere"=> (string) Additional WHERE statement to the above WHERE (default: "")
"orderby"   => (string) ORDER BY statement (default: "rmltmp.lvl ASC")
"limit"     => (string) LIMIT statement (default: "")

Note: The created SQL is supported by all well-known MySQL systems.

Parameters

\MatthiasWeb\RealMediaLibrary\api\IFolder|integer $folder

The folder object or folder id

boolean $includeSelf

Set true to include self (passed $folder)

integer $until

Until this folder id

array $options

Additional options for the SQL query, see above

Returns

string|boolean —

SQL query or false if something went wrong

wp_rml_all_children_sql_supported()

wp_rml_all_children_sql_supported(boolean  $force = false,string  $type = 'legacy'): boolean

Checks if the wp_rml_create_all_children_sql() SQL is supported by the current used database system. The function itself creates a dummy table and performs the SQL and checks if the result is as expected. The "support" result is cached site-wide.

Parameters

boolean $force

If true the database check is performed again

string $type

The type which is minimum required. Possible values: 'function' (MySQL UDF) or 'legacy' (default, old variant)

Returns

boolean

wp_rml_create_all_children_sql()

wp_rml_create_all_children_sql(\MatthiasWeb\RealMediaLibrary\api\IFolder|integer  $folder,boolean  $includeSelf = false,array  $options = null): string|boolean

Returns a SQL query to get all children for a folder id.

The first result for this SQL statement is the first children and so on...

$options parameters:

"fields"       => (string) SELECT fields (default: "rmldata.*"),
"join"         => (string) JOIN statement (default: ""),
"where"        => (string) Replace WHERE statement, it is preferred to use afterWhere (default: '1=1 ' . ($includeSelf === true ? "" : $wpdb->prepare(" AND rmldata.id != %d", $folderId))),
"afterWhere"   => (string) Additional WHERE statement to the above WHERE (default: ""),
"orderby"      => (string) ORDER BY statement (default: "rmldata.parent, rmldata.ord"),
"limit"        => (string) LIMIT statement (default: "")

Note: Not all database systems do support this kind of SQL query. You have to use the wp_rml_all_children_sql_supported() API function to check if it is supported.

Parameters

\MatthiasWeb\RealMediaLibrary\api\IFolder|integer $folder

The folder object or folder id

boolean $includeSelf

Set true to include self (passed $folder)

array $options

Additional options for the SQL query, see above

Returns

string|boolean —

SQL query or false if something went wrong

wp_rml_last_queried_folder()

wp_rml_last_queried_folder(integer  $folder = null): integer

Set or get the last queried folder.

Parameters

integer $folder

The folder id (0 is handled as "All files" folder)

Returns

integer