Last active
July 13, 2024 03:38
-
-
Save wpmudev-sls/de49a50b18601f9ce5de265bd0ccfa01 to your computer and use it in GitHub Desktop.
[Defender Pro] reCaptcha compatibility with Avada login form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [Defender Pro] reCaptcha compatibility with Avada login form | |
* Description: Adds a custom reCaptcha integration to the Avada login form | |
* Author: Anderson Salas @ WPMUDEV | |
* Task: SLS-6260 | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
add_action( 'plugins_loaded', function() { | |
if ( ! defined( 'DEFENDER_VERSION' ) ) { | |
return; // Defender is not installed/enabled. | |
} | |
if ( ! defined( 'FUSION_BUILDER_VERSION' ) ) { | |
return; // Avada is not installed/enabled. | |
} | |
$recaptcha = wd_di()->get( \WP_Defender\Controller\Recaptcha::class ); | |
$recaptcha_model = wd_di()->get( \WP_Defender\Model\Setting\Recaptcha::class ); | |
if ( ! $recaptcha_model->is_active() ) { | |
return; // reCaptcha module is not active. | |
} | |
$configure = function( $recaptcha ) { | |
$method = new ReflectionMethod( $recaptcha, 'declare_variables' ); | |
$method->setAccessible( true ); | |
$method->invoke( $recaptcha ); | |
}; | |
// NOTE: Implementation of fusion_user_login_notices_array filter (for the Defender's reCaptcha error) | |
// is not supported. | |
add_filter( 'fusion_element_user_login_content', function( $output, $args ) use( $recaptcha, $configure ) { | |
if ( isset( $GLOBALS['_wds_avada_recaptcha'] ) ) { | |
return $output; | |
} | |
$configure( $recaptcha ); | |
add_action( 'wp_enqueue_scripts', function() use ( $recaptcha ) { | |
$recaptcha->add_scripts(); | |
}); | |
$method = new ReflectionMethod( $recaptcha, 'display_recaptcha' ); | |
$method->setAccessible( true ); | |
ob_start(); | |
echo $method->invoke( $recaptcha ); | |
$markup = ob_get_clean(); | |
if ( ! empty( $markup ) ) { | |
$output = str_ireplace( '</form>', $markup . '</form>', $output ); | |
} | |
$GLOBALS['_wds_avada_recaptcha'] = true; | |
return $output; | |
}, 10, 2 ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment