PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.0.0
Forumax – AI Powered Advanced Community Forum Plugin v2.0.0
2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 2.0.0 2.1.0 All 29 releases
bbp-core / includes / login-form.php

login-form.php in Forumax – AI Powered Advanced Community Forum Plugin 2.0.0, at includes/login-form.php

74 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 function forumax_login_form_shortcode( $atts ) {
3 // If user already logged in, return a message or redirect
4 if ( is_user_logged_in() ) {
5 return '<div class="login-already" style="color: green; margin-bottom: 15px;">' . esc_html__( 'You are already logged in.', 'forumax' ) . '</div>';
6 }
7
8 // Extract shortcode attributes with defaults
9 $atts = shortcode_atts( array(
10 'redirect' => '',
11 'submit_label' => esc_html__( 'Sign in', 'forumax' ),
12 'username_label' => esc_html__( 'Username', 'forumax' ),
13 'password_label' => esc_html__( 'Password', 'forumax' ),
14 'error_notice' => esc_html__( 'Invalid username or password. Please try again.', 'forumax' ),
15 'username_placeholder' => esc_attr__( 'Enter your username', 'forumax' ),
16 'password_placeholder' => esc_attr__( 'Enter your password', 'forumax' ),
17 'button_color' => '#1e73be', // Default button background color
18 'button_text_color' => '#ffffff', // default text color
19 'button_position' => 'left', // left, center, right
20 'signup_link' => '', // attribute for signup link
21 ), $atts );
22
23 // Set redirect URL
24 $redirect_url = ! empty( $atts['redirect'] ) ? $atts['redirect'] : get_permalink();
25
26 // Determine button alignment based on 'button_position' attribute
27 $button_alignment = 'text-align: center;'; // default
28 if ( $atts['button_position'] === 'left' ) {
29 $button_alignment = 'text-align: left;';
30 } elseif ( $atts['button_position'] === 'right' ) {
31 $button_alignment = 'text-align: right;';
32 }
33
34 ob_start();
35
36 $form_args = array(
37 'redirect' => $redirect_url,
38 'label_username' => $atts['username_label'],
39 'label_password' => $atts['password_label'],
40 'label_remember' => esc_html__( 'Remember Me', 'forumax' ),
41 'label_log_in' => $atts['submit_label'],
42 'form_id' => 'forumax_login_form',
43 'remember' => true,
44 ''
45 );
46
47 wp_login_form($form_args);
48
49 if ( ! empty( $atts['signup_link'] ) ) : ?>
50 <div class="signup-text">
51 <?php esc_html_e( 'Don’t have an account yet?', 'forumax' ); ?>
52 <a href="<?php echo esc_url( $atts['signup_link'] ); ?>">
53 <?php esc_html_e( 'Sign up here', 'forumax' ); ?>
54 </a>
55 </div>
56 <?php endif; ?>
57 <?php
58
59 return ob_get_clean();
60 }
61
62 add_shortcode( 'forumax_login_form', 'forumax_login_form_shortcode' );
63
64 // Redirect to the referrer page after login
65 add_action( 'wp_login_failed', 'forumax_login_failed_redirect' );
66
67 function forumax_login_failed_redirect( $username ) {
68 $referrer = wp_get_referer();
69 if ( ! empty( $referrer ) && ! str_contains( $referrer, 'wp-login.php' ) ) {
70 wp_redirect( add_query_arg( 'login', 'failed', $referrer ) );
71 exit;
72 }
73 }
74