Skip to content

Commit

Permalink
= 4.2.6.6 =
Browse files Browse the repository at this point in the history
~ Fixed: security check option users_can_register
  • Loading branch information
tungnxt89 committed May 3, 2024
1 parent 38d5096 commit 3cfbd6e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
7 changes: 4 additions & 3 deletions inc/class-lp-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ public static function checkout_user_email_exists() {
$response = new LP_REST_Response();

try {
$email = LP_Request::get_email( 'email' );
$html_wrapper = [
$email = LP_Request::get_email( 'email' );
$user_can_register = get_option( 'users_can_register' );
$html_wrapper = [
'<label class="lp-guest-checkout-output">' => '</label>',
];

Expand All @@ -119,7 +120,7 @@ public static function checkout_user_email_exists() {
'Your email already exists. Do you want to continue with this email?',
'learnpress'
);
} else {
} elseif ( $user_can_register ) {
$output = sprintf(
'<input type="checkbox" name="checkout-email-option" value="new-account"> <span>%s</span>',
__(
Expand Down
21 changes: 12 additions & 9 deletions inc/class-lp-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class LP_Checkout {
use Singleton;

/**
* Payment method
*
Expand Down Expand Up @@ -228,20 +229,21 @@ public function checkout_email_exists() {
/**
* Create LP Order.
*
* @since 3.0.0
* @version 4.0.2
* @return mixed|string
* @throws Exception
* @since 3.0.0
* @version 4.0.3
*/
public function create_order() {
$cart = LearnPress::instance()->cart;
$cart_total = $cart->calculate_totals();
$order = new LP_Order();
$user_id = 0;
$cart = LearnPress::instance()->cart;
$cart_total = $cart->calculate_totals();
$order = new LP_Order();
$user_id = 0;
$user_can_register = get_option( 'users_can_register' );

if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
} else {
} elseif ( $user_can_register ) {
$checkout_option = LP_Request::get_param( 'checkout-email-option' );
// Set user id for Order if buy with Guest and email exists on the user
$user_id = $this->checkout_email_exists();
Expand Down Expand Up @@ -333,7 +335,7 @@ public function is_enable_guest_checkout() {
* @since 3.0.0
*/
public function is_enable_login() {
return apply_filters( 'learn-press/checkout/enable-login', in_array( LP_Settings::instance()->get( 'enable_login_checkout' ), array( '', 'yes' ) ) );
return apply_filters( 'learn-press/checkout/enable-login', 'yes' === LP_Settings::get_option( 'enable_login_checkout', 'yes' ) );
}

/**
Expand All @@ -343,7 +345,7 @@ public function is_enable_login() {
* @since 3.0.0
*/
public function is_enable_register() {
return apply_filters( 'learn-press/checkout/enable-register', in_array( LP_Settings::instance()->get( 'enable_registration_checkout' ), array( '', 'yes' ) ) && get_option( 'users_can_register' ) );
return apply_filters( 'learn-press/checkout/enable-register', 'yes' === LP_Settings::get_option( 'enable_registration_checkout', 'yes' ) );
}

/**
Expand Down Expand Up @@ -418,6 +420,7 @@ public function validate_checkout_fields() {
$error = apply_filters( 'learn-press/validate-checkout-fields', $this->errors, $fields, $this );
if ( is_wp_error( $error ) ) {
$this->errors[] = $error;

return false;
}

Expand Down
4 changes: 2 additions & 2 deletions inc/class-lp-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public function on_activate() {
}

// Force option users_can_register to ON.
if ( ! get_option( 'users_can_register' ) ) {
/*if ( ! get_option( 'users_can_register' ) ) {
update_option( 'users_can_register', 1 );
}
}*/
}

/**
Expand Down

0 comments on commit 3cfbd6e

Please sign in to comment.