getolympus/olympus-dionysos-field-code

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

v0.0.14 2023-12-20 22:09 UTC

This package is auto-updated.

Last update: 2024-10-20 23:47:22 UTC


README

Dionysos Code Field

Olympus Component CodeFactor Grade Packagist Version MIT

This component is a part of the Olympus Dionysos fields for WordPress.
It uses the default WordPress code field made with a complete integration with codemirror JS component.

composer require getolympus/olympus-dionysos-field-code

Table of contents

Field initializationVariables definitionAccepted modeRetrive dataRelease HistoryContributing

Field initialization

Use the following lines to add a code field in your WordPress admin pages or custom post type meta fields:

return \GetOlympus\Dionysos\Field\Code::build('my_code_field_id', [
    'title'       => 'How do Penguins code their icebergs?',
    'default'     => 'With a frozen bug.',
    'description' => 'A simple question to let you know how to seduce a penguin.',
    'mode'        => 'json',
    'rows'        => 4,

    /**
     * Code mirror settings
     * @see https://developer.wordpress.org/reference/functions/wp_get_code_editor_settings/
     */
    'settings' => [
        'indentUnit'     => 2,
        'indentWithTabs' => false,
        'tabSize'        => 2,
    ],
]);

Variables definition

Accepted mode

  • text/css or css
  • text/x-diff or x-diff or diff
  • text/html or html
  • text/javascript or javascript or js
  • application/json or json
  • text/x-markdown or markdown or md
  • application/x-httpd-php or x-httpd-php or php
  • text/x-python or x-python or python
  • text/x-ruby or x-ruby or ruby
  • text/x-sh or x-sh or sh
  • text/x-mysql or x-mysql or mysql
  • text/x-mariadb or x-mariadb or mariadb
  • application/xml or xml
  • text/x-yaml or x-yaml or yaml

Usage example

Fill the form properly (with JSON in this example):

{
    "response": "With a frozen bug."
}

Retrive data

Retrieve your value from Database with a simple get_option('my_code_field_id', '') (see WordPress reference):

// Get code from Database
$code = get_option('my_code_field_id', '');

// Display code in HTML tag
echo '<pre>'.htmlspecialchars($code).'</pre>';

Release history

Contributing

  1. Fork it (https://github.com/GetOlympus/olympus-dionysos-field-code/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.