Skip to content

GetOlympus/olympus-dionysos-field-oembed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dionysos oEmbed Field

Olympus Component CodeFactor Grade Packagist Version MIT

This component is a part of the Olympus Dionysos fields for WordPress.

composer require getolympus/olympus-dionysos-field-oembed

Table of contents

Field initializationVariables definitionTexts definitionRetrive dataRelease historyContributing


Field initialization

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',
]);

Variables definition

Variable Type Default value if not set Accepted values
title String 'oEmbed' empty
default Array empty empty
description String empty empty

Texts definition

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

Retrive data

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']);
}

Release history

Version Note
0.0.5 Fix jQuery integration on domReady
0.0.4 Fix JS ready
0.0.3 Better CSS display

Contributing

  1. Fork it (https://github.com/GetOlympus/olympus-dionysos-field-oembed/fork)
  2. Create your feature branch (git checkout -b feature/fooBar)
  3. Commit your changes (git commit -am 'Add some fooBar')
  4. Push to the branch (git push origin feature/fooBar)
  5. Create a new Pull Request

Built with ♥ by Achraf Chouk ~ (c) since a long time.

About

Διώνυσος — oEmbed field, this component is a part of the Olympus Dionysos fields for WordPress.

Resources

License

Stars

Watchers

Forks

Packages

No packages published