How to make user to add image in comment or answer ?
this is my page : http://jogjasky.com/forum/
i want to make my forum feature same as this forum where user can attach image on it
1 Answers
About this issue, you can try to 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 !
not working for me 🙁
At the moment, this code only allowed your user can add a media when ask a question. In the single question it not works. If you can not find the Add media button in the Ask question page, you can send me username & password of your site for further checking.
Please login or Register to submit your answer