' . esc_html__( 'You are already logged in.', 'forumax' ) . '';
}
// Same shortcode is used on several spots of one page (reply prompt, topic
// prompt, subscribe modal, page content). Each instance needs its own IDs
// so a later form is not dropped and tabs/labels stay wired to that form.
static $frmx_login_form_instance = 0;
$frmx_login_form_instance++;
$uid = 'frmx-auth-' . $frmx_login_form_instance;
// Extract shortcode attributes with defaults.
$atts = shortcode_atts( array(
'redirect' => '',
), $atts );
// Set redirect URL.
$redirect_url = ! empty( $atts['redirect'] ) ? $atts['redirect'] : get_permalink();
$can_register = get_option( 'users_can_register' );
$wrapper_id = $uid;
ob_start();
?>
$redirect_url,
'label_username' => esc_html__( 'Username or Email', 'forumax' ),
'label_password' => esc_html__( 'Password', 'forumax' ),
'label_remember' => esc_html__( 'Remember Me', 'forumax' ),
'label_log_in' => esc_html__( 'Sign In', 'forumax' ),
'form_id' => $uid . '-login',
'id_username' => $uid . '-user',
'id_password' => $uid . '-pass',
'id_remember' => $uid . '-remember',
'id_submit' => $uid . '-submit',
'remember' => true,
'echo' => false,
) );
// Class hook for styling (keeps a stable selector with form_id).
$form_html = preg_replace(
'/
get_error_code(), $referrer ) );
exit;
}
// Create the user.
$user_id = wp_create_user( $user_login, $user_pass, $user_email );
if ( is_wp_error( $user_id ) ) {
$error_code = $user_id->get_error_code();
wp_safe_redirect( add_query_arg( 'reg_error', $error_code, $referrer ) );
exit;
}
// Fire standard WordPress registration action.
do_action( 'user_register', $user_id );
// Auto-login the new user.
wp_set_current_user( $user_id );
wp_set_auth_cookie( $user_id, true );
wp_safe_redirect( $redirect );
exit;
}
add_action( 'admin_post_nopriv_forumax_register', 'forumax_handle_registration' );
add_action( 'admin_post_forumax_register', 'forumax_handle_registration' );