/** * Restrict access to the administration screens. * * Only administrators will be allowed to access the admin screens, * all other users will be shown a message instead. * * We do allow access for Ajax requests though, since these may be * initiated from the front end of the site by non-admin users. * * @link https://developer.wordpress.org/reference/hooks/admin_init/ */ function restrict_admin() { // Set user capability required to access dashboard. // List of standard capabilities here: https://wordpress.org/support/article/roles-and-capabilities/ $required_capability = 'manage_options'; if ( ! current_user_can( $required_capability ) && ( ! wp_doing_ajax() ) ) { wp_die( __( 'You are not allowed to access this part of the site' ) ); } } add_action( 'admin_init', 'restrict_admin', 1 );
Not sure what to do with this code?
You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.
Here are some free articles to get you started:
- Using Code Snippets from the Site
- The functions.php File
- Create a plugin file for custom functions
- Create a child theme
- Do not modify plugin files!
For "hands on" help, consider a plugin support subscription or the Pro Bundle.