如何在登录wordpress之前检查前提条件

时间:2016-02-24 04:52:02

标签: wordpress wordpress-plugin wordpress-theming

问候

我想在登录前检查用户状态。例如,如果用户角色是测试人员,请不要登录。否则登录。

由于

2 个答案:

答案 0 :(得分:0)

add_action( 'get_header', 'no_testers' );
function no_testers() {
    if ( current_user_can( 'tester_only_capability' ))
        $logout_url = wp_login_url().'?mode=maintainance';
        wp_logout();
        wp_redirect( $logout_url, 302 );
}

tester_only_capability替换为只有测试人员才能做的事情。

答案 1 :(得分:0)

在涉及WordPress之前,您可以使用wp_authenticate来使用自定义登录机制。

<?php
  add_action( 'wp_authenticate' , 'check_custom_authentication' );
  function check_custom_authentication ( $username ) {
    // Get user role by username & put your logic
  }
?>
相关问题