https://github.com/getolympus/olympus-dionysos-field-select
Διώνυσος — Select / Multiselect field, this component is a part of the Olympus Dionysos fields for WordPress.
https://github.com/getolympus/olympus-dionysos-field-select
custom field framework multiselect olympus-zeus php select twig wordpress
Last synced: 23 days ago
JSON representation
Διώνυσος — Select / Multiselect field, this component is a part of the Olympus Dionysos fields for WordPress.
- Host: GitHub
- URL: https://github.com/getolympus/olympus-dionysos-field-select
- Owner: GetOlympus
- License: mit
- Created: 2016-04-29T13:24:44.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-12-18T19:53:06.000Z (over 1 year ago)
- Last Synced: 2025-02-15T02:22:06.063Z (3 months ago)
- Topics: custom, field, framework, multiselect, olympus-zeus, php, select, twig, wordpress
- Language: PHP
- Homepage:
- Size: 29.3 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dionysos Select Field
[![Olympus Component][olympus-image]][olympus-url]
[![CodeFactor Grade][codefactor-image]][codefactor-url]
[![Packagist Version][packagist-image]][packagist-url]
[![MIT][license-image]][license-blob]> This component is a part of the **Olympus Dionysos fields** for **WordPress**.
> It uses the default WordPress select or multiselect field.```sh
composer require getolympus/olympus-dionysos-field-select
```---
## Table of contents
[Field initialization](#field-initialization) • [Variables definition](#variables-definition) • [Texts definition](#texts-definition) • [Retrive data](#retrive-data) • [Release history](#release-history) • [Contributing](#contributing)
---
## Field initialization
Use the following lines to add a `select field` in your **WordPress** admin pages or custom post type meta fields:
```php
// Uniq choice version
return \GetOlympus\Dionysos\Field\Select::build('my_select_field_id', [
'title' => 'Select a Minion that you may know',
'default' => 'kevin',
'description' => 'A very important question! Pay attention to it ;)',
'multiple' => false,
'options' => [
'kevin' => 'Kevin',
'mel' => 'Mel',
'dave' => 'Dave',
'bob' => 'Bob',
],/**
* Texts definition
* @see the `Texts definition` section below
*/
't_keyboard' => 'Press the CTRL or CMD button to select more than one option.',
't_no_options' => 'The field does no have any options.',
]);
``````php
// Multiple choice version
return \GetOlympus\Dionysos\Field\Select::build('my_multiselect_field_id', [
'title' => 'What are your preferred personas?',
'default' => ['minions', 'lapinscretins'],
'description' => 'The White House needs your feedback asap!',
'multiple' => true,
'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_keyboard' => 'Press the CTRL or CMD button to select more than one option.',
't_no_options' => 'The field does no have any options.',
]);
```## Variables definition
The variables definition depends on `multiple` value:
- set to `false`, a uniq string value is stored in Database
- set to `true`, an array of key values is stored in DatabaseIn all cases:
| Variable | Type | Default value if not set | Accepted values |
| ------------- | ------- | ------------------------ | --------------- |
| `title` | String | `'Radio button'` | *empty* |
| `description` | String | *empty* | *empty* |
| `options` | Array | *empty* | Array with a key/value options |### Uniq choice
| Variable | Type | Default value if not set | Accepted values |
| ------------- | ------- | ------------------------ | --------------- |
| `default` | String | *empty string* | One of the options keys |
| `multiple` | Boolean | `false` | *nothing else* |### Multiple choices
| Variable | Type | Default value if not set | Accepted values |
| ------------- | ------- | ------------------------ | --------------- |
| `default` | String | *empty array* | Array with options keys |
| `multiple` | Boolean | `true` | *nothing else* |## Texts definition
| Code | Default value | Definition |
| ---- | ------------- | ---------- |
| `t_keyboard` | Press the CTRL or CMD
button to select more than one
option. | Used as a notice to help users to user multiselect field |
| `t_no_options` | The field does no have any options. | Used as an error in the case no options have been set |## Retrive data
Retrieve your value from Database with a simple `get_option('my_select_field_id', '')` or `get_option('my_multiselect_field_id', [])` (see [WordPress reference][getoption-url]):
```php
// Get select from Database
$select = get_option('my_select_field_id', '');// Display value
echo '';
'.$select.', master of the ceremony// Get multiselect from Database
$multiselect = get_option('my_multiselect_field_id', []);if (!empty($multiselect)) {
echo 'And the nominees are:
';
echo '
- ';
- '.$value.' '; // Will display key item options!
foreach ($multiselect as $value) {
echo '
}
echo '
}
```
## Release History
| Version | Note |
| :------ | :--- |
| 0.0.12 | Change main css class |
| 0.0.11 | New Olympus components compatibility
Change repository to be a part of Dionysos fields |
| 0.0.10 | Remove twig dependency from composer |
## Contributing
1. Fork it ()
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](https://github.com/crewstyle "Achraf Chouk") ~ (c) since a long time.**
[olympus-image]: https://img.shields.io/badge/for-Olympus-44cc11.svg?style=flat-square
[olympus-url]: https://github.com/GetOlympus
[codefactor-image]: https://www.codefactor.io/repository/github/GetOlympus/olympus-dionysos-field-select/badge?style=flat-square
[codefactor-url]: https://www.codefactor.io/repository/github/getolympus/olympus-dionysos-field-select
[getoption-url]: https://developer.wordpress.org/reference/functions/get_option/
[license-blob]: https://github.com/GetOlympus/olympus-dionysos-field-select/blob/master/LICENSE
[license-image]: https://img.shields.io/badge/license-MIT_License-blue.svg?style=flat-square
[packagist-image]: https://img.shields.io/packagist/v/getolympus/olympus-dionysos-field-select.svg?style=flat-square
[packagist-url]: https://packagist.org/packages/getolympus/olympus-dionysos-field-select