Plugin for CiSkeleton that provides a unified, consistent interface for embedding media from popular providers via oEmbed endpoints.
Supports automatic provider detection, runtime caching, persistent caching, response normalization, and dynamic provider registration.
- Auto Provider Detection: Embed URLs automatically detect YouTube, Vimeo, TikTok, Reddit, Dailymotion, Flickr, Twitter, etc.
- Normalized Responses: Consistent structure across providers for titles, authors, thumbnails, HTML, and more.
- Runtime & Persistent Caching: Avoid repeated API calls within a request and optionally store results in CiSkeleton cache.
- Dynamic Provider Registration: Add custom providers at runtime.
- Lightweight: Pure PHP, no external dependencies beyond CiSkeleton’s cURL helper.
- YouTube
- Vimeo
- Dailymotion
- Flickr
- Twitter/X
- TikTok
Note: Providers like SoundCloud and Instagram are omitted due to requiring Client ID or Access Tokens. You can add them via custom registration if needed.
- Install the plugin via
Plugins Browseror place it in yourapplication/plugins/directory if you have the package. - Ensure the folder structure includes:
src/services/CI_Oembed_service.php,src/metadata.php, andsrc/boot.php. - Enable the plugin on the dashboard.
- Load the service anywhere in your code using
$this->load->service('oembed'), or directly viaservice('oembed')helper. The latter returns the service's object.
Fetch oEmbed Data
// By loading the service:
$this->load->service('oembed');
$data = $this->oembed_service->fetch('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
// Or using service() helper:
$data = service('oembed')->fetch('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
// Then:
if ($data) {
echo $data['title']; // Video title
echo $data['author_name']; // Author
echo $data['html']; // Embeddable HTML
}Embed Directly in HTML
echo service('oembed')->to_html('https://www.tiktok.com/@user/video/123456789');You can register a new provider at runtime. Important: the URL must include a %s placeholder for the media URL.
// By loading the service:
$this->load->service('oembed');
$this->oembed_service->register(
'myprovider',
'https://api.myprovider.com/oembed?url=%s&access_token=XYZ',
['myprovider.com', 'mp.com']
);
// Or using service() helper:
service('oembed')->register(
'myprovider',
'https://api.myprovider.com/oembed?url=%s&access_token=XYZ',
['myprovider.com', 'mp.com']
);Then you can fetch embeds as usual:
// By loading the service:
$this->load->service('oembed');
$data = $this->oembed_service->fetch('https://myprovider.com/media/abc123');
// Or using service() helper:
$data = service('oembed')->fetch('https://myprovider.com/media/abc123');- Runtime (In-memory): Each request caches repeated fetches automatically.
- Persistent: Uses CiSkeleton’s cache driver if available.
- Cache key format:
oembed_{md5(provider + url)}. - Default TTL: 24 hours.
$data = service('oembed')->fetch($url, null, true); // true = cache enabled- Invalid URLs or unsupported providers return
false. - Attempting to register a provider without a
%splaceholder will throw anInvalidArgumentException.
MIT License. See LICENSE for details.
