Need to hook into plugin
-
I have a custom login form that seems to be pulling in some of this plugins functions as I can not successfully login while this plugin is active, I get a “username or password invalid”, once the plugin is off I can login just fine.
The costume login page does not show the google no captcha recaptcha like the core wp login page.
What do I need to do to hook in the captcha window.
-
Iv got most of the php writen but when and right now it is pulling in just an empty div
any idea why?
php code output
<div class=”g-recaptcha” data-sitekey=”MYKEY” data-theme=”light”></div>——————
<?php class Ncr_Custom_Login_Captcha extends Ncr_No_Captcha_Recaptcha { public static function initialize() { // initialize if login is activated if ( isset(self::$plugin_options['captcha_login']) && self::$plugin_options['captcha_login'] == 'yes') { // add captcha header script to WordPress header add_action( 'wp_head', array( __CLASS__, 'header_script' ) ); // adds the captcha to the custom login form add_action( 'custom_captcha_login', array( __CLASS__, 'display_captcha' ) ); // authenticate the captcha answer add_action( 'wp_authenticate_user', array( __CLASS__, 'validate_captcha_custom_login' ), 10, 2 ); } } /** * Verify the captcha answer * * @param $user string login username * @param $password string login password * * @return WP_Error|WP_user */ public static function validate_captcha_custom_login( $user, $password ) { if ( ! isset( $_POST['g-recaptcha-response'] ) || ! self::captcha_verification() ) { // Pop error message into $error_msg } return $user; } }——————-
require_once dirname(__FILE__). '/custom-login.php';
Ncr_Custom_Login_Captcha::initialize();
—————————–
On the form in question I have added a fire action
{do_action( 'custom_captcha_login' )}I think i just found the answer…
`/** reCAPTCHA header script */
public static function header_script() {$lang_option = self::$language;
// if language is empty (auto detected chosen) do nothing otherwise add the lang query to the
// reCAPTCHA script url
if ( isset( $lang_option ) && ( ! empty( $lang_option ) ) ) {
$lang = “?hl=$lang_option”;
} else {
$lang = null;
}echo ‘<script src=”https://www.google.com/recaptcha/api.js’ . $lang . ‘” async defer></script>’ . “\r\n”;
}/**
* Enqueue the Google ReCAPTCHA script using the WP system.
*
* @since 1.0.3
*/
public static function enqueue_header_script() {// if language is empty (auto detected chosen) do nothing otherwise add the lang query to the
// reCAPTCHA script url
if ( ! empty( self::$language ) ) {
$lang = “?hl={self::$language}”;
} else {
$lang = ”;
}$src = ‘https://www.google.com/recaptcha/api.js’ . $lang;
wp_enqueue_script( self::$script_handle, $src, false, false, true );
}`Its not getting called into the custom login page
Now it seems when validation fails I get a 500 server error
PHP Fatal error: Class name must be a valid object or a stringUpdate to custom-login.php
Good news, the login is working only problem is getting the error message to display. So far no error message is showing.
<?php class Ncr_Custom_Login_Captcha extends Ncr_No_Captcha_Recaptcha { public static function initialize() { // initialize if login is activated if ( isset(self::$plugin_options['captcha_login']) && self::$plugin_options['captcha_login'] == 'yes') { // add captcha header script to WordPress header add_action( 'wp_head', array( __CLASS__, 'header_script' ) ); // adds the captcha to the custom login form add_action( 'custom_captcha_login', array( __CLASS__, 'display_captcha' ) ); // authenticate the captcha answer add_action( 'wp_authenticate_user', array( __CLASS__, 'validate_captcha_custom_login' ), 10, 2 ); } } /** * Verify the captcha answer * * @param $user string login username * @param $password string login password * * @return WP_Error|WP_user */ public static function validate_captcha_custom_login( $user, $password ) { if ( ! isset( $_POST['g-recaptcha-response'] ) || ! self::captcha_verification() ) { // Pop error message into $error_msg echo $error_message; } return $user; } }Latest code iteration
<?php class Ncr_Custom_Login_Captcha extends Ncr_No_Captcha_Recaptcha { public static function initialize() { // initialize if login is activated if ( isset(self::$plugin_options['captcha_login']) && self::$plugin_options['captcha_login'] == 'yes') { // add captcha header script to WordPress header add_action( 'wp_head', array( __CLASS__, 'header_script' ) ); // adds the captcha to the custom login form add_action( 'custom_captcha_login', array( __CLASS__, 'display_captcha' ) ); // authenticate the captcha answer add_action( 'wp_authenticate_user', array( __CLASS__, 'validate_captcha_custom_login' ), 10, 2 ); } } /** * Verify the captcha answer * * @param $user string login username * @param $password string login password * * @return WP_Error|WP_user */ public static function validate_captcha_custom_login( $user, $password ) { if ( ! isset( $_POST['g-recaptcha-response'] ) || ! self::captcha_verification() ) { // Stop user and populate error message $error_message into $error_msg } // Do nothing and let user login } }
The topic ‘Need to hook into plugin’ is closed to new replies.