Services
StorageServiceInterface
v1.0.0File storage interface for uploads, generated assets, and public URLs.
Access
$ctx->storage()?->put('reports/latest.json', $json);How To Use It
- Use it when the module owns generated files, exports, or uploaded assets that need a stable runtime path and URL.
- Check existence and retrieve public URLs through the service instead of manually assuming a WordPress uploads path layout.
Works Well With
Methods
public function put(string $path, string $contents): stringStores a file and returns the resolved storage path.
public function get(string $path): ?stringReads a stored file and returns its contents or null when missing.
public function delete(string $path): boolDeletes a stored file and reports success.
public function exists(string $path): boolChecks whether a stored file exists.
public function url(string $path): stringReturns the public URL for a stored file.
Example
bootstrap.php
public function exportReport(SdkContext $ctx, array $report): string
{
$path = $ctx->storage()?->put(
'reports/latest.json',
wp_json_encode($report, JSON_PRETTY_PRINT) ?: '{}'
);
return $ctx->storage()?->url($path ?? 'reports/latest.json') ?? '';
}