Title: Need to hook into plugin
Last modified: August 30, 2016

---

# Need to hook into plugin

 *  [webmasteral](https://wordpress.org/support/users/webmasteral/)
 * (@webmasteral)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/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.
 * [https://wordpress.org/plugins/no-captcha-recaptcha/](https://wordpress.org/plugins/no-captcha-recaptcha/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Thread Starter [webmasteral](https://wordpress.org/support/users/webmasteral/)
 * (@webmasteral)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/need-to-hook-into-plugin/#post-6585826)
 * 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](https://wordpress.org/support/users/webmasteral/)
 * (@webmasteral)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/need-to-hook-into-plugin/#post-6585828)
 * 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](https://www.google.com/recaptcha/api.js&#8217);.
   $lang . ‘” async defer></script>’ . “\r\n”;
    }
 *  /**
    * Enqueue the Google ReCAPTCHA script using the WP system. * * [@since](https://wordpress.org/support/users/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](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](https://wordpress.org/support/users/webmasteral/)
 * (@webmasteral)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/need-to-hook-into-plugin/#post-6585843)
 * 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](https://wordpress.org/support/users/webmasteral/)
 * (@webmasteral)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/need-to-hook-into-plugin/#post-6585853)
 * 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](https://wordpress.org/support/users/webmasteral/)
 * (@webmasteral)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/need-to-hook-into-plugin/#post-6585883)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/no-captcha-recaptcha_afc5ce.svg)
 * [No CAPTCHA reCAPTCHA](https://wordpress.org/plugins/no-captcha-recaptcha/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/no-captcha-recaptcha/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/no-captcha-recaptcha/)
 * [Active Topics](https://wordpress.org/support/plugin/no-captcha-recaptcha/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/no-captcha-recaptcha/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/no-captcha-recaptcha/reviews/)

## Tags

 * [add](https://wordpress.org/support/topic-tag/add/)
 * [custom](https://wordpress.org/support/topic-tag/custom/)

 * 5 replies
 * 1 participant
 * Last reply from: [webmasteral](https://wordpress.org/support/users/webmasteral/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/need-to-hook-into-plugin/#post-6585883)
 * Status: not resolved