WordPress how to limit upload size

22. janvāris, 2019
PHP
add_filter('wp_handle_upload_prefilter', 'handle_upload_prefilter');
public function wp_handle_upload_prefilter($file) {    
    if (!is_array($file)) {
        return $file;
    }

    if (in_array($file['type'], ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'])) {
        if ($file['size'] > 1024 * 500) {
            $file['error'] = 'Image size is too big. Resize it!';
        }
    }

    return $file;
}