---
title: "Media Folder Providers"
description: "Register a third-party folder provider for the Media Browser and Builder Browser, select it by post type, and control upload destinations."
canonical: "https://academy.bricksbuilder.io/developer/guides/media-folder-providers/"
markdownUrl: "https://academy.bricksbuilder.io/developer/guides/media-folder-providers.md"
pageType: "article"
section: "developer"
category: "guides"
lastmod: "2026-12-01T08:34:11.000Z"
---
The [Media Browser](/builder/features/media-browser/) uses `Bricks\Media_Folder_Provider` to browse folders, filter attachments, assign media, and manage folders through an integration. The provider owns its storage and permissions. Bricks includes a HappyFiles provider.

The provider interface is available from Bricks 2.4. Bricks 2.4.4 adds local uploads and URL imports into custom provider folders, folder-assignment verification and recovery for those uploads, and the optional `uploadable` folder flag.

## Register a provider

Implement `Bricks\Media_Folder_Provider` in your integration plugin and register an instance through `bricks/media_folder_providers/register`. The action receives the registry class name.

Add the action callback in your plugin. Load your provider class inside the callback, or let your plugin autoload it when Bricks fires the action. At that point the Bricks interface is available.

```php
add_action( 'bricks/media_folder_providers/register', function( $registry_class ) {
    $registry_class::register( new \MyPlugin\Media_Folder_Provider() );
} );
```

Use a stable provider ID compatible with WordPress `sanitize_key()`, such as `my-media-folders`. Registration uses that ID as the key, so registering the same ID again replaces the previous provider.

### Required methods

| Method | Purpose |
| --- | --- |
| `get_id()` | Return the stable provider ID. |
| `get_label()` | Return the provider's display label. |
| `is_available()` | Report whether the provider is available to the current user and media library. |
| `can_manage()` | Report whether the user can create, rename, move, and delete folders. |
| `can_assign()` | Report whether the user can assign attachments to folders. |
| `get_folders()` | Return a flat list of folder entries. |
| `apply_query( $query_args, $folder_id )` | Add the folder constraint to WordPress query arguments and return them. |
| `assign_attachment( $attachment_id, $folder_id )` | Assign the attachment and return `true` or a `WP_Error`. A folder ID of `0` means no folder relationship. |
| `manage_folder( $input )` | Sanitize the unslashed request input, perform the folder operation, and return the refreshed folder list or a `WP_Error`. |

Keep permission checks and folder validation in the provider's assignment and management methods. The capability methods control available Browser actions; they do not replace validation when an operation runs. The provider also determines assignment behavior when its storage supports multiple folders.

### Choose between available providers

Bricks uses one active provider per post type. The following example selects a provider for the media library (`attachment`). Use `bricks/media_folder_provider` to select a registered provider when several integrations are available:

```php
add_filter( 'bricks/media_folder_provider', function( $provider_id, $available, $post_type ) {
    if ( $post_type === 'attachment' && isset( $available['my-media-folders'] ) ) {
        return 'my-media-folders';
    }

    return $provider_id;
}, 10, 3 );
```

`$available` contains available provider instances keyed by ID. Returning an empty or unavailable ID falls back to the first available provider in registration order.

## Support posts, pages, and custom post types

The base interface covers attachments. To show folders for other post types in the [Builder Browser](/builder/features/builder-browser/), have the registered class also implement `Bricks\Media_Folder_Post_Type_Provider`. Bricks calls `for_post_type( $post_type )` for each requested type, including `attachment`. Return a `Bricks\Media_Folder_Provider` scoped to that type, or `null` for a type your plugin does not support.

For example, a provider for media and pages could use this method. Its constructor accepts a post type, and its folder queries, counts, and permission checks use that type.

```php
public function for_post_type( $post_type ) {
    if ( ! in_array( $post_type, [ 'attachment', 'page' ], true ) ) {
        return null;
    }

    return new self( $post_type );
}
```

To let users move posts or pages between folders, the scoped provider must also implement `Bricks\Media_Folder_Item_Assignment_Provider` and return `true` from `can_assign()` for users with assignment permission. Its `assign_item( $item_id, $folder_id )` method receives a post ID and a destination folder ID. A destination of `0` means **Uncategorized**. Return `true` on success or a `WP_Error` on failure. Bricks checks edit permission for each selected post.

## Return folder entries

Each entry returned by `get_folders()` must include `id`, `name`, `parent`, and `count`. Use positive integer folder IDs and a parent ID of `0` for top-level folders.

From Bricks 2.4.4, an entry can also include boolean `uploadable`. Omit it or set it to `true` for normal upload targeting. Set it to boolean `false` for a virtual grouping that should not receive automatic upload assignments. The string `'false'` does not disable targeting.

For example, this list contains a virtual Collections entry and a real folder beneath it. Replace the example IDs, names, and counts with your provider's data:

```php
[
    [
        'id'         => 100,
        'name'       => 'Collections',
        'parent'     => 0,
        'count'      => 0,
        'uploadable' => false,
    ],
    [
        'id'     => 101,
        'name'   => 'Client photos',
        'parent' => 100,
        'count'  => 12,
    ],
]
```

The flag applies only to that entry. Client photos remains an upload destination because it omits the flag, even though its parent has `uploadable` set to `false`.

`uploadable` controls automatic assignment of new uploads. It does not disable uploading, change moves of existing attachments, or replace rejection of invalid destinations in `assign_attachment()`.

## Upload destinations

For both local uploads and **From URL** imports, Bricks captures the active provider and selected folder when each file enters the queue. Navigation and transfer retries keep that captured destination.

For a positive folder destination, Bricks sends `bricksMediaFolderId` and `bricksMediaFolderProvider`. The upload handler checks that the requested provider matches the active provider, then calls its `assign_attachment()` method. The `hfOpenId` compatibility parameter is sent only for HappyFiles.

When the selected entry has `uploadable` set to `false`, both upload methods omit all three folder parameters. The queue shows **No folder assignment** and skips destination verification and repair, including HappyFiles' usual Uncategorized verification. The provider's default upload behavior applies; the file is not guaranteed to be uncategorized.

Without an explicit folder destination, custom providers also retain their default assignment behavior and show **No folder assignment**. HappyFiles retains its **Uncategorized** label and verification unless the selected entry explicitly opts out.

## Verify and retry folder assignments

From Bricks 2.4.4, verification and recovery work with the base `Media_Folder_Provider` interface. A separate `get_item_folder_ids()` method is not required.

The optional `Bricks\Media_Folder_Item_Provider` interface defines `get_item_folder_ids( $item_id )`, which returns an array of folder IDs or a `WP_Error`. If the provider exposes a callable `get_item_folder_ids( $attachment_id )` method, Bricks uses it to read folder membership. Otherwise, it calls `apply_query()` for a query restricted to the uploaded attachment and its stored post status. Preserve those query constraints when adding the folder filter.

`apply_query()` must handle positive folder IDs, `'unfiled'` for attachments without folder relationships, and an empty value for no folder constraint. Returning the correct attachment for the intended folder lets Bricks confirm that the assignment succeeded.

If verification fails, **Retry folder assignment** calls `assign_attachment()` for the existing attachment, then checks its membership again. It does not upload a second copy. Verification and retry require upload permission and permission to edit the attachment. A queued provider ID that no longer matches the active provider is rejected before any repair is attempted.