Skip Navigation

[Resolved] Change file upload error text, add maximum upload file size

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use different text in the CRED form image upload error alert. I would like to add the maximum upload size to my own custom text.

Solution:
Add the following code to functions.php:

add_filter( 'gettext', 'better_ajax_upload_filesize_error', 20, 3);
function better_ajax_upload_filesize_error( $translated_text, $text, $domain ) {
    if( $text == 'The file you uploaded it too large. You can upload files up to ' && $domain =='wp-cred' ){
        $translated_text = "The file you attempted to upload is too large. You can upload files up to ";
    }
    return $translated_text;
}
This support ticket is created 7 years ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 6 replies, has 2 voices.

Last updated by Marco 7 years ago.

Assisted by: Christian Cox.

Author
Posts
#588904
Schermafbeelding 2017-11-12 om 13.24.12.png

Tell us what you are trying to do? The user may only upload a file of max 2 MB. How can I handle this via CRED and provide an error message?

What is the link to your site? hidden link

#588971

Hi, you can provide your own translation for the text shown in this alert if you would like. If you're using WPML String Translation, you can find the string in the domain "wp_cred". Otherwise, you can add some code to your theme to override the current translation:

add_filter( 'gettext', 'better_ajax_upload_filesize_error', 20, 3 );
/**
 * @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
 */
function better_ajax_upload_filesize_error( $translated_text, $text, $domain ) {
    if($text == 'The uploaded file exceeds the upload_max_filesize directive in php.ini' && $domain = 'wp-cred'){
        $translated_text = "Your translation here";
    }
    return $translated_text;
}
#589123

Thanks,

I placed the code in function.php, but the message stays the same...
What did i do wrong?
I dont use WPML.

#589257
Schermafbeelding 2017-11-13 om 21.55.46.png

Sorry, but now I don't see any message.

Is there something wrong in the Function.php?

See Uploaded image.

#589581

Okay, for now please comment out or remove the filter in your PHP code. Would it be possible for me to log in and see this in the browser? I'd like to know where the process is breaking down. If that's okay with you, please provide login credentials here in the private reply fields and let me know how to access this form on the front-end.

#589634

Hi, I added an updated error message in functions-additional.php. You can modify the text however you would like. The string "2,00 MB" will be added at the end automatically. Let me know if you have additional questions about that.

add_filter( 'gettext', 'better_ajax_upload_filesize_error', 20, 3);
function better_ajax_upload_filesize_error( $translated_text, $text, $domain ) {
    if( $text == 'The file you uploaded it too large. You can upload files up to ' && $domain =='wp-cred' ){
        $translated_text = "The file you attempted to upload is too large. You can upload files up to ";
    }
    return $translated_text;
}
#589685

Thanks!!!!!

It works great!

The forum ‘Types Community Support’ is closed to new topics and replies.