
If you have contributors to your blog, you probably got annoyed to see that they can’t upload files and images while writing guest posts for you. Today’s recipe will solve the problem, allowing contributors to upload files to your blog.

If you have contributors to your blog, you probably got annoyed to see that they can’t upload files and images while writing guest posts for you. Today’s recipe will solve the problem, allowing contributors to upload files to your blog.
Nothng hard with this code: The only thing you have to do is to paste it in your functions.php file:
if ( current_user_can('contributor') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
Big thanks to Altaf Sayani for his contribution to WpRecipes!
9 Responses
You might want to fix the HTML entities in the code; if someone copies & pastes that as is, a parse error is in their future.
@Rick Beckman: Thanks! Just fixed it.
I think it’s better just using the roles and capabilities plugins.
I’m actually using the same hack, except I got through all the code that it executes.
During the process, I noticed one important thing – if you remove this snippet, your contributors’ capabilities will remain the same – this function modifies capabilities permanently in the database.
Therefore, to undo, you have to first execute remove_cap() at least once, and then remove the snippet.
and again – good idea but horrible code – 1-2 SQL queries for every visit of every visitor of any page. Add it e.g. to the login action, if you want to do it this way, but much better is just to add this capability to the contributor role and check it for every existing contributor
@Tomas
actually, it just proves you don’t know how WordPress internals work. There are no extra SQL queries that run in the if statement. Look up wp_options and “autoload” before making these accusations.
However, regardless of whether there are SQL queries or not, this code is indeed superfluous after you load it one time, as I mentioned before. Might as well just comment it out after the first page run.
Thanks for the code, just wanted to make downloading files
how to write functions. I am a total new person and dont have technical background of web programing or designing.
my current funtions.php contains following code. pls guide if i want to add above code in my file
(i am using sail-away theme)
***
”,
‘after_widget’ => ”,
‘before_title’ => ”,
‘after_title’ => ”,
));
?>
Trackbacks: