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

Latest commit

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


Type Name Latest commit message Commit time
Failed to load latest commit information.

Upload Field

This component is a part of the Olympus Zeus Core WordPress framework.
It uses the default WordPress media upload component.

Olympus Component CodeFactor Grade Packagist Version


Using composer in your PHP project:

composer require getolympus/olympus-upload-field

Field initialization

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

return \GetOlympus\Field\Upload::build('my_upload_field_id', [
    'title'       => 'What\'s your flavor?',
    'can_upload'  => false,
    'default'     => [],
    'description' => 'Tell me what\'s your flavour!',
    'multiple'    => false,
    'type'        => 'image',
    'size'        => 'thumbnail',

     * Texts definition
     * @see the `Texts definition` section below
    't_add_media'     => 'Add media',
    't_add_medias'    => 'Add medias',
    't_delete_item'   => 'Delete selection',
    't_delete_all'    => 'Delete all medias',
    't_cannot_upload' => 'It seems you are not able to upload files.',
    't_dimensions'    => 'Dimensions:',
    't_label'         => 'Title:',
    't_size'          => 'Size:',
    't_url'           => 'URL:',

Variables definition

Variable Type Default value if not set Accepted values
title String 'Upload' empty
can_upload Boolean false true or false
default Array empty empty
description String empty empty
multiple Boolean false true or false
type String 'image' default file mime types
size String 'thumbnail' image sizes from add_image_size() WordPress function


  • can_upload value is defined thanks to current_user_can('upload_files') (see WordPress reference)
  • Set multiple to true to enable the "Add medias" button

Texts definition

Code Default value Definition
t_add_media Add media Used as an add media label button
t_add_medias Add medias Used as an add medias label button if multiple is set to true
t_delete_item Delete selection Used as a delete selection label button
t_delete_all Delete all medias Used as a delete medias label button
t_cannot_upload It seems you are not able to upload files. Used as an error if user cannot upload files
t_dimensions Dimensions: Dimension image label
t_label Title: Title image label
t_size Size: Size image label
t_url URL: Url image label

Retrive data

Retrieve your value from Database with a simple get_option('my_upload_field_id', []) (see WordPress reference). Below, a json_encode() example to understand how data are stored in Database:

  "mediaId": {
    "name": "mediaName.mediaExt",
    "id": "mediaId",
    "height": "mediaHeight",
    "url": "mediaUrl",
    "width": "mediaWidth"

And below, a simple example to show how to iterate on the data array in PHP:

// Get upload from Database
$upload = get_option('my_upload_field_id', []);

if (!empty($upload)) {
    foreach ($upload as $img) {
        echo '<figure id="'.$img['id'].'">';
        echo '<img src="'.$img['url'].'" width="'.$img['width'].'" height="'.$img['height'].'" alt="'.esc_html($img['name']).'" />';
        echo '<figcaption>'.$img['name'].'</figcaption>';
        echo '</figure>';

Release History

  • 0.0.12
  • FIX: remove twig dependency from composer
  • 0.0.11
  • FIX: remove zeus-core dependency from composer
  • 0.0.10
  • ADD: new assets folder

Authors and Copyright

Achraf Chouk

Please, read LICENSE for more information.


  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 ~ (c) since a long time.

You can’t perform that action at this time.