Using WordPress ‘import_upload_size_limit’ PHP filter

The import_upload_size_limit WordPress PHP Filter allows you to modify the maximum allowed upload size for import files.

Usage

add_filter('import_upload_size_limit', 'your_custom_function');

function your_custom_function($max_upload_size) {
  // your custom code here
  return $max_upload_size;
}

Parameters

  • $max_upload_size (int) – Allowed upload size. Default 1 MB.

More information

See WordPress Developer Resources: import_upload_size_limit

Examples

Increase the maximum upload size

Increase the maximum allowed upload size to 5 MB.

add_filter('import_upload_size_limit', 'increase_import_upload_size_limit');

function increase_import_upload_size_limit($max_upload_size) {
  return 5 * 1024 * 1024; // 5 MB
}

Decrease the maximum upload size

Decrease the maximum allowed upload size to 500 KB.

add_filter('import_upload_size_limit', 'decrease_import_upload_size_limit');

function decrease_import_upload_size_limit($max_upload_size) {
  return 500 * 1024; // 500 KB
}

Set the maximum upload size based on user role

Allow administrators to upload larger import files (10 MB) and keep the default limit for other users.

add_filter('import_upload_size_limit', 'set_upload_size_based_on_role');

function set_upload_size_based_on_role($max_upload_size) {
  if (current_user_can('activate_plugins')) {
    return 10 * 1024 * 1024; // 10 MB for administrators
  }
  return $max_upload_size; // Default limit for other users
}

Disable imports by setting the maximum upload size to zero

Disallows file imports by setting the maximum allowed upload size to 0.

add_filter('import_upload_size_limit', 'disable_imports');

function disable_imports($max_upload_size) {
  return 0; // Disable imports
}

Set the maximum upload size based on file extension

Allow larger upload sizes for XML files (3 MB) and keep the default limit for other file types.

add_filter('import_upload_size_limit', 'set_upload_size_based_on_file_extension', 10, 2);

function set_upload_size_based_on_file_extension($max_upload_size, $extension) {
if ($extension === ‘xml’) {
return 3 * 1024 * 1024; // 3 MB for XML files
}
return $max_upload_size; // Default limit for other file types
}