-
-
Save mmarj/8f27b5afa7dec7126e44dc27579116c8 to your computer and use it in GitHub Desktop.
WPJM: Limit file upload size
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
| <?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' ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment