# Functions

The **Function** section provides a collection of PHP functions designed to manage folders and attachments within the **WordPress Media Library**. These functions utilize a structured **namespace** for easy integration and usage within custom plugins or themes.

**Key Features:**

✅ **Simplified Folder Management** – Create, retrieve, and organize folders effortlessly.\
✅ **Attachment Handling** – Easily assign or remove media files from folders.\
✅ **Optimized for Developers** – Functions are **namespaced** for better organization and seamless integration.\
✅ **Flexible Usage** – Designed for use in custom development, ensuring compatibility with WordPress best practices.

**Available Functions:**

🔹 **Get Folders** – Retrieve detailed information about all folders.\
🔹 **Get Folder** – Fetch data for a specific folder by ID.\
🔹 **Add Folder** – Create a new folder within the media library.\
🔹 **Rename Folder** – Rename folder by id.\
🔹 **Change Folder Color** – Change folder color by id.\
🔹 **Remove Folder** – Remove folder by id.\
🔹 **Add Attachment** – Assign media files to a folder.\
🔹 **Remove Attachment** – Detach media files from a folder.

Each function is well-documented, making it easy for developers to integrate and extend functionality based on project needs.

Source

```
\includes\Model\Folder.php
```

**Get Folders**

```php
<?php

use Luvre\Model\Folder as MyFolder;

$folders = MyFolder::generateFoldersData();
```

**Get Folder**

```php
<?php

use Luvre\Model\Folder as MyFolder;

$folder_id = 1;
$folders   = MyFolder::getFolderData( $folder_id );
```

**Add Folder**

```php
<?php

use Luvre\Model\Folder as MyFolder;

$folder_id = 1;
$parent_id = 0; // You can set with another parent id
$folders   = MyFolder::add( $name, $parent_id );
```

**Rename Folder**

```php
<?php

use Luvre\Model\Folder as MyFolder;

$new_name  = "New Folder Name";
$folder_id = 1;
$folders   = MyFolder::rename( $new_name, $folder_id );
```

**Change Folder Color**

```php
<?php

use Luvre\Model\Folder as MyFolder;

$folder_id = 1;
$color     = "#f4a97c"; // Color format must be hex color
$folders   = MyFolder::updateColor( $folder_id, $color );
```

**Remove Folder**

```php
<?php

use Luvre\Model\Folder as MyFolder;

$folder_id = 1;
$folders   = MyFolder::delete( $folder_id );
```

Source

```
\includes\Model\Attachment.php
```

**Add Attachment**

```php
<?php

use Luvre\Model\Attachment as MyAttachment;

$folder_id = 1;
$ids       = [115, 511]; // You can set single id or array
$folders   = MyAttachment::assignAttachment( [ 'folder_id' => $folder_id, 'ids' => $ids ] );
```

**Remove Attachment**

```php
<?php

use Luvre\Model\Attachment as MyAttachment;

$ids       = [115, 511]; // You can set single id or array
$folders   = MyAttachment::unassignAttachment( $ids );
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ghozylab.gitbook.io/plugins/details/luvre/developer/functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
