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 . In case of an unexpected situation, 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

Appreciate TA
A total of {{data. count}} people
People have appreciated
⚠️
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.
Shopping Cart
Coupon
search