Last active
April 17, 2020 17:48
-
-
Save Kyzoe/52a608eba33c8ae298ca9484476ed34c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WP - LIMIT IMAGE UPLOAD SIZE | |
function max_image_size( $file ) { | |
$size = $file['size']; | |
$size = $size / 1024; | |
$type = $file['type']; | |
$is_image = strpos( $type, 'image' ) !== false; | |
$limit = 850; | |
$limit_output = '850KB'; | |
if ( $is_image && $size > $limit ) { | |
$file['error'] = 'Image files must be smaller than ' . $limit_output; | |
}//end if | |
return $file; | |
}//end max_image_size() | |
add_filter( 'wp_handle_upload_prefilter', 'max_image_size' ); | |
// WP - LIMIT IMAGE UPLOAD SIZE - CHANGE FRONT END TEXT | |
add_action('wp_head', 'file_size_limit_string'); | |
function file_size_limit_string(){ | |
?> | |
<script type="text/javascript"> | |
(function($){ | |
$(document).ready(function($){ | |
//CHANGE THE FILE UPLOAD SIZE LIMIT MESSAGE ON FRONT-END IMAGE UPLOADERS | |
$('#submit-job-form .file-upload-field small').text('Maximum file size: 850KB.'); | |
}); | |
})(jQuery); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment