• Hi,

    I was creating a shortcode but it’s not working with user-sync plugin. The code I use for the shortcode is:

    function ts_user_login_shortcode() {
        ob_start();
        $redirect = $_GET['redirect'];
        if ( is_user_logged_in() ) {
            // User is already logged in
        } else {
            // Display login form with Bootstrap 5 classes
            ?>
            <form class="form" method="post" action="<?php echo esc_url( wp_login_url() ); ?>">
                <div class="mb-3">
                    <label for="user_login" class="form-label">Username or Email</label>
                    <input type="text" name="log" id="user_login" class="form-control" value="<?php echo esc_attr( isset( $_POST['log'] ) ? $_POST['log'] : '' ); ?>" />
                </div>
                <div class="mb-3">
                    <label for="user_pass" class="form-label">Password</label>
                    <input type="password" name="pwd" id="user_pass" class="form-control" />
                </div>
                <?php do_action( 'login_form' ); ?>
                <div class="mb-3">
                    <input type="submit" name="wp-submit" id="wp-submit" class="btn btn-primary" value="Log In" />
                    <input type="hidden" name="redirect_to" value="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" />
                </div>
            </form>
            
            <script>
                // Reload the page after successful login
                document.addEventListener('DOMContentLoaded', function() {
                    var loginForm = document.querySelector('.form');
                    loginForm.addEventListener('submit', function(event) {
                        event.preventDefault(); // Prevent form submission
                        var formData = new FormData(loginForm);
                        fetch(loginForm.action, {
                            method: loginForm.method,
                            body: formData
                        })
                        .then(function(response) {
                            if (response.ok) {
                                window.location.href = '<?php echo $redirect; ?>'; // Redirect to demo.com
                            } else {
                                console.error('Login failed.');
                            }
                        })
                        .catch(function(error) {
                            console.error('Login failed:', error);
                        });
                    });
                });
            </script>
            <?php
        }
    
        return ob_get_clean();
    }
    add_shortcode( 'user_login_register', 'ts_user_login_shortcode' );

    Please give me the modified code for working with user-sync plugin

  • The topic ‘[NSFW] Help me to fix the shortcode for user-sync’ is closed to new replies.