Using WordPress ‘plupload_default_settings’ PHP filter

The lupload_default_settings WordPress PHP filter allows you to modify the default Plupload settings.

Usage

add_filter('lupload_default_settings', 'your_custom_function');
function your_custom_function($defaults) {
  // your custom code here
  return $defaults;
}

Parameters

  • $defaults (array) – The default Plupload settings array.

More information

See WordPress Developer Resources: lupload_default_settings

Examples

Change max file size

Change the maximum file size allowed for uploads.

add_filter('lupload_default_settings', 'change_max_file_size');
function change_max_file_size($defaults) {
  $defaults['max_file_size'] = '10mb'; // Set max file size to 10 MB
  return $defaults;
}

Restrict file types

Restrict the allowed file types for uploads.

add_filter('lupload_default_settings', 'restrict_file_types');
function restrict_file_types($defaults) {
  $defaults['filters'] = array(array('title' => 'Allowed files', 'extensions' => 'jpg,jpeg,gif,png')); // Allow only image files
  return $defaults;
}

Enable multi-selection

Enable multiple file selection for uploads.

add_filter('lupload_default_settings', 'enable_multi_selection');
function enable_multi_selection($defaults) {
  $defaults['multi_selection'] = true; // Enable multi-selection
  return $defaults;
}

Change chunk size

Change the chunk size for file uploads.

add_filter('lupload_default_settings', 'change_chunk_size');
function change_chunk_size($defaults) {
  $defaults['chunk_size'] = '1mb'; // Set chunk size to 1 MB
  return $defaults;
}

Enable drag and drop

Enable drag and drop feature for file uploads.

add_filter('lupload_default_settings', 'enable_drag_drop');
function enable_drag_drop($defaults) {
  $defaults['dragdrop'] = true; // Enable drag and drop
  return $defaults;
}