| @@ -20,8 +20,15 @@ | ||
| 20 | 20 | if ( is_user_logged_in() ) { |
| 21 | 21 | return '<div class="frmx-auth-logged-in">' . esc_html__( 'You are already logged in.', 'forumax' ) . '</div>'; |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | + // Same shortcode is used on several spots of one page (reply prompt, topic | |
| 25 | + // prompt, subscribe modal, page content). Each instance needs its own IDs | |
| 26 | + // so a later form is not dropped and tabs/labels stay wired to that form. | |
| 27 | + static $frmx_login_form_instance = 0; | |
| 28 | + $frmx_login_form_instance++; | |
| 29 | + $uid = 'frmx-auth-' . $frmx_login_form_instance; | |
| 30 | + | |
| 24 | 31 | // Extract shortcode attributes with defaults. |
| 25 | 32 | $atts = shortcode_atts( array( |
| 26 | 33 | 'redirect' => '', |
| 27 | 34 | ), $atts ); |
| @@ -29,9 +36,9 @@ | ||
| 29 | 36 | // Set redirect URL. |
| 30 | 37 | $redirect_url = ! empty( $atts['redirect'] ) ? $atts['redirect'] : get_permalink(); |
| 31 | 38 | |
| 32 | 39 | $can_register = get_option( 'users_can_register' ); |
| 33 | - $wrapper_id = uniqid( 'frmx-auth-tabs-' ); | |
| 40 | + $wrapper_id = $uid; | |
| 34 | 41 | |
| 35 | 42 | ob_start(); |
| 36 | 43 | ?> |
| 37 | 44 | <div class="frmx-auth-tabs" id="<?php echo esc_attr( $wrapper_id ); ?>"> |
| @@ -55,13 +62,25 @@ | ||
| 55 | 62 | 'label_username' => esc_html__( 'Username or Email', 'forumax' ), |
| 56 | 63 | 'label_password' => esc_html__( 'Password', 'forumax' ), |
| 57 | 64 | 'label_remember' => esc_html__( 'Remember Me', 'forumax' ), |
| 58 | 65 | 'label_log_in' => esc_html__( 'Sign In', 'forumax' ), |
| 59 | - 'form_id' => 'forumax_login_form', | |
| 66 | + 'form_id' => $uid . '-login', | |
| 67 | + 'id_username' => $uid . '-user', | |
| 68 | + 'id_password' => $uid . '-pass', | |
| 69 | + 'id_remember' => $uid . '-remember', | |
| 70 | + 'id_submit' => $uid . '-submit', | |
| 60 | 71 | 'remember' => true, |
| 61 | 72 | 'echo' => false, |
| 62 | 73 | ) ); |
| 63 | 74 | |
| 75 | + // Class hook for styling (keeps a stable selector with form_id). | |
| 76 | + $form_html = preg_replace( | |
| 77 | + '/<form\b/i', | |
| 78 | + '<form class="forumax_login_form"', | |
| 79 | + $form_html, | |
| 80 | + 1 | |
| 81 | + ); | |
| 82 | + | |
| 64 | 83 | // Add placeholders to core login form fields. |
| 65 | 84 | $username_placeholder = esc_attr__( 'Username or Email', 'forumax' ); |
| 66 | 85 | $password_placeholder = esc_attr__( 'Password', 'forumax' ); |
| 67 | 86 | |
| @@ -94,25 +113,25 @@ | ||
| 94 | 113 | <input type="hidden" name="action" value="forumax_register" /> |
| 95 | 114 | <input type="hidden" name="redirect_to" value="<?php echo esc_url( $redirect_url ); ?>" /> |
| 96 | 115 | |
| 97 | 116 | <div class="frmx-auth-field"> |
| 98 | - <label for="frmx_reg_user_login"><?php esc_html_e( 'Username', 'forumax' ); ?></label> | |
| 99 | - <input type="text" name="user_login" id="frmx_reg_user_login" placeholder="<?php esc_attr_e( 'Username', 'forumax' ); ?>" autocomplete="username" required /> | |
| 117 | + <label for="<?php echo esc_attr( $uid ); ?>-reg-login"><?php esc_html_e( 'Username', 'forumax' ); ?></label> | |
| 118 | + <input type="text" name="user_login" id="<?php echo esc_attr( $uid ); ?>-reg-login" placeholder="<?php esc_attr_e( 'Username', 'forumax' ); ?>" autocomplete="username" required /> | |
| 100 | 119 | </div> |
| 101 | 120 | |
| 102 | 121 | <div class="frmx-auth-field"> |
| 103 | - <label for="frmx_reg_user_email"><?php esc_html_e( 'Email', 'forumax' ); ?></label> | |
| 104 | - <input type="email" name="user_email" id="frmx_reg_user_email" placeholder="<?php esc_attr_e( 'Email', 'forumax' ); ?>" autocomplete="email" required /> | |
| 122 | + <label for="<?php echo esc_attr( $uid ); ?>-reg-email"><?php esc_html_e( 'Email', 'forumax' ); ?></label> | |
| 123 | + <input type="email" name="user_email" id="<?php echo esc_attr( $uid ); ?>-reg-email" placeholder="<?php esc_attr_e( 'Email', 'forumax' ); ?>" autocomplete="email" required /> | |
| 105 | 124 | </div> |
| 106 | 125 | |
| 107 | 126 | <div class="frmx-auth-field"> |
| 108 | - <label for="frmx_reg_user_pass"><?php esc_html_e( 'Password', 'forumax' ); ?></label> | |
| 109 | - <input type="password" name="user_pass" id="frmx_reg_user_pass" placeholder="<?php esc_attr_e( 'Password', 'forumax' ); ?>" autocomplete="new-password" required /> | |
| 127 | + <label for="<?php echo esc_attr( $uid ); ?>-reg-pass"><?php esc_html_e( 'Password', 'forumax' ); ?></label> | |
| 128 | + <input type="password" name="user_pass" id="<?php echo esc_attr( $uid ); ?>-reg-pass" placeholder="<?php esc_attr_e( 'Password', 'forumax' ); ?>" autocomplete="new-password" required /> | |
| 110 | 129 | </div> |
| 111 | 130 | |
| 112 | 131 | <div class="frmx-auth-field"> |
| 113 | - <label for="frmx_reg_user_pass_confirm"><?php esc_html_e( 'Confirm Password', 'forumax' ); ?></label> | |
| 114 | - <input type="password" name="user_pass_confirm" id="frmx_reg_user_pass_confirm" placeholder="<?php esc_attr_e( 'Confirm Password', 'forumax' ); ?>" autocomplete="new-password" required /> | |
| 132 | + <label for="<?php echo esc_attr( $uid ); ?>-reg-pass-confirm"><?php esc_html_e( 'Confirm Password', 'forumax' ); ?></label> | |
| 133 | + <input type="password" name="user_pass_confirm" id="<?php echo esc_attr( $uid ); ?>-reg-pass-confirm" placeholder="<?php esc_attr_e( 'Confirm Password', 'forumax' ); ?>" autocomplete="new-password" required /> | |
| 115 | 134 | </div> |
| 116 | 135 | |
| 117 | 136 | <?php |
| 118 | 137 | /** |
| @@ -124,9 +143,9 @@ | ||
| 124 | 143 | do_action( 'register_form' ); |
| 125 | 144 | ?> |
| 126 | 145 | |
| 127 | 146 | <div class="frmx-auth-submit"> |
| 128 | - <button type="submit" id="frmx-register-submit" name="wp-submit" class="button submit fill-brand"> | |
| 147 | + <button type="submit" id="<?php echo esc_attr( $uid ); ?>-register" name="wp-submit" class="button submit fill-brand"> | |
| 129 | 148 | <?php esc_html_e( 'Register', 'forumax' ); ?> |
| 130 | 149 | </button> |
| 131 | 150 | </div> |
| 132 | 151 | |