Prohibit non administrators from accessing the background and restrict access to background login registration

After adding this code, the background login function of WordPress can be disabled, and non administrator users are prohibited from logging into the background of the website

If your website does not have front-end login and user center functions, please carefully add If an unexpected situation occurs, you can delete the relevant code on the server side.

In the subject's functions.php Filed Add the following code

 /** *Prohibit non administrators from accessing the background and restrict access to background login registration * @package bertly */ function redirect_non_admin_users() { if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_ SERVER['PHP_SELF'] ) { wp_redirect( home_url() ); exit; } } add_action( 'admin_init', 'redirect_non_admin_users' ); add_action('login_enqueue_scripts','login_protection'); function login_protection(){ header('Location: /'); } /** * End */

Code Preview:

Prohibit non administrators from accessing the background and restrict access to background login registration

Extraction code: None
Decompression code: None
course

Remove the category - wordpress tutorial from the category directory URL

2019-4-17 0:00:15

course

How to prevent the publication of articles with duplicate titles- Wordpress Tutorial

2019-4-20 0:06:07

⚠️
Some codes and tutorials on Npcink come from the Internet, and are only for netizens to learn and exchange. If you like this article, you can Attach original link Reprint at will.
No intention of infringing your rights, please send an email to 1355471563#qq.com Or click on the right Private message: Muze feedback, we will deal with it as soon as possible.
0 replies A Author M administrators
    There is no discussion yet. Tell me your opinion
Personal Center
Shopping Cart
Coupon
Sign in today
There are new private messages Private Message List
search