Last active
April 30, 2025 03:50
-
-
Save wpmudev-sls/c899e6d4824d50803c7dbd559159f75d to your computer and use it in GitHub Desktop.
[Defender Pro] reCaptcha compatibility with Indeed Ultimate Affiliate Pro plugin
This file contains hidden or 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 Indeed Ultimate Affiliate Pro plugin | |
* Description: Adds a custom reCaptcha integration to the Indeed Ultimate Affiliate Pro login shortcode | |
* Author: Anderson Salas @ WPMUDEV | |
* Task: SLS-7010 | |
* 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( 'UAP_PLUGIN_VER' ) ) { | |
return; // Indeed Ultimate Affiliate Pro plugin 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 ); | |
}; | |
add_filter( 'do_shortcode_tag', function( $output, $tag, $attr, $m ) use( $recaptcha, $configure ) { | |
if ( 'uap-login-form' !== $tag || isset( $GLOBALS['_wds_uap_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_uap_recaptcha'] = true; | |
return $output; | |
}, 10, 4 ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment