PHPackages                             arraypress/wp-media-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. arraypress/wp-media-utils

ActiveLibrary[File &amp; Storage](/categories/file-storage)

arraypress/wp-media-utils
=========================

A lean WordPress library for working with attachments and media files.

014PHP

Since Sep 6Pushed 8mo agoCompare

[ Source](https://github.com/arraypress/wp-media-utils)[ Packagist](https://packagist.org/packages/arraypress/wp-media-utils)[ RSS](/packages/arraypress-wp-media-utils/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

WordPress Media Utils
=====================

[](#wordpress-media-utils)

A lean WordPress library for working with attachments and media files.

Installation
------------

[](#installation)

```
composer require arraypress/wp-media-utils
```

Usage
-----

[](#usage)

### Single Attachment Operations

[](#single-attachment-operations)

```
use ArrayPress\MediaUtils\Attachment;

// Get attachment info
$attachment = Attachment::get( 123 );
$exists     = Attachment::exists( 123 );

// File information
$type      = Attachment::get_type( 123 );        // 'image', 'video', 'audio', 'document', 'file'
$mime      = Attachment::get_mime_type( 123 );   // 'image/jpeg'
$extension = Attachment::get_extension( 123 );   // 'jpg'
$size      = Attachment::get_file_size( 123 );   // '2.5 MB'
$filename  = Attachment::get_filename( 123 );    // 'photo.jpg'
$url       = Attachment::get_url( 123 );

// Attachment fields
$title       = Attachment::get_title( 123 );
$caption     = Attachment::get_caption( 123 );
$description = Attachment::get_description( 123 );
$alt         = Attachment::get_alt_text( 123 );
Attachment::set_alt_text( 123, 'New alt text' );

// Image specific
$is_image   = Attachment::is_image( 123 );
$dimensions = Attachment::get_dimensions( 123 ); // ['width' => 1920, 'height' => 1080]
$image_html = Attachment::get_image( 123, 'thumbnail' );
$image_url  = Attachment::get_image_url( 123, 'large' );

// Media content
$duration  = Attachment::get_duration( 123 );           // 180 (seconds)
$formatted = Attachment::get_duration_formatted( 123 ); // '3:00'

// Delete
Attachment::delete( 123, true ); // force delete
```

### Multiple Attachment Operations

[](#multiple-attachment-operations)

```
use ArrayPress\MediaUtils\Attachments;

// Get multiple attachments
$attachments    = Attachments::get( [ 123, 456, 789 ] );
$by_parent      = Attachments::get_by_parent( 100 );
$images         = Attachments::get_by_type( 'image' );
$search_results = Attachments::search( 'photo' );

// Form options
$options = Attachments::get_options(); // [123 => 'Title', 456 => 'Another']

// Bulk operations
$results = Attachments::update_meta( [ 123, 456 ], 'custom_field', 'value' );
$results = Attachments::delete_meta( [ 123, 456 ], 'old_field' );
$results = Attachments::delete( [ 123, 456 ] );

// Utilities
$existing  = Attachments::exists( [ 123, 456, 999 ] );    // [123, 456]
$sanitized = Attachments::sanitize( '123,456,invalid' );  // [123, 456]
```

### Media Output

[](#media-output)

```
use ArrayPress\MediaUtils\Media;

// Universal media output (auto-detects type)
echo Media::output( 123 );

// Specific media types
echo Media::image( 123, [ 'size' => 'large' ] );
echo Media::video( 123, [ 'width' => 800, 'height' => 450 ] );
echo Media::audio( 123, [ 'controls' => true ] );
echo Media::file( 123, [ 'show_size' => true ] );

// WordPress shortcode embeds
echo Media::embed( 123 ); // [video] or [audio] shortcodes

// Media galleries
echo Media::gallery( [ 123, 456, 789 ], [ 'columns' => 3 ] );
```

### Thumbnail Display

[](#thumbnail-display)

```
use ArrayPress\MediaUtils\Thumbnail;

// Entity thumbnails
echo Thumbnail::post( 123 );                                    // Post featured image
echo Thumbnail::user( 456, 'profile_image' );                   // User meta thumbnail
echo Thumbnail::term( 789, 'featured_image' );                  // Term meta thumbnail
echo Thumbnail::attachment( 123, 'thumbnail' );                 // Direct attachment
echo Thumbnail::avatar( 456, 48 );                              // User avatar/Gravatar

// With custom attributes
echo Thumbnail::post( 123, 'medium', [ 'class' => 'featured' ], true );
```

Examples
--------

[](#examples)

### Admin Column Thumbnails

[](#admin-column-thumbnails)

```
// In admin list tables
echo Thumbnail::post( $post->ID );
echo Thumbnail::user( $user->ID, 'avatar_attachment_id' );
echo Thumbnail::attachment( $attachment_id );
```

### Frontend Media Display

[](#frontend-media-display)

```
// Blog post content
echo Media::output( $featured_video_id );
echo Media::gallery( $gallery_attachment_ids, [ 'columns' => 4 ] );

// Portfolio items
if ( Attachment::get_type( $attachment_id ) === 'video' ) {
    echo Media::video( $attachment_id, [ 'controls' => true ] );
} else {
    echo Media::image( $attachment_id, [ 'size' => 'large' ] );
}
```

### Custom Video Player

[](#custom-video-player)

```
echo Media::video( $video_id, [
    'width'    => 1280,
    'height'   => 720,
    'controls' => true,
    'preload'  => 'metadata'
]);
```

### File Downloads with Metadata

[](#file-downloads-with-metadata)

```
echo Media::file( $document_id, [
    'show_size' => true,
    'show_icon' => true,
    'text'      => 'Download Report'
]);
```

Requirements
------------

[](#requirements)

- PHP 7.4+
- WordPress 5.0+

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the GPL-2.0-or-later License.

Support
-------

[](#support)

- [Documentation](https://github.com/arraypress/wp-media-utils)
- [Issue Tracker](https://github.com/arraypress/wp-media-utils/issues)

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance43

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/cd6eb8aff0903d87eb674d1ba3c5f3653899c0d7661504eb0deb7798ed86b643?d=identicon)[arraypress](/maintainers/arraypress)

---

Top Contributors

[![arraypress](https://avatars.githubusercontent.com/u/22668877?v=4)](https://github.com/arraypress "arraypress (3 commits)")

### Embed Badge

![Health badge](/badges/arraypress-wp-media-utils/health.svg)

```
[![Health](https://phpackages.com/badges/arraypress-wp-media-utils/health.svg)](https://phpackages.com/packages/arraypress-wp-media-utils)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15161.6M2.6k](/packages/illuminate-filesystem)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M62](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)[madnest/madzipper

Easier zip file handling for Laravel applications.

1382.3M6](/packages/madnest-madzipper)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
