Created
December 9, 2022 15:46
-
-
Save ideadude/ebbb51695a7056cb589aaa6a323e1240 to your computer and use it in GitHub Desktop.
Limit non-admin/editor file uploads to 2mb with WordPress
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 | |
/** | |
* Limit non-admin/editor file uploads to 2mb | |
* We check the upload_files capability, | |
* so anyone with access to the Media Library | |
* can upload files at the PHP/server set max. | |
* | |
* You can add this recipe to your site by creating a custom plugin | |
* or using the Code Snippets plugin available for free in the WordPress repository. | |
* Read this companion article for step-by-step directions on either method. | |
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function my_upload_size_limit_for_non_admins( $size ) { | |
if ( ! current_user_can( 'upload_files' ) ) { | |
$size = 2 * 1024; // 2 megabytes | |
} | |
return $size; | |
} | |
add_filter( 'upload_size_limit', 'my_upload_size_limit_for_non_admins' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment