Kirki: Upload control in Repeater

Created on 16 Aug 2018  路  7Comments  路  Source: kirki-framework/kirki

Issue description:

Hey @aristath,

It seems like when using an upload control inside a repeater, I cannot select any other files than images. Uploading files (non-images) works.

It also works great outside the repeater field.
Please see the examples below.

Version used:

3.0.33

Using theme_mods or options?

Code to reproduce the issue (config + field(s))

doesn't work:

Kirki::add_field( 'config_id', array(
    'type'              =>          'repeater',
    'label'             =>          esc_attr__( 'Repeater Upload', 'textdomain' ),
    'settings'          =>          'prefix_setting',
    'priority'          =>          '3',
    'section'           =>          'prefix_section',
    'row_label'         =>          array(
        'type'          =>          'text',
        'value'         =>          esc_attr__( 'Row Label', 'textdomain' ),
        ),
    'fields'            =>          array(
        'upload_field'  =>      array(
            'type'      =>      'upload',
            'label'     =>      esc_attr__( 'Upload', 'textdomain' ),
        ),
    ),
));

works:

Kirki::add_field( 'theme_config_id', array(
    'type'        => 'upload',
    'settings'    => 'upload_setting_url',
    'label'       => esc_attr__( 'Upload Control, 'textdomain' ),
    'section'     => 'section_id',
    'default'     => '',
) );
bug repeater

Most helpful comment

Thanks @aristath! :)

Here's something else I've noticed. I saw there were some other posts on that I think that were resolved but the "remove" text doesn't show up for me.

bildschirmfoto 2018-08-23 um 18 35 21

Just letting you know :)

Have a great day!

All 7 comments

After digging a bit deeper, here's what we got:

I was able to make all mime types showing up by adding this to the repeater field above:

'mime_type' => array()

Unfortunately, something like this didn't work and didn't show any files when clicking on the "Add File" button:

'mime_type' => ['application/x-font-woff']

So this is partially resolved since I can show all mime_types. There seems to be a bug or I'm simply doing it wrong with a more specific mime_type setting.

Marking as a bug :+1:

Thanks @aristath! :)

Here's something else I've noticed. I saw there were some other posts on that I think that were resolved but the "remove" text doesn't show up for me.

bildschirmfoto 2018-08-23 um 18 35 21

Just letting you know :)

Have a great day!

Looks like it's an issue within kirki/controls/php/class-kirki-control-repeater.php.
Line 388 have the correct remove button (used for field.type === 'image' || field.type === 'cropped_image') but line 420 has the remove button without a label (for field.type === 'upload').
The issue can be resolved by simply copying line 388 to 420.

Fix was merged.

After digging a bit deeper, here's what we got:

I was able to make all mime types showing up by adding this to the repeater field above:

'mime_type' => array()

Unfortunately, something like this didn't work and didn't show any files when clicking on the "Add File" button:

'mime_type' => ['application/x-font-woff']

So this is partially resolved since I can show all mime_types. There seems to be a bug or I'm simply doing it wrong with a more specific mime_type setting.

Where should i place the mime_type param? i have tried to place it in repeater field, but still can't upload the woff file.

Solved by filtering upload_mimes

add_filter('upload_mimes', 'add_custom_upload_mimes');
function add_custom_upload_mimes($existing_mimes) {
  $existing_mimes['otf'] = 'application/x-font-otf';
  $existing_mimes['woff'] = 'application/x-font-woff';
  $existing_mimes['woff2'] = 'application/x-font-woff2';
  $existing_mimes['ttf'] = 'application/x-font-ttf';
  $existing_mimes['svg'] = 'image/svg+xml';
  $existing_mimes['eot'] = 'application/vnd.ms-fontobject';
  return $existing_mimes;
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

hussainnayani picture hussainnayani  路  4Comments

manuelmoreale picture manuelmoreale  路  3Comments

ravishakya picture ravishakya  路  7Comments

MapSteps picture MapSteps  路  6Comments

rahulv3a picture rahulv3a  路  3Comments