The following action hook should help:
add_action('admin_init', 'wpse28702_restrictAdminAccess', 1);
function wpse28702_restrictAdminAccess() {
$isAjax = (defined('DOING_AJAX') && true === DOING_AJAX) ? true : false;
if(!$isAjax) {
if(!current_user_can('administrator')) {
wp_die(__('You are not allowed to access this part of the site'));
}
}
}
Related Posts:
- 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?
- wp-admin – save options without refreshing?
- How to create a wp admin page (for use in an ajax request)
- Redirect users away from Admin breaks ajax
- Ajax solution similar to WP Categories functioning in Admin area
- Ajax requests from front-end with jQuery Fancybox
- Dismiss Admin Pointer Temporarily
- Can admin-ajax.php be used for spam purposes? And if yes, how to prevent that?
- Organizing Code in your WordPress Theme's functions.php File?
- How to check if a user is in a specific role?
- Can’t change language (only “English (United States)”)
- Create WP tutorial for users with admin pointer using next button for navigation
- Taxonomy dropdown metabox in the back-end
- How to redirect/rewrite all /wp-login requests
- Disable image attachment links
- Remove “Time to upgrade” message from dashboard
- How can I enable Google Analytics on a file download link?
- What is the best method to close off the backend?
- 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
- Change the link of ‘Howdy’ at the top right
- AJAX handler throws 400 (Bad request) – why?
- wp-admin remove the subfolder URL
- Reorder custom submenu item
- Options for restricting access to wp-admin
- Looking for a hook to add attachment information to the media library tab
- Removing admin bar from wordpress dashboard
- Load Balanced WP with single server admin access
- How to control contextual help section by code?
- Can’t access wp-admin Internal Server Error 500
- File exceeds upload_max_filesize, despite max filesize being large enough
- How can I rename the WordPress AJAX URL? [duplicate]
- WordPress admin not changing language
- 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
- Just how ‘expensive’ is this function?
- Custom Background-Image not showing up
- js Conflict in admin panel – I guess it’s from the core WP installation
- Admin wp_ajax hook returning 0
- Why is there an intermediate redirect to https://public-url.org/wp-admin?
- Remove query var on admin pages when ‘Save changes’ pressed
- How to hide wordpress default description box?
- Create a fullwidth dashboard widget
- Website looks fine, but login to wp-admin yields a blank screen
- cannot find the login page for local WordPress site
- In editor-style.css how can I change background color of title field?
- /wp-admin/ 500 error
- How do I change the upload file size limit in single-site wordpress install?
- Can’t call external stylesheet for WordPress admin (using wp_admin_css)?
- wrapping ‘rest_api_init’ in ‘is_admin()’ function
- display dynamic WP Site logo on wp-admin using CSS
- Restore a layout [closed]
- Logging into sandbox subdomain WP
- White screen of death on admin and other dashboard pages
- TinyMCE strips breaks inside editor
- can not access wp-admin after migrating to openshift
- wp-admin url doesn’t allow to login and redirects to same page
- wp-admin dashboard redirects to homepage
- /wp-admin/ doesn’t work but /admin/ does
- WordPress Side Menu Admin Panel Default Order numbers List?
- Why can I log into wp-login.php and not wp-admin.php?
- Change admin defaults for reading settings
- How to Custom Edit Post Title & Permalink Slug?
- How to break line / add to ADMIN menu
- Adding Notification Bubble on Admin Top Bar
- WordPress admin page not found error
- Use of domain name
- Where is function to prevents non logged users access wp-admin?
- Registering for a domain on WordPress
- WordPress site stopped working after simply opening header.php in the wp-admin editor
- CSS of the admin panel
- User Profile Avatars
- Change Post Meta via AJAX from the posts list table
- Why wp redirects me to wp-login.php when I visit a rewritten wp-admin URL?
- wp-admin blocking causing http error on uploads
- Performance-issue in WP-admin with a lot of posts
- 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
- Custom admin menu order fails if slugs are complicated
- Cant access wp-admin
- Function to get a ‘post selector’ UI?
- 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
- CSRF attack to create USER
- Changing headers for an export from within a PHP class extension
- When installing wordpress through WP CLI mysite.com/admin not working
- 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
- Undeletable posts, users or other content
- Making changes to woocommerce order before save
- Action for opening edit page in admin?
- Couple questions about .htaccess, login page, updates
- Cannot Access wp-admin