Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active March 11, 2024 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/888cad8ac672a419cb05da0efca5ccd8 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/888cad8ac672a419cb05da0efca5ccd8 to your computer and use it in GitHub Desktop.
[Defender Pro] Pwned Passwords integration with Peepso
<?php
/**
* Plugin Name: [Defender Pro] Pwned Passwords integration with Peepso (Rev. 1)
* Description: Solves a compatibility issue between Peepso Core plugin and the Defender's Pwned Passwords feature
* Author: Anderson Salas @ WPMUDEV
* Task: SLS-5836
* 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.
}
add_action('peepso_ajax_start', function( $page ) {
if ( 'auth.login' !== $page ) {
return; // Not the Auth login page.
}
$controller = wd_di()->get( \WP_Defender\Controller\Password_Protection::class );
$component = wd_di()->get( \WP_Defender\Component\Password_Protection::class );
remove_action( 'wp_authenticate_user', [ $controller, 'handle_login_password' ], 100 );
add_action( 'wp_authenticate_user', function( $user, $password ) use ( $component ) {
if (
! is_wp_error( $user ) &&
wp_check_password( $password, $user->user_pass, $user->ID ) &&
$component->is_weak_password( $user, $password )
) {
$error = new WP_Error();
$error->add(
'invalid_login',
__( 'You are required to change your password to a new one to use this site.', 'wpdef' )
);
return $error;
}
return $user;
}, 100, 2 );
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment