Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // For the resource file upload - check that the file is a PDF under 1MB in size.
- add_filter('cred_form_ajax_upload_validate','cred_filetype_size_validation',10,2);
- function cred_filetype_size_validation($error_fields, $form_data)
- {
- //field data are field values and errors
- list($fields,$errors)=$error_fields;
- //validate if specific form
- if ( ($form_data['id']==358) || ($form_data['id']==473) )
- {
- if(isset($fields['wpcf-images'])) {
- //Retrieve file type
- $file_type_uploaded=$fields['wpcf-images']['field_data']['type'];
- //Retrieve file size
- $file_size_uploaded=$fields['wpcf-images']['field_data']['size'];
- //check if featured image exists
- if ( ($file_size_uploaded > 1000000) || ($file_type_uploaded != 'png') )
- {
- //set error message for featured image
- $errors['Resource File'] = 'Sorry the file you have uploaded is not of correct type (png) or exceeded 1MB limit';
- }
- }
- }
- //return result
- return array($fields,$errors);
- }
Advertisement
Add Comment
Please, Sign In to add comment