I saw earlier posts about this, but I’m trying to figure out if there’s a way to add images to answers. Also, is there a way that images can be added to questions, other than by giving users the Administrator label?
1 Answers
Hi,
About this issue, you can try add the following code to the functions.php
file:
function dw_custom_restrict_mime_types( $mime_types ) {
$mime_types = array(
'jpg|jpeg|jpe' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
'bmp' => 'image/bmp',
);
return $mime_types;
}
if ( is_user_logged_in() ) {
global $current_user;
$user = new WP_User( $current_user->id );
$user->add_cap( 'upload_files' );
$roles = $user->roles;
if (! in_array( 'administrator', $roles )) {
add_filter( 'upload_mimes', 'dw_custom_restrict_mime_types' );
}
} else {
$users = get_users( array( 'blog_id' => get_current_blog_id() ) );
if( $users ) {
foreach ($users as $user) {
$roles = $user->roles;
if ( ! in_array( 'administrator', $roles ) ) {
$user->remove_cap( 'upload_files' );
}
}
}
}
Hope this helps !
Please login or Register to submit your answer