getolympus/olympus-dionysos-field-oembed

oEmbed field, this component is a part of the Olympus Dionysos fields.

Installs: 166

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

Type:olympus-field

v0.0.4 2023-12-18 19:08 UTC

This package is auto-updated.

Last update: 2024-10-21 00:37:43 UTC


README

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

Texts definition

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

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.