Files
WPS3Media/classes/pro/api/v1/licences.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

115 lines
3.0 KiB
PHP

<?php
namespace DeliciousBrains\WP_Offload_Media\Pro\API\V1;
use DeliciousBrains\WP_Offload_Media\Pro\API\API;
use WP_Error;
use WP_REST_Request;
use WP_REST_Response;
class Licences extends API {
/** @var int */
protected static $version = 1;
/** @var string */
protected static $name = 'licences';
/**
* Register REST API routes.
*/
public function register_routes() {
register_rest_route(
static::api_namespace(),
static::route(),
array(
'methods' => 'GET',
'callback' => array( $this, 'get_licences' ),
'permission_callback' => array( $this, 'check_permissions' ),
)
);
register_rest_route(
static::api_namespace(),
static::route(),
array(
'methods' => 'POST',
'callback' => array( $this, 'post_licences' ),
'permission_callback' => array( $this, 'check_permissions' ),
)
);
register_rest_route(
static::api_namespace(),
static::route(),
array(
'methods' => 'DELETE',
'callback' => array( $this, 'delete_licences' ),
'permission_callback' => array( $this, 'check_permissions' ),
)
);
}
/**
* Processes a REST GET request to retrieve licence info.
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response|mixed
*/
public function get_licences( WP_REST_Request $request ) {
$data = $request->get_json_params();
$force = ! empty( $data['force'] );
return $this->rest_ensure_response( 'get', static::name(), array(
'licences' => $this->as3cf->get_licences( $force ),
) );
}
/**
* Processes a REST POST request to activate supplied licence and return resultant licence info.
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response|mixed
*/
public function post_licences( WP_REST_Request $request ) {
$data = $request->get_json_params();
$licence_key = empty( $data['licence'] ) ? '' : $data['licence'];
$result = $this->as3cf->activate_licence( $licence_key );
if ( is_wp_error( $result ) ) {
return $this->rest_ensure_response( 'post', static::name(), $result );
}
return $this->rest_ensure_response( 'post', static::name(), array(
'licences' => $this->as3cf->get_licences(),
) );
}
/**
* Processes a REST DELETE request to deactivate current licence and return resultant licence info.
*
* @param WP_REST_Request $request
*
* @return WP_REST_Response|mixed
*/
public function delete_licences( WP_REST_Request $request ) {
if ( $this->as3cf->is_licence_constant() ) {
return $this->rest_ensure_response( 'delete', static::name(),
new WP_Error(
'licence-constant',
__( 'Your licence key is currently defined via a constant and must be removed manually.', 'amazon-s3-and-cloudfront' )
)
);
}
// We currently have one licence applied to a plugin install.
$this->as3cf->remove_licence();
return $this->rest_ensure_response( 'delete', static::name(), array(
'licences' => $this->as3cf->get_licences(),
) );
}
}