The plupload_init WordPress PHP filter allows you to modify the default settings of the Plupload library used for handling file uploads.
Usage
add_filter('plupload_init', 'your_function_name');
function your_function_name($plupload_init) {
// your custom code here
return $plupload_init;
}
Parameters
$plupload_init(array) – An array of default settings used by Plupload.
More information
See WordPress Developer Resources: plupload_init
Examples
Changing the maximum file size
Change the maximum file size allowed for uploads to 5 MB.
add_filter('plupload_init', 'change_max_file_size');
function change_max_file_size($plupload_init) {
$plupload_init['filters']['max_file_size'] = '5mb';
return $plupload_init;
}
Restrict file types for upload
Allow only JPEG and PNG files to be uploaded.
add_filter('plupload_init', 'restrict_file_types');
function restrict_file_types($plupload_init) {
$plupload_init['filters']['mime_types'] = [
['title' => 'Allowed Image Types', 'extensions' => 'jpg,jpeg,png']
];
return $plupload_init;
}
Set custom chunk size
Set the chunk size for file uploads to 1 MB.
add_filter('plupload_init', 'set_custom_chunk_size');
function set_custom_chunk_size($plupload_init) {
$plupload_init['chunk_size'] = '1mb';
return $plupload_init;
}
Enable multi-selection in file dialog
Allow users to select multiple files at once in the file dialog.
add_filter('plupload_init', 'enable_multiselect');
function enable_multiselect($plupload_init) {
$plupload_init['multi_selection'] = true;
return $plupload_init;
}
Set custom error message for file size limit
Display a custom error message when the uploaded file exceeds the allowed file size.
add_filter('plupload_init', 'set_custom_file_size_error');
function set_custom_file_size_error($plupload_init) {
$plupload_init['filters']['max_file_size'] = '2mb';
$plupload_init['filters']['file_size_error'] = 'File size exceeds the allowed limit of 2 MB.';
return $plupload_init;
}