0

I'm using wp-editor to let users write text & upload media.

I added a script that prevents users from going to the back-end if they're not logged as admin.

This is the script :

function yproject_admin_init() {
   if (! current_user_can( 'activate_plugins' )) {
     wp_redirect(site_url());
     exit();
   }
}
add_action( 'admin_init', 'yproject_admin_init' );

The problem is: with non-admin users, when they try to upload files, the file seems to upload but at the end, the get the message : "An error occurred in the upload. Please try again later."

If I delete the "redirect" and "exit" lines, it works fine (but obviously, the user access the admin side).

Which test could I add to prevent this?

0 Answers0