Skip to content
Content field, this component is a part of the Olympus Zeus Core framework.
PHP HTML
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
languages
src
.gitignore
LICENSE
README.md
composer.json

README.md

Content Field

This component is a part of the Olympus Zeus Core WordPress framework.

Olympus Component CodeFactor Grade Packagist Version

Installation

Using composer in your PHP project:

composer require getolympus/olympus-content-field

Field initialization

Use the following lines to add a content field in your WordPress admin pages or custom post type meta fields:
Note that the $identifier (first ::build() parameter) is set to false useless because no value is stored in database.

return \GetOlympus\Field\Content::build(false, [
    'title'   => 'The Dark Knight',
    'content' => '',
    'debug'   => false,
    'file'    => 'im_the_batman.php',
    'vars'    => [
        'question' => 'Who\'s the Batman?',
        'answers'  => [
            'the-joker'    => 'The Joker',
            'harley-quinn' => 'Harley Quinn',
            'bruce-wayne'  => 'Bruce Wayne, don\'t tell anybody!',
            'gotham-city'  => 'Gotham City',
        ],
    ],
]);

Variables definitions

Variable Type Default value if not set Accepted values
title String 'File contents' empty
content String empty empty
debug Bookean empty empty
file String false true or false
vars Array empty empty

Notes:

  • Set content to display HTML tags. It can be used as a fallback if file doesn't exist
  • Set debug to true to enable the debug mode in case file inclusion fail
  • Set file to define the PHP file path to include as include_once PHP function

Vars usage

In the included file (im_the_batman.php in this example), you can use the $v variable as an array:

// Display question
echo '<h2>'.stripslashes($v['question']).'</h2>';
echo '<ul>';

// Display answers choices with radio button
foreach ($v['answers'] as $k => $answer) {
    echo '<li class="'.$k.' is-the-batman">'.stripslashes($answer).'</li>';
}

echo '</ul>';

Content display priority

The component will display, by priority:

  1. included file path
  2. everything in content

Note: do not forget to set debug to true to display an error in the case the file does not exist or is not readable.

Release History

  • 0.0.10
  • FIX: content raw display on twig file
  • 0.0.9
  • FIX: remove twig dependency from composer
  • 0.0.8
  • FIX: remove zeus-core dependency from composer

Authors and Copyright

Achraf Chouk
@crewstyle

Please, read LICENSE for more information.
MIT

https://github.com/crewstyle
https://fr.linkedin.com/in/achrafchouk

Contributing

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

You can’t perform that action at this time.