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
use Luvre\Model\Folder as MyFolder;
$folders = MyFolder::generateFoldersData();
Get Folder
<?php
use Luvre\Model\Folder as MyFolder;
$folder_id = 1;
$folders = MyFolder::getFolderData( $folder_id );
Add Folder
<?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
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
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
use Luvre\Model\Folder as MyFolder;
$folder_id = 1;
$folders = MyFolder::delete( $folder_id );
Source
\includes\Model\Attachment.php
Add Attachment
<?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
use Luvre\Model\Attachment as MyAttachment;
$ids = [115, 511]; // You can set single id or array
$folders = MyAttachment::unassignAttachment( $ids );
Last updated