Tuesday, January 23, 2018

Wordpress - Set the maximum upload size limit for non-administrators.

/**
 * Set the upload size limit for non-administrators.
 * @param string $size Upload size limit (in bytes).
 * @return int (maybe) Filtered size limit.
 */
function filter_site_upload_size_limit( $size ) {
    // Set the upload size limit to 2 MB for users lacking the 'manage_options' capability.
    if ( ! current_user_can( 'manage_options' ) ) {
        // 2 MB.
        $size = 2 * 1024* 1024;
    }
    return $size;
}
add_filter( 'upload_size_limit', 'filter_site_upload_size_limit', 2 );

No comments: