getolympus / olympus-dionysos-field-checkbox
Checkbox field, this component is a part of the Olympus Dionysos fields.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Language:Less
Type:olympus-field
Requires (Dev)
- phpunit/phpunit: ~5.3
README
This component is a part of the Olympus Dionysos fields for WordPress.
composer require getolympus/olympus-dionysos-field-checkbox
Field initialization
Use the following lines to add a checkbox field
in your WordPress admin pages or custom post type meta fields:
return \GetOlympus\Dionysos\Field\Checkbox::build('my_checkbox_field_id', [ 'title' => 'What are your preferred personas?', 'default' => ['minions', 'lapinscretins'], 'description' => 'The White House needs your feedback asap!', 'mode' => 'default', 'options' => [ 'minions' => 'The Minions', 'lapinscretins' => 'The Lapins Crétins', 'marvel' => 'All Marvel Superheroes', 'franklin' => 'Franklin (everything is possible)', 'spongebob' => 'Spongebob (nothing to say... Love it!)', ], /** * Texts definition * @see the `Texts definition` section below */ 't_no_options' => 'The field does no have any options.', ]);
Variables definition
The field display depends on mode
value:
- set to
default
(orinline
), labels options will be displayed on the same line, as aninline-block
display - set to
block
, labels options will be displayed each per line, as ablock
display - set to
image
, labels options will be displayed asdefault
mode, with images and overlay text label - set to
image-block
, labels options will be displayed asblock
mode, with images and overlay text label - set to
group
, labels options will be displayed as a simple but efficient group of choices
In all cases
Texts definition
Retrive data
Retrieve your value from Database with a simple get_option('my_checkbox_field_id', [])
(see WordPress reference):
// Get checkbox from Database $checkbox = get_option('my_checkbox_field_id', []); if (!empty($checkbox)) { echo '<p>And the nominees are:</p>'; echo '<ul>'; foreach ($checkbox as $value) { echo '<li>'.$value.'</li>'; // Will display key item options! } echo '</ul>'; }
Image mode
To display images instead of simple labels, set the mode
to image
and build the field's options as follow:
$options = [ 'key-name' => [ 'label' => 'Label item', 'image' => 'https://label-image-url', ], ];
Below, a full example:
return \GetOlympus\Dionysos\Field\Checkbox::build('my_checkbox_field_id', [ 'title' => 'Select a Minion that you may know', 'default' => 'dave', 'description' => 'A very important question! Pay attention to it ;)', 'mode' => 'image', 'options' => [ 'kevin' => [ 'label' => 'Kevin', 'image' => 'https://vignette.wikia.nocookie.net/despicableme/images/1/1d/Kevin_minions.png/revision/latest/scale-to-width-down/350?cb=20170703052012', ], 'mel' => [ 'label' => 'Mel', 'image' => 'https://vignette.wikia.nocookie.net/despicableme/images/2/2e/Mel_Minion_01.png/revision/latest/scale-to-width-down/350?cb=20160717135212', ], 'dave' => [ 'label' => 'Dave', 'image' => 'https://vignette.wikia.nocookie.net/despicableme/images/7/71/Daveholdingcupcake.png/revision/latest/scale-to-width-down/350?cb=20130717145735', ], 'bob' => [ 'label' => 'Bob', 'image' => 'https://vignette.wikia.nocookie.net/despicableme/images/c/ca/Bob-from-the-minions-movie.jpg/revision/latest/scale-to-width-down/350?cb=20151224154354', ], ], /** * Texts definitions * @see the `Texts definitions` section below */ 't_no_options' => 'The field does no have any options.', ]);
Release History
0.0.1
- Initial commit
Contributing
- Fork it (https://github.com/GetOlympus/olympus-dionysos-field-checkbox/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.