Limit the file size
If you need to limit the upload file size you can use the below code snippet.
In the code snippet, we are limiting the file size to 1 MB. Please change the value to your preferred choice.
1
function awsm_application_upload_size_limit( $size ) {
2
if ( is_singular( 'awsm_job_openings' ) ) {
3
$size = 1 * 1024 * 1024; // 1 MB
4
}
5
return $size;
6
}
7
add_filter( 'upload_size_limit', 'awsm_application_upload_size_limit' );
8
9
function awsm_job_application_submitting() {
10
global $awsm_response;
11
if ( count( $awsm_response['error'] ) === 0 && isset( $_FILES ) && count( $_FILES ) > 0 ) {
12
$error = false;
13
foreach ( $_FILES as $file ) {
14
$limit = 1 * 1024 * 1024; // 1 MB
15
if ( $file['size'] > $limit ) {
16
$error = true;
17
}
18
}
19
if ( $error ) {
20
$awsm_response['error'][] = 'The file you have selected is too large';
21
}
22
}
23
}
24
add_action( 'awsm_job_application_submitting', 'awsm_job_application_submitting' );
Copied!
Last modified 7mo ago
Copy link