Error: How to allow the “contributor” to upload media in wordpress

This is what I just used, maybe there was a problem in past versions of WordPress or your theme.

function allow_contrib_upload() {

    // get the role
    $contrib = get_role( 'contributor' );

    // add the upload capability
    $contrib->add_cap( 'upload_files' );
}
add_action( 'admin_init', 'allow_contrib_upload', 11 );