cloudProvider = $cloudProvider; } /** * Register the observer with WordPress hooks. * * @return void */ public function register(): void { add_filter('wp_get_attachment_url', [$this, 'run'], 10, 2); } /** * Modify the attachment URL if the media is offloaded. * * @param string $url The original URL. * @param int $post_id The attachment ID. * @return string The modified URL. */ public function run(string $url, int $post_id): string { if ($this->is_offloaded($post_id)) { $subDir = $this->get_attachment_subdir($post_id); $url = rtrim($this->cloudProvider->getDomain(), '/') . '/' . ltrim($subDir, '/') . basename($url); } return $url; } }