Search by

arraypress / wp-s3-browser

arraypress

This package is abandoned and no longer maintained. No replacement package was suggested.

A comprehensive PHP library for integrating S3-compatible storage providers with WordPress. Features advanced media browser, upload/download management, presigned URLs, and support for multiple providers including AWS S3, Cloudflare R2, DigitalOcean Spaces, and more.

Package info

github.com/arraypress/wp-s3-browser

Homepage

pkg:composer/arraypress/wp-s3-browser

Statistics

Installs: 563

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0


README

This library has moved. It is now part of sugarcommerce/storage (namespace SugarCommerce\Storage, PHP 8.3+). That package's README has a "Moving from arraypress/wp-*" table. This repository is archived and read-only.

S3 Browser

A media browser for S3-compatible storage, inside the WordPress admin.

What it does

Files sold as downloads usually live in object storage rather than the media library, and the moment they do, attaching one to a product means copying a key out of another tab.

This adds a browser beside the media library: buckets, folders, search, upload and a link back into whatever field asked for it. Underneath it is arraypress/wp-s3-signer, so nothing is made public and uploads go straight from the browser to storage rather than through PHP.

Features

  • Browse buckets and folders from the admin, without leaving WordPress
  • Upload straight to storage from the browser, bypassing the PHP upload limit
  • Attach a file to a field, the way the media library does
  • Confine a browser to one bucket, or to certain post types
  • Require a capability, so not everyone who can edit can see storage
  • Run more than one browser on a site, each on its own provider and context
  • Work against R2, B2, Wasabi, DigitalOcean, MinIO or anything S3-compatible

Installation

composer require arraypress/wp-s3-browser

Quick start

use ArrayPress\S3\Browser;
use ArrayPress\S3\Provider;

$browser = new Browser(
	Provider::r2( 'your-account-id' ),
	$access_key,
	$secret_key,
	[ 'download' ],   // post types this browser appears for; [] means all
	'my-bucket',      // bucket it opens on
	'upload_files',   // capability required to use it
	'edd'             // context: which integration this instance serves
);

$browser->set_allowed_buckets( [ 'my-bucket' ] );

Confining it to one bucket is worth doing whenever you can — the credentials usually reach more than the browser should.

Pages that are not post editors

A post editor is recognised by its post type. A plugin with screens of its own — a settings page, a custom list, a panel — has no post type to be recognised by, so it names the page and says where a chosen file goes:

add_action( 'admin_enqueue_scripts', function ( $hook ) use ( $browser ) {
	if ( 'toplevel_page_my-shop' === $hook ) {
		$browser->set_host_hook( $hook );
	}
}, 5 );
window.S3BrowserHost = {
	insert: function ( files ) {
		// files: [ { fileName, bucket, key } ]
	}
};

The browser then appears as a tab in any media frame that page opens. The page owns its fields, so it is asked rather than written into: throw from insert and the frame stays open with the selection still in it.

Uploads need CORS

Uploading from the browser is a cross-origin request, so the bucket has to allow it. Setting that rule needs an admin token: a key with Object Read & Write cannot call PutBucketCors, and the error it returns says AccessDenied, which reads like a bucket-permissions problem rather than a key-permissions one.

Icons

Buckets, folders, file types and upload states are drawn as Heroicons (outline, inline SVG) when arraypress/wp-field-kit is installed, and as the Dashicons they replaced when it is not. Every icon carries the class arraypress-icon, so a stylesheet that restyles them has one class to target either way.

Requirements

  • PHP 8.3 or later
  • WordPress 7.1 or later
  • Credentials for an S3-compatible provider
  • arraypress/wp-field-kit (optional), for Heroicons

License

GPL-2.0-or-later