Skip to content

Commit

Permalink
Add Profile Builder Login form.
Browse files Browse the repository at this point in the history
  • Loading branch information
kagg-design committed Jul 31, 2023
1 parent 62d52e3 commit 8aa0794
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
Binary file added assets/images/profile-builder-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/php/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,9 @@ public function print_inline_styles() {
.elementor-field-type-hcaptcha .h-captcha {
margin-bottom: unset;
}
#wppb-loginform .h-captcha {
margin-bottom: 14px;
}
div[style*="z-index: 2147483647"] div[style*="border-width: 11px"][style*="position: absolute"][style*="pointer-events: none"] {
border-style: none;
}
Expand Down Expand Up @@ -873,6 +876,11 @@ public function load_modules() {
'paid-memberships-pro/paid-memberships-pro.php',
PaidMembershipsPro\Login::class,
],
'Profile Builder Login' => [
[ 'profile_builder_status', 'login' ],
'profile-builder/index.php',
ProfileBuilder\Login::class,
],
'Quform' => [
[ 'quform_status', 'form' ],
'quform/quform.php',
Expand Down
109 changes: 109 additions & 0 deletions src/php/ProfileBuilder/Login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/**
* Login class file.
*
* @package hcaptcha-wp
*/

namespace HCaptcha\ProfileBuilder;

use HCaptcha\Abstracts\LoginBase;
use HCaptcha\Helpers\HCaptcha;
use WP_Error;
use WP_User;

/**
* Class Login.
*/
class Login extends LoginBase {

/**
* Nonce action.
*/
const ACTION = 'hcaptcha_login';

/**
* Nonce name.
*/
const NONCE = 'hcaptcha_login_nonce';

/**
* Init hooks.
*/
protected function init_hooks() {
parent::init_hooks();

add_filter( 'wppb_login_form_before_content_output', [ $this, 'add_captcha' ], 10, 2 );
add_filter( 'wp_authenticate_user', [ $this, 'verify' ], 10, 2 );
}

/**
* Add captcha.
*
* @param string|mixed $login_form Login form html.
* @param array $form_args Form arguments.
*
* @return string|mixed
* @noinspection PhpUnusedParameterInspection
*/
public function add_captcha( $login_form, array $form_args ) {
if ( ! $this->is_login_limit_exceeded() ) {
return $login_form;
}

$login_form = (string) $login_form;

$args = [
'action' => self::ACTION,
'name' => self::NONCE,
'id' => [
'source' => HCaptcha::get_class_source( __CLASS__ ),
'form_id' => 'login',
],
];

$search = '<p class="login-submit">';

return str_replace( $search, HCaptcha::form( $args ) . $search, $login_form );
}

/**
* Verify login form.
*
* @param WP_User|WP_Error $user WP_User or WP_Error object if a previous
* callback failed authentication.
* @param string $password Password to check against the user.
*
* @return WP_User|WP_Error
* @noinspection PhpUnusedParameterInspection
*/
public function verify( $user, string $password ) {
// phpcs:disable WordPress.Security.NonceVerification.Missing
$wppb_login_form_used = isset( $_POST['wppb_login'] ) ?
sanitize_text_field( wp_unslash( $_POST['wppb_login'] ) ) :
'';
// phpcs:enable WordPress.Security.NonceVerification.Missing

if ( ! $wppb_login_form_used ) {
return $user;
}

if ( ! $this->is_login_limit_exceeded() ) {
return $user;
}

$error_message = hcaptcha_verify_post(
self::NONCE,
self::ACTION
);

if ( null === $error_message ) {
return $user;
}

$code = array_search( $error_message, hcap_get_error_messages(), true );
$code = $code ?: 'fail';

return new WP_Error( $code, $error_message, 400 );
}
}
7 changes: 7 additions & 0 deletions src/php/Settings/Integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ public function init_form_fields() {
'login' => __( 'Login Form', 'hcaptcha-for-forms-and-more' ),
],
],
'profile_builder_status' => [
'label' => 'Profile Builder',
'type' => 'checkbox',
'options' => [
'login' => __( 'Login Form', 'hcaptcha-for-forms-and-more' ),
],
],
'quform_status' => [
'label' => 'Quform',
'type' => 'checkbox',
Expand Down

0 comments on commit 8aa0794

Please sign in to comment.