Skip to main content
1 of 3
Nicolai Grossherr
  • 18.9k
  • 8
  • 64
  • 109

You can restrict the file size via the wp_handle_upload_prefilter, where

The single parameter, $file, represent a single element of the $_FILES array.

The code below is just exemplary and untested, but you'll get the point.

add_filter(
    'wp_handle_upload_prefilter',
    'wpse163236_restrict_upload_file_size'
);
function wpse163236_restrict_upload_file_size( $file ){
    $file_size  = $file[ 'size' ];
    $size_limit = '1024';
    if ( $size_limit < $file_size ) {
        $file[ 'error' ] = 'File Size Over: ' . $file_size_limit;
    }
    return $file;
}
Nicolai Grossherr
  • 18.9k
  • 8
  • 64
  • 109