You just need one extra thing for this.
Here is the code I typically use to do what you are doing:
function pws_block_admin() {
if (
// Look for the presence of /wp-admin/ in the url
stripos($_SERVER['REQUEST_URI'],'/wp-admin/') !== false
&&
// Allow calls to async-upload.php
stripos($_SERVER['REQUEST_URI'],'async-upload.php') === false
&&
// Allow calls to admin-ajax.php
stripos($_SERVER['REQUEST_URI'],'admin-ajax.php') === false
) {
if ( !current_user_can('manage_options') ) {
$redirect_to = home_url();
wp_redirect($redirect_to, 302);
}
}
}
add_action('admin_init', 'pws_block_admin', 0);
It looks like you are just missing the exclusion for allowing async-upload.php to work.
Related Posts:
- custom tabs in media uploader
- Client system for media review?
- Run filter if only it was run from specific admin page ( ‘upload_dir’ changed )
- send information from the thickbox image uploader second tab
- How to remove list view from media library?
- Uploading files in admin panel?
- Thickbox hacking – removing fields
- Possible to create placeholder images in WordPress editor that are clickable (should bring up uploader)?
- Making Media Library “Alternative Text” Field Required
- Customize the upload screen
- Uploading Images to Multi-Site Causes Failure to HTTP Error
- wordpress upload http error?
- Refreshing collections in the admin media manager
- Editing the Backend Uploader
- Convert (-) and (escape) signs to (_) when uploading files on wordpress media library automatically
- Unable to upload image using the standard uploader in the WP admin (v4.3)
- WordPress post feature image not uploading
- Where to set individual blog quotas?
- WordPress Media Uploader custom Javascript not working
- Custom Jquery in admin breaks media-upload script
- Problem with implenting Uploadify with WordPress
- Upload error on localhost (at minimum, not yet tested online)
- Admin hook after editing an image?
- add instructions to upload pages and / or forms
- Why doesn’t the Media Browser use thumbnail sized images?
- Making a custom upload form and page in the admin section
- how to automatically cleanup failed WordPress uploads in /tmp?
- Where in WP can I check history or log of updates of plugins etc?
- How does admin-ajax.php work?
- Saving Media – Which Hook is Fired?
- Can an admin check passwords of registered users?
- Prevent author from changing their posts if admin has modified
- Set a maximum upload count for users on a specific user role
- Set Featured Image programmatically (in admin) with JavaScript?
- Can I set a default dashboard layout for all users?
- Organize uploaded media files
- Append button to WordPress Image Details modal
- How to remove “Super Admin” from All Users for those that are not a “Super Admin”?
- How to print the output of the get_num_queries function from frontend to backend?
- Retrieving JSON data in ajax request from media uploader
- Javascript not working in admin
- Downloading entire site locally with httrack
- add_submenu_page set for multiple roles [duplicate]
- Adminstering Large Number of WordPress Sites
- How To Create User Specific Admin User Pages?
- Adding markup to column text in “Edit Pages” admin page
- How to host different file formats/types for a media attachment without creating multiple attachments?
- How to re-arrange media uploaded using : media_handle_upload() as per year / month
- Disable HTML (Text) Tab in Post Editor
- Hide Updates from Admins that don’t equal a set Username
- wp_schedule_event only when admin is visited
- Why would media_sideload_image() not work locally?
- Hide Pages on Edit Pages based on Capability (edit_others_pages)?
- Hide one admin from another admin
- Media upload on WordPress changes title of image
- Uppload image from another source wp.media
- move_uploaded_file() not working on wordpress front end
- How to add custom classes to admin list table default rows or columns?
- How to hide a specific part of dashboard for non-admin roles?
- Prevent small image sizes from being uploaded
- Get a listing of portfolio items and categories
- Protecting uploads not working
- What is the alternative to “ when it comes to calling Media (image) files in the ‘attachment.php’ file?
- WordPress Remove Submenus
- Continuous Login Sessions For Super Admins Across Multi-Site Network of Sites
- using rewrites to secure login page
- WordPress automatically adds links to uploaded images
- Redirect from the dashboard to edit.php if wp_is_mobile() is true
- Customizing WordPress Admin – How to Change the Avatar size
- Create a WordPress administrator without access to back-end
- WordPress 3.1’s admin bar disappears only leaving its 28 px padding (in ubuntu)!
- Error: The uploaded file exceeds the upload_max_filesize directive in php.ini [duplicate]
- How To Make Iris Color Picker Showed Up Over Form and Text?
- my checkbox is not saving it’s value
- Can’t login to my admin area
- How much traffic is real traffic?
- How to change the descriptive text on the menus admin page?
- Convert all uploaded PNG files to PNG-8 format
- Call require_once form admin page with checkbox
- unable to write to the database while uploading images
- Can’t upload format files on media library
- WordPress media has all disappeared on wp-admin but still on the server
- How To Remove Import/Export Option From Tools?
- unsharp thumbnails after uploading image
- Error “Sorry, you are not allowed to access this page”
- Create WordPress Menu Item Without Linking to a Custom Page
- Search Only Works when Logged into Admin
- Different role for free and pro users in wordpress without using bbpress
- Force relative path in media library for LAN deployment
- WordPress login not working
- Enqueue script throws error in console
- Set featured link not showing
- Broken Media Library
- Calculate and save an average in a meta
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- Use the wordpress admin table
- 2FA for admin login only, is it doable?
- Add a user to edit the layout of a site
- Uploading media to wordpress API with C# HttpClient
- Image in binary in the data to WordPress media library