Limit file upload size

Note: All code examples on this site are provided for developer reference/guidance only and we cannot guarantee that they will always work as expected. Our support policy does not include assistance with modifying or debugging code from any code examples, and they may be changed or removed if we find they no longer work due to changes in our plugins.

By default, WP Job Manager inherits the maximum file upload filesize from WordPress.

If you want to specify a maximum filesize, the following code will set the limit to 1mb for non-admins.

Add this code to the Code Snippets plugin.

<?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' );

If this doesn’t work, you may need to try a different way to change the limit. See this article for some suggestions.

Code Snippets Documentation