You can and a check for the DOING_AJAX
constant which is defined on an Ajax in your conditional check:
function no_admin_access()
{
if (
// Don't do this for AJAX calls
! defined( 'DOING_AJAX' )
// Capability check
&& ! current_user_can( 'delete_posts' )
)
{
// Redirect to home/front page
wp_redirect( site_url( "https://wordpress.stackexchange.com/" ) );
// Never ever(!) forget to exit(); or die(); after a redirect
exit;
}
}
add_action( 'admin_init', 'no_admin_access' );
Related Posts:
- Admin Page Redirect
- Admin ajax request return 0 with die()
- Custom column for changing post status via ajax
- How to make ajax call in wordpress in right way?
- stop redirection on /wp-admin call to /wp-login
- wp-admin – save options without refreshing?
- Login to wp-admin “redirect_to” points to wrong URL after migration
- How to create a wp admin page (for use in an ajax request)
- redirect to a dedicated sign in page
- Ajax solution similar to WP Categories functioning in Admin area
- How can I prevent redirects from mysite/page to mysite/wp path/page?
- blocking the admin section (but still using admin-ajax.php)
- Unable to properly login
- Ajax requests from front-end with jQuery Fancybox
- Dismiss Admin Pointer Temporarily
- Redirect WordPress login for customers but not admin
- WP site after login keeps redirecting to looped url [closed]
- Can admin-ajax.php be used for spam purposes? And if yes, how to prevent that?
- Redirecting the user to the admin table area after publishing a post, getting an invalid response error?
- Organizing Code in your WordPress Theme's functions.php File?
- Add “external” link to admin menu in the backend
- Disable image attachment links
- Remove “Time to upgrade” message from dashboard
- Pre-fill fields with content from outside when creating a new post
- Why are admin scripts not printed
- White screen of death only in wp-admin
- AJAX handler throws 400 (Bad request) – why?
- Admin Media grid view images won’t load
- Looking for a hook to add attachment information to the media library tab
- Removing admin bar from wordpress dashboard
- WP-admin giving 404
- How to control contextual help section by code?
- Can’t access wp-admin Internal Server Error 500
- How can I rename the WordPress AJAX URL? [duplicate]
- Add custom text to Page Tamplate without need to know html
- Move WP Admin Bar
- Get Stylesheet To Showup in WP Admin Panel Editor
- Deprecated : contextual_help has been deprecated since version 3.3.0
- Display $pagenow error notice on all admin pages
- How can I restrict a user to a specific item in the WordPress Admin? [closed]
- How to show postmeta in custom columns for the posts screen?
- disable a wp javascript on live website, but not on wp-admin page
- wp_nonce_url to users.php for deleting user not working
- How to stop – Database Update Required – from happening again?
- Moving wp-admin to a different to a subdomain
- Can’t login to Dashboard when changing site URL to HTTPS
- Limit access to wp_admin
- Not Found (404) error on admin page, CSS gone on blog
- MySQL CPU Usage Surge up When Multiple Post Editor Pages are open
- How to add a custom-post-type post within another custom-post-type post edit screen using AJAX?
- Pass additional parameter with async upload
- how to customize wp-admin page using child theme
- new subdomain to apply as main domain
- WordPress server change – slow admin login time for first time
- I can´t access my admin panel. I tried all possible solutions
- Blank page for wp-admin after i uploaded the website from my localhost to the live server
- Difference between admin and user admin
- How to get specific page screen ID
- Hooks: admin_footer and admin_print_footer_scripts not working?
- Editing edit-tags.php page in wp-admin
- What is the correct way to get only display plugin for Administrator Only
- displaying an error before update_post_meta
- firing function at login within class
- How to break line / add to ADMIN menu
- WordPress admin page not found error
- Use of domain name
- “Add New” button on custom post type grid
- Where is function to prevents non logged users access wp-admin?
- Registering for a domain on WordPress
- CSS of the admin panel
- WordPress admin right sidebar isn’t working
- WordPress menu to change page title
- wp-admin blocking causing http error on uploads
- DISALLOW_FILE_EDIT is false but I still am not able to edit files from the admin interface and the menus do not show up
- Updated MAMP and localhost on MacOS site no longer accessible
- What hooks should you use to create a table only once?
- Custom admin menu order fails if slugs are complicated
- Cant access wp-admin
- Function to get a ‘post selector’ UI?
- WordPress wp-admin Page
- How can I trigger a javascript function after a post update on edit post screen in wordpress admin panel?
- restrict admin panel sections to users
- how to set not to be logined in wp-admin except administrator?
- CSRF attack to create USER
- WordPress, content editor default type
- Changing headers for an export from within a PHP class extension
- Remove capability to interact with a page
- WordPress Login for multiple sites
- How do I change the WordPress Address URL only and still login to wp-admin
- wordpress wp-admin showing white screen with no error
- Blank sign in page
- Action for opening edit page in admin?
- Couple questions about .htaccess, login page, updates
- My website does not load since two days!
- After Upgrade: $user becomes unknown (id: 0) after successful login?
- Redirect users based on their roles, is_admin()
- insert an admin table inside another admin page
- /wp-admin/ – this link showing me “Index of /wp-admin”/ instead of dashboard
- What methods are you using to transfer individual WP site components from one site to another?
- how to Hide all products except the General Manager role in the WordPress admin panel?