Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WPJM: Limit file upload size
<?php
function limit_upload_size_limit_for_non_admin( $limit ) {
if ( ! current_user_can( 'manage_options' ) ) {
$limit = 1000000; // 1mb in bytes
}
return $limit;
}
add_filter( 'upload_size_limit', 'limit_upload_size_limit_for_non_admin' );
function apply_wp_handle_upload_prefilter( $file ) {
if ( ! current_user_can( 'manage_options' ) ) {
$limit = 1000000; // 1mb in bytes
if ( $file['size'] > $limit ) {
$file['error'] = __( 'Maximum filesize is 1mb', 'wp-job-manager' );
}
}
return $file;
}
add_filter( 'wp_handle_upload_prefilter', 'apply_wp_handle_upload_prefilter' );
?>
@godigi

This comment has been minimized.

Copy link

godigi commented Sep 2, 2016

10000 bytes does not equal 1 megabyte.

@codep0et

This comment has been minimized.

Copy link

codep0et commented Jul 10, 2017

I agree. This would bloque the upload at 0.01mb

@codep0et

This comment has been minimized.

Copy link

codep0et commented Jul 10, 2017

Basically it should read 1 million bytes : 1000000

@marekmaurizio

This comment has been minimized.

Copy link

marekmaurizio commented Feb 19, 2019

Came to say the same. This is the exact level of computer science knowledge you can expect from Wordpress plugin developers. Also number and string mix for no reason and lack of a better filer so they act on the whole Wordpress upload system. Terrible and sad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.