Decrease file size upload in Media

By default, I have a 2m limit of uploads. I want to decrease this number. I found out that this code:

function custom_file_max_upload_size( $file ) {
    $size = $file['size'];
    if ( $size > 1000 * 1024 ) { 
           $file['error'] = __( 'ERROR: you cannot upload files larger than 1M', 'textdomain' ); 

    }
    return $file;
}
add_filter ( 'wp_handle_upload_prefilter', 'custom_file_max_upload_size', 10, 1 );

works by adding to functions. However, it does not update the upload size information when the user is on upload screen. It still displays Maximum upload file size: 2MB. How can I change that text to 1mb? Or alternatively, a different approach to decrease the file size (that does not include editing php.ini or htaccess…)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

That number is taken from wp_max_upload_size(), and there is a filter: 'upload_size_limit'. See wp-admin/includes/template.php.

So this should work (not tested):

add_filter( 'upload_size_limit', 'wpse_70754_change_upload_size' );

function wpse_70754_change_upload_size()
{
    return 1000 * 1024;
}


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x