Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 49 additions & 28 deletions includes/free/class-login.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function is_override_enabled() {
public function add_custom_fields() {
$recaptcha = wpuf_get_option( 'login_form_recaptcha', 'wpuf_profile', 'off' );

if ( $recaptcha == 'on' ) {
if ( $recaptcha === 'on' ) {
echo wp_kses(
recaptcha_get_html( wpuf_get_option( 'recaptcha_public', 'wpuf_general' ), true, null, is_ssl() ), [
'div' => [
Expand Down Expand Up @@ -117,18 +117,15 @@ public function add_custom_fields() {
* @since 2.9.0
*/
public function login_form_scripts() {
if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( 'wp_login_nonce' ) ) {
}

$post_data = wp_unslash( $_POST );
$post_data = wp_unslash( $_REQUEST );

if ( isset( $post_data['wpuf_login'] ) ) {
return;
}

$recaptcha = wpuf_get_option( 'login_form_recaptcha', 'wpuf_profile', 'off' );

if ( $recaptcha == 'on' ) { ?>
if ( $recaptcha === 'on' ) { ?>
<style type="text/css">
body #login {
width: 350px;
Expand All @@ -148,18 +145,15 @@ public function login_form_scripts() {
* @since 2.9.0
*/
public function validate_custom_fields( $user, $password ) {
if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( 'wp_login_nonce' ) ) {
}

if ( isset( $_POST['wpuf_login'] ) ) {
if ( isset( $_REQUEST['wpuf_login'] ) ) {
return $user;
}

$recaptcha = wpuf_get_option( 'login_form_recaptcha', 'wpuf_profile', 'off' );

if ( $recaptcha == 'on' ) {
if ( isset( $_POST['g-recaptcha-response'] ) ) {
if ( empty( $_POST['g-recaptcha-response'] ) ) {
if ( $recaptcha === 'on' ) {
if ( isset( $_REQUEST['g-recaptcha-response'] ) ) {
if ( empty( $_REQUEST['g-recaptcha-response'] ) ) {
$user = new WP_Error( 'WPUFLoginCaptchaError', 'Empty reCaptcha Field.' );
} else {
$no_captcha = 1;
Expand Down Expand Up @@ -239,7 +233,7 @@ public function get_registration_url( $register_url = null ) {
$page_id = wpuf_get_option( 'reg_override_page', 'wpuf_profile', false );
$wp_reg_url = site_url( 'wp-login.php?action=register', 'login' );

if ( $register_link_override == 'off' || ! $page_id ) {
if ( $register_link_override === 'off' || ! $page_id ) {
return $wp_reg_url;
}

Expand Down Expand Up @@ -376,7 +370,8 @@ public function login_form() {

case 'rp':
case 'resetpass':
if ( $reset == 'true' ) {
if ( $reset === 'true' ) {
/* translators: %s: login url */
printf( '<div class="wpuf-message">' . esc_html( __( 'Your password has been reset. %s', 'wp-user-frontend' ) ) . '</div>', sprintf( '<a href="%s">%s</a>', esc_attr( $this->get_action_url( 'login' ) ), esc_html( __( 'Log In', 'wp-user-frontend' ) ) ) );

return;
Expand All @@ -391,7 +386,7 @@ public function login_form() {
default:
$loggedout = isset( $getdata['loggedout'] ) ? sanitize_text_field( $getdata['loggedout'] ) : '';

if ( $loggedout == 'true' ) {
if ( $loggedout === 'true' ) {
$this->messages[] = __( 'You are now logged out.', 'wp-user-frontend' );
}

Expand Down Expand Up @@ -512,8 +507,7 @@ public function login_redirect() {
return;
}

$redirect_to = isset( $_REQUEST['redirect_to'] ) ? wp_unslash( $_REQUEST['redirect_to'] ) : '';

$redirect_to = isset( $_REQUEST['redirect_to'] ) ? esc_url_raw( wp_unslash( $_REQUEST['redirect_to'] ) ) : '';
return $this->get_login_redirect_link( $redirect_to );
}

Expand Down Expand Up @@ -572,7 +566,7 @@ public function default_login_redirect( $redirect ) {

$link = get_permalink( $redirect_to );

if ( $override != 'on' || 'previous_page' == $redirect_to || empty( $link ) ) {
if ( $override !== 'on' || 'previous_page' === $redirect_to || empty( $link ) ) {
return $redirect;
}

Expand All @@ -587,7 +581,7 @@ public function default_login_redirect( $redirect ) {
public function process_logout() {
$action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';

if ( $action == 'logout' ) {
if ( $action === 'logout' ) {
if ( ! $this->is_override_enabled() ) {
return;
}
Expand Down Expand Up @@ -778,6 +772,7 @@ public function successfully_authenticate( $user, $username, $password ) {
$wpuf_user = new WPUF_User( $user->ID );

if ( ! $wpuf_user->is_verified() ) {
/* translators: %s: activation link */
$error->add( 'acitve_user', sprintf( __( '<strong>Your account is not active.</strong><br>Please check your email for activation link. <br><a href="%s">Click here</a> to resend the activation link', 'wp-user-frontend' ), $resend_link ) );

return $error;
Expand Down Expand Up @@ -823,7 +818,7 @@ public function activation_user_registration() {

$activation_key = isset( $_GET['wpuf_registration_activation'] ) ? sanitize_text_field( wp_unslash( $_GET['wpuf_registration_activation'] ) ) : '';

if ( $user->get_activation_key() != $activation_key ) {
if ( $user->get_activation_key() !== $activation_key ) {
wpuf()->login->add_error( __( 'Activation URL is not valid', 'wp-user-frontend' ) );

return;
Expand All @@ -834,7 +829,7 @@ public function activation_user_registration() {

$message = __( 'Your account has been activated', 'wp-user-frontend' );

if ( $wpuf_user_status != 'approved' ) {
if ( $wpuf_user_status !== 'approved' ) {
$message = __( "Your account has been verified , but you can't login until manually approved your account by an administrator.", 'wp-user-frontend' );
}

Expand All @@ -857,9 +852,9 @@ public function activation_user_registration() {
if ( is_wp_error( $key ) ) {
return;
}

/* translators: %s: blogname */
$subject = sprintf( __( '[%s] Your username and password info', 'wp-user-frontend' ), $blogname );

/* translators: %s: username */
$message = sprintf( __( 'Username: %s', 'wp-user-frontend' ), $the_user->user_login ) . "\r\n\r\n";
$message .= __( 'To set your password, visit the following address:', 'wp-user-frontend' ) . "\r\n\r\n";
$message .= network_site_url( "wp-login.php?action=rp&key=$key&login=" . rawurlencode( $the_user->user_login ), 'login' ) . "\r\n\r\n";
Expand All @@ -871,8 +866,9 @@ public function activation_user_registration() {

wp_mail( $user_email, $subject, $message );
} else {
/* translators: %s: blogname */
$subject = sprintf( __( '[%s] Account has been activated', 'wp-user-frontend' ), $blogname );

/* translators: %s: username */
$message = sprintf( __( 'Hi %s,', 'wp-user-frontend' ), $the_user->user_login ) . "\r\n\r\n";
$message .= __( 'Congrats! Your account has been activated. To login visit the following url:', 'wp-user-frontend' ) . "\r\n\r\n";
$message .= wp_login_url() . "\r\n\r\n";
Expand All @@ -884,6 +880,29 @@ public function activation_user_registration() {

wp_mail( $user_email, $subject, $message );
}

$autologin_after_registration = wpuf_get_option( 'autologin_after_registration', 'wpuf_profile', 'on' );
$pack_id = ! empty( $_GET['pack_id'] ) ? sanitize_key( wp_unslash( $_GET['pack_id'] ) ) : '';

if ( $autologin_after_registration === 'on'
&& $pack_id !== null && is_integer( (int) $pack_id ) ) {
wp_set_current_user( $user_id );
wp_set_auth_cookie( $user_id );
}

if ( $pack_id ) {
wp_safe_redirect(
add_query_arg(
[
'action' => 'wpuf_pay',
'type' => 'pack',
'pack_id' => $pack_id,
], home_url() . '/payment'
)
);
exit();
}

add_filter( 'redirect_canonical', '__return_false' );
do_action( 'wpuf_user_activated', $user_id );
}
Expand All @@ -902,8 +921,8 @@ public function user_activation_message() {
public function wp_login_page_redirect() {
global $pagenow;

if ( ! is_admin() && $pagenow == 'wp-login.php' && isset( $_GET['action'] ) && $_GET['action'] == 'register' ) {
if ( wpuf_get_option( 'register_link_override', 'wpuf_profile' ) != 'on' ) {
if ( ! is_admin() && $pagenow === 'wp-login.php' && isset( $_GET['action'] ) && $_GET['action'] === 'register' ) {
if ( wpuf_get_option( 'register_link_override', 'wpuf_profile' ) !== 'on' ) {
return;
}

Expand Down Expand Up @@ -947,6 +966,7 @@ public function email_reset_pass( $user_login, $user_email, $key ) {

$message = __( 'Someone requested that the password be reset for the following account:', 'wp-user-frontend' ) . "\r\n\r\n";
$message .= network_home_url( '/' ) . "\r\n\r\n";
/* translators: %s: username */
$message .= sprintf( __( 'Username: %s', 'wp-user-frontend' ), $user_login ) . "\r\n\r\n";
$message .= __( 'If this was a mistake, just ignore this email and nothing will happen.', 'wp-user-frontend' ) . "\r\n\r\n";
$message .= __( 'To reset your password, visit the following address:', 'wp-user-frontend' ) . "\r\n\r\n";
Expand All @@ -959,7 +979,7 @@ public function email_reset_pass( $user_login, $user_email, $key ) {
}

$user_data = get_user_by( 'login', $user_login );

/* translators: %s: blogname */
$title = sprintf( __( '[%s] Password Reset', 'wp-user-frontend' ), $blogname );
$title = apply_filters( 'retrieve_password_title', $title );

Expand Down Expand Up @@ -1001,6 +1021,7 @@ public function show_errors() {
$errors = apply_filters( 'wpuf_login_errors', $this->login_errors );
if ( $errors ) {
foreach ( $errors as $error ) {
//phpcs:disable
echo wp_kses_post( '<div class="wpuf-error">' . __( $error, 'wp-user-frontend' ) . '</div>' );
}
}
Expand Down