Formule Excel
asked 9 years ago

Hello

How to insert an image or a file in a question or an answer?
I replaced ‘media_buttons’ => true, in actions.php but that only works for the admin.
Is it possible to allow any user to do it?
Thanks.

1 Answers
DominicStaff
answered 9 years ago

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 !

Powered by DW Question & Answer Pro