Skip Navigation

[Resolved] Can add an *.ico to an image field, but when editing form only shows link

This support ticket is created 7 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by lindsayH 7 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#419362
chrome_2016-07-25_16-39-51.png
chrome_2016-07-25_16-31-12.png

I realise you maybe shouldn't upload an *.ico image, but when adding to a new form it allows me to do so, and adds a path (see path in Main Image of larger attached image). Same with *.tif.

If I try to add a *.bmp then I get advised I can't add - 'You can add only images.' It would be good to add *.ico\*.tif to files not allowed to be uploaded.

#419617

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Lindsay

I think my original reply to you was lost, so here goes again...

CRED doesn't have any in-built means to restrict the file types that can be uploaded to an image custom field. But while digging around I did notice that when the form markup is printed the data-attribute used to specify the allowable extensions passes through a filter which gives us a chance to intervene and modify it.

You need to know the id of your CRED form (107 in my example code below) and you need to set this for each form as required. I added the following to my functions.php and tested it and it worked. Caveat: you may need to tweak this for your own purposes and the code provided is unsupported.

add_filter('wptoolset_forms_field_js_validation_data_cred_form_107_1', 'set_image_types', 99, 1);
function set_image_types( $params ) {

	if ( isset($params['extension']) ) {

		$params['extension']['args'][0] = "jpeg|jpg|png";
		$params['extension']['message'] = "You can only add jpeg, jpg, or png images";
	}
	return $params;
}
#419629
chrome_2016-07-25_16-39-51.png

That works well, thank you.

I did already get a similar prompt (see image attached) but was only working for word docs\bmp files etc.. it 'let through' ico and tifs, even though just displayed path then unable to delete (delete button didn't show after save).

So JFYI although the code snippet really useful it's like there is something already partially setup?

#419634

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

That list of allowed extensions by default looks like:

bmp|gif|ico|jpeg|jpg|png|svg|webp

WordPress itself maintains a list of allowable extensions for uploads which evolves over time and it is possible that the two may get out of sync (e.g. "allowed" by Toolset but no longer allowed by WordPress) which could account for errors when trying to add a "permitted" file type.

I haven't investigated but suspect that may be the reason.

#419637

Thanks for the excellent information and great code snippet. Snippet works well for me at the moment, but will monitor.

This ticket is now closed. If you're a Toolset client and need related help, please open a new support ticket.