This component is a part of the Olympus Dionysos fields for WordPress.
composer require getolympus/olympus-dionysos-field-oembed
Field initialization • Variables definition • Texts definition • Retrive data • Release history • Contributing
Use the following lines to add an oembed field
in your WordPress admin pages or custom post type meta fields:
return \GetOlympus\Dionysos\Field\Oembed::build('my_oembed_field_id', [
'title' => 'Never gonna give you up!',
'default' => [
'url' => 'https://www.youtube.com/watch?v=Xxbd5keKhPU',
'height' => 1000,
'width' => 916,
'html' => '<iframe title="Popopooooo" width="916" height="515" src="https://www.youtube.com/embed/Xxbd5keKhPU?feature=oembed" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>',
],
'description' => 'You\'ve been Rick rolled!',
/**
* Texts definition
* @see the `Texts definition` section below
*/
't_addblock_label' => 'Enter URL here.',
't_removeblock_label' => 'Clear',
]);
Variable | Type | Default value if not set | Accepted values |
---|---|---|---|
title |
String | 'oEmbed' |
empty |
default |
Array | empty | empty |
description |
String | empty | empty |
Code | Default value | Definition |
---|---|---|
t_addblock_label |
Enter URL here | Used as an URL input placeholder |
t_removeblock_label |
Clear | Used as a Clear button area title |
Retrieve your value from Database with a simple get_option('my_oembed_field_id', [])
(see WordPress reference).
Below, a json_encode()
example to understand how data are stored in Database:
{
"url": "https://www.youtube.com/watch?v=Xxbd5keKhPU",
"height": 1000,
"width": 916,
"html": "<iframe title=\"Popopooooo\" width=\"916\" height=\"515\" src=\"https://www.youtube.com/embed/Xxbd5keKhPU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>"
}
And below, a simple example to show how to iterate on the data array in PHP
:
// Get embed from Database
$embed = get_option('my_oembed_field_id', []);
// Check if embed is empty and display it
if (!empty($embed)) {
echo stripcslashes($embed['html']);
}
Version | Note |
---|---|
0.0.5 | Fix jQuery integration on domReady |
0.0.4 | Fix JS ready |
0.0.3 | Better CSS display |
- Fork it (https://github.com/GetOlympus/olympus-dionysos-field-oembed/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request
Built with ♥ by Achraf Chouk ~ (c) since a long time.