Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@danielbachhuber
Created March 14, 2014 15:48
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielbachhuber/9550397 to your computer and use it in GitHub Desktop.
Save danielbachhuber/9550397 to your computer and use it in GitHub Desktop.
In multisite, give editors and above the ability to upload whatever they want.
<?php
/**
* Allow editors and above to upload whatever they want
*/
add_filter( 'map_meta_cap', function( $caps, $cap, $user_id ) {
if ( 'unfiltered_upload' !== $cap ) {
return $caps;
}
if ( user_can( $user_id, 'edit_others_posts' ) ) {
if ( false !== ( $key = array_search( 'do_not_allow', $caps ) ) ) {
unset( $caps[ $key ] );
}
$caps[] = 'unfiltered_upload';
$caps = array_values( $caps );
}
return $caps;
}, 10, 3 );
/**
* Allow editors and above to upload whatever, part two
*/
add_filter( 'user_has_cap', function( $allcaps, $caps ) {
if ( ! in_array( 'unfiltered_upload', $caps ) ) {
return $allcaps;
}
$allcaps['unfiltered_upload'] = true;
return $allcaps;
}, 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment