2015-12-22 5 views
2

Привет, сообщество stackoverflow, Мне нужна помощь в решении моей проблемы с аутентификацией входа в WordPress. Таким образом, я установил CAPATCHA по Best ... И чтобы поместить capatcha в пользовательский wp_login_form, мне нужно добавить подтверждение. Поэтому я создал это:Проблемы с аутентификацией wp_login_form

add_filter('wp_authenticate_user', 'my_custom_authenticate', 10, 3); 
function my_custom_authenticate($user, $username, $password){ 
    //Get POSTED value 
    if ((function_exists('cptch_check_custom_form') && cptch_check_custom_form() !== true) || (function_exists('cptchpr_check_custom_form') && cptchpr_check_custom_form() !== true)) { 
     remove_action('authenticate', 'wp_authenticate_username_password', 20); 
     $user = new WP_Error('denied', __("<strong>ERROR</strong>: You're CAPTCHA field was wrong.")); 
    } 
    return $user; 
} 

Но он всегда возвращается как ошибка. Я добавил capatcha поле с этим:

add_filter('login_form_middle','cptch_custom_form'); 

У вас когда-либо была эта проблема, как я могу ее решить?

+0

Я не уверен, как решить вашу проблему, но я могу порекомендовать этот плагин. Настройка была простой для стандартной страницы входа, возможно, стоит посмотреть - https://wordpress.org/plugins/wp-recaptcha/ – tonyedwardspz

+0

Может ли cptch_check_custom_form быть cptch_custom_form в вашем if-statement? – danjah

+0

@ danjah по-прежнему ничего ...:/ – Sidas

ответ

1

Приступить к подходу «попробуйте и не подходите».

Используйте var_dump(), чтобы проверить значения каждого отдельного условия в своем заявлении if.

Что-то вроде этого:

add_filter('wp_authenticate_user', 'my_custom_authenticate', 10, 3); 
function my_custom_authenticate($user, $username, $password){ 

    /** THIS IS THE DEBUGGING PART */ 
    var_dump(function_exists('cptch_check_custom_form')); 
    var_dump(cptch_check_custom_form())); 
    var_dump(function_exists('cptchpr_check_custom_form')); 
    var_dump(cptchpr_check_custom_form() !== true); 
    /** END DEBUGGING PART */ 

    //Get POSTED value 
    if (
     (function_exists('cptch_check_custom_form') && true !== cptch_check_custom_form()) 
     || (function_exists('cptchpr_check_custom_form') && true !== cptchpr_check_custom_form())) 
    { 
     remove_action('authenticate', 'wp_authenticate_username_password', 20); 
     $user = new WP_Error('denied', __("<strong>ERROR</strong>: You're CAPTCHA field was wrong.")); 
    } 
    return $user; 
} 

ПРИМЕЧАНИЕ: Я изменил условия с помощью Yoda's notation, что является более безопасным для использования.

Смежные вопросы