Okey so this is just an example how you can archive this..
First change the upload directory to the current users username. eg uploads/admin
function wpse_16722_type_upload_dir( $args ) {
// Get current user data
$current_user = wp_get_current_user();
// Make upload dir to current username
$newdir="https://wordpress.stackexchange.com/" . $current_user->user_login;
$args['path'] = str_replace( $args['subdir'], '', $args['path'] ); //remove default subdir
$args['url'] = str_replace( $args['subdir'], '', $args['url'] );
$args['subdir'] = $newdir;
$args['path'] .= $newdir;
$args['url'] .= $newdir;
return $args;
}
add_filter( 'upload_dir', 'wpse_16722_type_upload_dir' );
Then we need a function to check the size of the current users uploads. I found a function called recurse_dirsize
within ms-functions.php that calculate the directory in bytes.
/**
* Get the size of a directory recursively.
*
* Used by get_dirsize() to get a directory's size when it contains
* other directories.
*
* @since MU
*
* @param string $directory
* @return int
*/
function recurse_dirsize( $directory ) {
$size = 0;
$directory = untrailingslashit( $directory );
if ( !file_exists($directory) || !is_dir( $directory ) || !is_readable( $directory ) )
return false;
if ($handle = opendir($directory)) {
while(($file = readdir($handle)) !== false) {
$path = $directory."https://wordpress.stackexchange.com/".$file;
if ($file != '.' && $file != '..') {
if (is_file($path)) {
$size += filesize($path);
} elseif (is_dir($path)) {
$handlesize = recurse_dirsize($path);
if ($handlesize > 0)
$size += $handlesize;
}
}
}
closedir($handle);
}
return $size;
}
And then we need to check if the current users uploads is bigger than x if so disable media_buttons
function wpse_16722_user_upload_size() {
// Get current user data
$current_user = wp_get_current_user();
// Array of key => value pairs
$uploads = wp_upload_dir();
$dir = $uploads['basedir'] . "https://wordpress.stackexchange.com/" . $current_user->user_login;
if( file_exists( $dir ) && is_dir( $dir ) ) {
$size = recurse_dirsize( $dir ) / 1024 / 1024;
// Convert bytes to human readable format
$new_size = round( $size / 1024 * 1024, 2 );
// If current users upload dir is
// Bigger than 20 MB disable
// Upload buttton
if( $new_size >= 20 ) {
remove_action( 'media_buttons', 'media_buttons' );
}
}
}
add_action('admin_head', 'wpse_16722_user_upload_size');
You also wanted to control more than one user and different sizes. I would recommend you to add a settings-page that saves the users available size with update_user_meta($user_id, 'size_limit', $value );
Read more about that here
When you have the sizes added to the users_meta
you can change the size within the function wpse_16722_user_upload_size
“20” to the size within get_user_meta( $user_id, 'size_limit');