Files
WPS3Media/include/functions.php
Malin 3248cbb029 feat: add S3-compatible storage provider (MinIO, Ceph, R2, etc.)
Adds a new 'S3-Compatible Storage' provider that works with any
S3-API-compatible object storage service, including MinIO, Ceph,
Cloudflare R2, Backblaze B2, and others.

Changes:
- New provider class: classes/providers/storage/s3-compatible-provider.php
  - Provider key: s3compatible
  - Reads user-configured endpoint URL from settings
  - Uses path-style URL access (required by most S3-compatible services)
  - Supports credentials via AS3CF_S3COMPAT_ACCESS_KEY_ID /
    AS3CF_S3COMPAT_SECRET_ACCESS_KEY wp-config.php constants
  - Disables AWS-specific features (Block Public Access, Object Ownership)
- New provider SVG icons (s3compatible.svg, -link.svg, -round.svg)
- Registered provider in main plugin class with endpoint setting support
- Updated StorageProviderSubPage to show endpoint URL input for S3-compatible
- Built pro settings bundle with rollup (Svelte 4.2.19)
- Added package.json and updated rollup.config.mjs for pro-only builds
2026-03-03 12:30:18 +01:00

42 lines
1.8 KiB
PHP

<?php
use DeliciousBrains\WP_Offload_Media\Items\Media_Library_Item;
if ( ! function_exists( 'as3cf_get_attachment_url' ) ) {
/**
* Get the url of the file from provider, may be a signed expiring URL if associated file is set as private.
*
* NOTE: Returns false if attachment is not offloaded.
*
* @param int $post_id Post ID of the attachment, required.
* @param string|null $size Size of the image to get, optional.
* @param bool $skip_rewrite_check Always return the URL regardless of the 'Rewrite File URLs' setting, optional, default: false.
*
* @return string|bool|WP_Error
*/
function as3cf_get_attachment_url( $post_id, $size = null, $skip_rewrite_check = false ) {
return as3cf_get_secure_attachment_url( $post_id, null, $size, $skip_rewrite_check );
}
}
if ( ! function_exists( 'as3cf_get_secure_attachment_url' ) ) {
/**
* Get the signed expiring url of the file from provider.
*
* NOTE: Returns false if attachment is not offloaded.
*
* @param int $post_id Post ID of the attachment, required.
* @param int|null $expires Seconds for the link to live, optional, default: 900 (15 minutes).
* @param string|null $size Size of the image to get, optional.
* @param bool $skip_rewrite_check Always return the URL regardless of the 'Rewrite File URLs' setting, optional, default: false.
*
* @return string|bool|WP_Error
*/
function as3cf_get_secure_attachment_url( $post_id, $expires = 900, $size = null, $skip_rewrite_check = false ) {
$as3cf_item = Media_Library_Item::get_by_source_id( $post_id );
if ( ! empty( $as3cf_item ) && ! is_wp_error( $as3cf_item ) && $as3cf_item->served_by_provider( $skip_rewrite_check ) ) {
return $as3cf_item->get_provider_url( $size, $expires );
}
return false;
}
}