• 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.

    https://www.ads-software.com/plugins/no-captcha-recaptcha/

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter webmasteral

    (@webmasteral)

    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' )}

    Thread Starter webmasteral

    (@webmasteral)

    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&#8217; . $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&#8217; . $lang;

    wp_enqueue_script( self::$script_handle, $src, false, false, true );
    }`

    Its not getting called into the custom login page

    Thread Starter webmasteral

    (@webmasteral)

    Now it seems when validation fails I get a 500 server error
    PHP Fatal error: Class name must be a valid object or a string

    Thread Starter webmasteral

    (@webmasteral)

    Update 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;
    	}
    }
    Thread Starter webmasteral

    (@webmasteral)

    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
    	}
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Need to hook into plugin’ is closed to new replies.