Fluent Security Shortcodes

Below, you’ll find a detailed guide on how to add the Fluent Security Shortcodes to your WordPress website, including their parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the Fluent Security Plugin shortcodes not to show or not to work correctly.

Before starting, here is an overview of the Fluent Security Plugin and the shortcodes it provides:

Plugin Icon
FluentAuth – The Ultimate Authorization & Security Plugin for WordPress

"FluentAuth is an ultimate Authorization & Security Plugin for WordPress. Providing unprecedented site protection, this plugin ensures safe and secure website operation."

★★★☆✩ (15) Active Installs: 4000+ Tested with: 6.2.3 PHP Version: 7.0
Included Shortcodes:
  • [fluent_auth_login]
  • [fluent_auth_signup]
  • [fluent_auth]
  • [fluent_auth_reset_password]
  • [fluent_auth_magic_login]
  • [fs_auth_buttons]

Fluent Security [fluent_auth_login] Shortcode

The Fluent-Security shortcode ‘fluent_auth_login’ facilitates a secure login form. It checks if a user is already logged in and redirects them to the homepage. It also provides options for users to sign up or reset their password. The shortcode ensures the login form is only displayed when the plugin is enabled. Shortcode: [fluent_auth_login]

Shortcode: [fluent_auth_login]

Parameters

Here is a list of all possible fluent_auth_login shortcode parameters and attributes:

  • $attributes – array that holds shortcode attributes like redirect URL, show-signup, and show-reset-password
  • $headerContent – optional content to be displayed at the top of the form
  • redirect_to – URL to redirect the user after successful login
  • show-signup – decides whether to show the signup link or not
  • show-reset-password – determines if the reset password link should be displayed

Examples and Usage

Basic example – A basic usage of the fluent_auth_login shortcode without any additional parameters.

[fluent_auth_login /]

Advanced examples

Using the shortcode to display a login form with a redirect to a specific URL after successful login.

[fluent_auth_login redirect_to="https://www.example.com/dashboard" /]

Using the shortcode to display a login form with options to show signup and reset password links.

[fluent_auth_login show-signup="true" show-reset-password="true" /]

Using the shortcode to display a login form with a redirect to a specific URL after successful login and options to show signup and reset password links.

[fluent_auth_login redirect_to="https://www.example.com/dashboard" show-signup="true" show-reset-password="true" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [fluent_auth_login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('fluent_auth_login', array($this, 'loginForm'));

Shortcode PHP function:

function loginForm($attributes, $headerContent = '')
    {

        if (!$this->isEnabled()) {
            return '';
        }

        if (get_current_user_id()) {
            return '<p>' . sprintf(__('You are already logged in. <a href="%s">Go to Home Page</a>', 'fluent-security'), site_url()) . '</p>';
        }

        $this->loadAssets();
        $attributes = $this->getShortcodes($attributes);
        $this->handleAlreadyLoggedIn($attributes);

        $return = '<div id="fls_login_form" class="fls_login_wrapper">';

        if($headerContent) {
            $return .= $headerContent;
        }

        $redirect = '';

        if (!empty($attributes['redirect_to']) && filter_var($attributes['redirect_to'], FILTER_VALIDATE_URL)) {
            $redirect = $attributes['redirect_to'];
            add_filter('fluent_auth/social_redirect_to', function ($url) use ($redirect) {
                return $redirect;
            });
        }

        /*
         * Filter login form
         *
         * @since v1.0.0
         *
         * @param array $loginArgs
         */
        $loginArgs = apply_filters('fluent_auth/login_form_args', [
            'echo'           => false,
            'redirect'       => $redirect,
            'remember'       => true,
            'value_remember' => true,
            'action_url' => site_url('/')
        ]);

        $return .= $this->nativeLoginForm($loginArgs);

        if ($attributes['show-signup'] == 'true' && get_option('users_can_register')) {
            $return .= '<p style="text-align: center">'
                . __('Not registered?', 'fluent-security')
                . ' <a href="#" id="fls_show_signup">'
                . __('Create an Account', 'fluent-security')
                . '</a></p>';
        }

        if ($attributes['show-reset-password'] == 'true') {
            $return .= '<p style="text-align: center">'
                . __('Forgot your password?', 'fluent-security')
                . ' <a href="#" id="fls_show_reset_password">'
                . __('Reset Password', 'fluent-security')
                . '</a></p>';
        }

        $return .= '</div>';
        return $return;
    }

Code file location:

fluent-security/fluent-security/app/Hooks/Handlers/CustomAuthHandler.php

Fluent Security [fluent_auth_signup] Shortcode

The Fluent-Security plugin shortcode ‘fluent_auth_signup’ is used to create a registration form. This shortcode checks if user registration is enabled, and if the user is already logged in. The shortcode then retrieves the registration fields and builds the form. It also handles the visibility of the form based on the ‘hide’ attribute.

Shortcode: [fluent_auth_signup]

Examples and Usage

Basic example – The shortcode can be used to display a registration form on the webpage. This is a basic usage of the shortcode without any parameters.

[fluent_auth_signup /]

Advanced examples

Using the shortcode to hide the registration form. The ‘hide’ parameter can be set to ‘true’ to hide the registration form.

[fluent_auth_signup hide=true /]

Using the shortcode to customize the registration form. The ‘fields’ parameter can be passed an array of field names to be displayed in the form.

[fluent_auth_signup fields="username,email,password" /]

Using the shortcode to display a registration form and handle the case when the user is already logged in. The ‘already_logged_in_redirect’ parameter can be set to a URL to redirect the user if they are already logged in.

[fluent_auth_signup already_logged_in_redirect="http://example.com/home" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [fluent_auth_signup] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('fluent_auth_signup', array($this, 'registrationForm'));

Shortcode PHP function:

function registrationForm($attributes, $headerContent = '')
    {
        if (!$this->isEnabled()) {
            return '';
        }

        if (!get_option('users_can_register')) {
            return '<p>' . sprintf(__('User registration is not enabled. <a href="%s">Go to Home Page</a>', 'fluent-security'), esc_url(site_url())) . '</p>';
        }

        if (get_current_user_id()) {
            return '<p>' . sprintf(__('You are already logged in. <a href="%s">Go to Home Page</a>', 'fluent-security'), esc_url(site_url())) . '</p>';
        }

        $attributes = $this->getShortcodes($attributes);
        $this->handleAlreadyLoggedIn($attributes);

        $registrationFields = $this->getSignupFields();
        $hide = $attributes['hide'] == 'true' ? 'hide' : '';

        $this->loadAssets($hide);

        return $this->buildRegistrationForm($registrationFields, $hide, $attributes, $headerContent);
    }

Code file location:

fluent-security/fluent-security/app/Hooks/Handlers/CustomAuthHandler.php

Fluent Security [fluent_auth] Shortcode

The ‘fluent_auth’ shortcode from the Fluent-Security plugin is designed to manage user authentication. It provides a flexible way to display login, signup, and password reset forms. This shortcode first checks if the plugin is enabled and if the user is already logged in. If both conditions are met, it displays a message with a link to the homepage. If not, it generates an authentication form. The form includes login, signup, and password reset sections, which are displayed based on the website’s user registration settings. The shortcode also allows for custom redirect URLs post-authentication.

Shortcode: [fluent_auth]

Parameters

Here is a list of all possible fluent_auth shortcode parameters and attributes:

  • redirect_to – sets the URL where users are redirected after login, signup, or password reset
  • show-signup – when true, displays the signup form to the user
  • show-reset-password – when true, displays the password reset form to the user
  • hide – when true, hides the signup or reset password form

Examples and Usage

Basic example – The shortcode ‘fluent_auth’ is used to generate an authentication form. By default, it will display login, signup, and reset password forms if user registration is enabled on your site.

[fluent_auth /]

Advanced examples

1. In this example, the shortcode is used to display an authentication form with a custom redirect URL. After successful login, signup, or password reset, users will be redirected to the specified URL.

[fluent_auth redirect_to="https://www.yourwebsite.com/welcome" /]

2. In this example, the shortcode is used to display only the login form with a custom redirect URL. The ‘show-signup’ and ‘show-reset-password’ parameters are set to ‘false’ to hide the signup and reset password forms.

[fluent_auth_login redirect_to="https://www.yourwebsite.com/welcome" show-signup=false show-reset-password=false /]

3. In this example, the shortcode is used to display the signup form with a custom redirect URL. The ‘hide’ parameter is set to ‘false’ to display the signup form even if user registration is disabled on your site.

[fluent_auth_signup redirect_to="https://www.yourwebsite.com/welcome" hide=false /]

4. In this example, the shortcode is used to display the reset password form with a custom redirect URL. The ‘hide’ parameter is set to ‘false’ to display the reset password form even if user registration is disabled on your site.

[fluent_auth_reset_password redirect_to="https://www.yourwebsite.com/welcome" hide=false /]

PHP Function Code

In case you have difficulties debugging what causing issues with [fluent_auth] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('fluent_auth', array($this, 'authForm'));

Shortcode PHP function:

function authForm($attributes)
    {
        if (!$this->isEnabled()) {
            return '';
        }

        if (get_current_user_id()) {
            return '<p>' . sprintf(__('You are already logged in. <a href="%s">Go to Home Page</a>', 'fluent-security'), site_url()) . '</p>';
        }

        $atts = $this->getShortcodes($attributes);

        $authForm = '<div class="fls_auth_wrapper">';

        $authForm .= do_shortcode('[fluent_auth_login redirect_to="' . esc_url($atts['redirect_to']) . '" show-signup=true show-reset-password=true]');

        if (get_option('users_can_register')) {
            $authForm .= do_shortcode('[fluent_auth_signup redirect_to="' . esc_url($atts['redirect_to']) . '" hide=true]');
        }

        $authForm .= do_shortcode('[fluent_auth_reset_password redirect_to="' . esc_url($atts['redirect_to']) . '" hide=true]');

        $authForm .= '</div>';

        return $authForm;
    }

Code file location:

fluent-security/fluent-security/app/Hooks/Handlers/CustomAuthHandler.php

Fluent Security [fluent_auth_reset_password] Shortcode

The Fluent Security shortcode ‘fluent_auth_reset_password’ is used to generate a password reset form. If the user is logged in, a message is displayed directing them to the home page. This shortcode checks if the feature is enabled and if the user is already logged in. It then retrieves shortcode attributes and handles logged-in users. The shortcode also loads necessary assets and builds the password reset form.

Shortcode: [fluent_auth_reset_password]

Examples and Usage

Basic example – Display a reset password form using the shortcode with no additional parameters.

[fluent_auth_reset_password /]

Advanced examples

Using the shortcode to display a reset password form with hidden fields. The ‘hide’ attribute can be set to ‘true’ to hide the form fields.

[fluent_auth_reset_password hide=true /]

Using the shortcode to display a reset password form with custom attributes. The attributes parameter can be used to customize the form fields and behavior.

[fluent_auth_reset_password attributes="custom_attributes" /]

Using the shortcode to display a reset password form with a custom header. The ‘headerContent’ parameter can be used to add a custom header to the form.

[fluent_auth_reset_password headerContent="Welcome to our site, please reset your password." /]

Combining multiple parameters to create a more complex shortcode. In this example, the reset password form will have hidden fields, custom attributes, and a custom header.

[fluent_auth_reset_password hide=true attributes="custom_attributes" headerContent="Welcome to our site, please reset your password." /]

PHP Function Code

In case you have difficulties debugging what causing issues with [fluent_auth_reset_password] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('fluent_auth_reset_password', array($this, 'restPasswordForm'));

Shortcode PHP function:

function restPasswordForm($attributes, $headerContent = '')
    {
        if (!$this->isEnabled()) {
            return '';
        }

        if (get_current_user_id()) {
            return '<p>' . sprintf(__('You are already logged in. <a href="%s">Go to Home Page</a>', 'fluent-security'), esc_url(site_url())) . '</p>';
        }

        $attributes = $this->getShortcodes($attributes);
        $this->handleAlreadyLoggedIn($attributes);

        $resetPasswordFields = static::resetPasswordFields();
        $hide = $attributes['hide'] == 'true' ? 'hide' : '';

        $this->loadAssets($hide);

        return $this->buildResetPassForm($resetPasswordFields, $hide, $attributes, $headerContent);
    }

Code file location:

fluent-security/fluent-security/app/Hooks/Handlers/CustomAuthHandler.php

Fluent Security [fluent_auth_magic_login] Shortcode

The Fluent-Security shortcode ‘fluent_auth_magic_login’ facilitates a magic login form. It checks if the plugin and magic login handler are enabled, and if the user is already logged in. If logged in, it redirects to the home page. The shortcode accepts attributes and displays a form requesting email/username. It also includes a nonce for security and an optional redirect.

Shortcode: [fluent_auth_magic_login]

Examples and Usage

Basic example – The shortcode ‘fluent_auth_magic_login’ can be used to display a login form on any page or post. This shortcode doesn’t require any parameters to function.

[fluent_auth_magic_login /]

Advanced examples

Redirecting after successful login: The shortcode can accept a ‘redirect_to’ parameter. This can be used to redirect the user to a specific page after a successful login. The value of ‘redirect_to’ should be the URL of the page where you want to redirect the user.

[fluent_auth_magic_login redirect_to="http://yourwebsite.com/your-page" /]

Adding custom content: The shortcode also accepts custom content within its opening and closing tags. This content will be displayed above the login form. This can be used to display a custom message to the users before they log in.

[fluent_auth_magic_login]Welcome! Please log in to continue.[/fluent_auth_magic_login]

Combining both parameters: You can also use both parameters together to display a custom message and redirect the user after login.

[fluent_auth_magic_login redirect_to="http://yourwebsite.com/your-page"]Welcome! Please log in to continue.[/fluent_auth_magic_login]

PHP Function Code

In case you have difficulties debugging what causing issues with [fluent_auth_magic_login] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('fluent_auth_magic_login', array($this, 'magicLoginForm'));

Shortcode PHP function:

function magicLoginForm($attributes, $content = '')
    {
        $magicHandler = new MagicLoginHandler();
        if (!$this->isEnabled() || !$magicHandler->isEnabled()) {
            return '';
        }

        if (get_current_user_id()) {
            return '<p>' . sprintf(__('You are already logged in. <a href="%s">Go to Home Page</a>', 'fluent-security'), site_url()) . '</p>';
        }

        $atts = $this->getShortcodes($attributes);

        $magicHandler->pushAssets();

        ob_start();
        ?>
        <div id="fls_magic_login">
            <div class="fls_magic_login_form fls_magic_login">
                <?php if ($content): ?>
                    <div class="fls_magic_content">
                        <?php echo wp_kses_post($content); ?>
                    </div>
                <?php endif; ?>
                <label for="fls_magic_logon">
                    <?php _e('Your Email/Username', 'fluent-security'); ?>
                </label>
                <input placeholder="<?php _e('Your Email/Username', 'fluent-security'); ?>" id="fls_magic_logon"
                       class="fls_magic_input" type="text"/>
                <input id="fls_magic_logon_nonce" type="hidden"
                       value="<?php echo wp_create_nonce('fls_magic_send_magic_email'); ?>"/>
                <?php if (!empty($atts['redirect_to'])): ?>
                    <input type="hidden" value="<?php echo esc_url($atts['redirect_to']); ?>" name="redirect_to"/>
                <?php endif; ?>
                <div class="fls_magic_submit_wrapper">
                    <button class="button button-primary button-large" id="fls_magic_submit">
                        <?php _e('Continue', 'fluent-security'); ?>
                    </button>
                </div>
            </div>
        </div>
        <?php

        return ob_get_clean();
    }

Code file location:

fluent-security/fluent-security/app/Hooks/Handlers/CustomAuthHandler.php

Fluent Security [fs_auth_buttons] Shortcode

The Fluent-Security shortcode ‘fs_auth_buttons’ generates social login buttons for Github and Google. It checks if the user is logged in and whether social login is enabled. It uses the ‘fs_auth_buttons’ shortcode to render the buttons, with custom attributes for the button title, prefix, and redirect URL. The buttons are only displayed if their respective login methods are enabled. The shortcode also ensures secure output by escaping the data.

Shortcode: [fs_auth_buttons]

Parameters

Here is a list of all possible fs_auth_buttons shortcode parameters and attributes:

  • title – sets the title for the login/signup form
  • title_prefix – sets the prefix for the social login buttons
  • redirect – sets the URL where users will be redirected after login

Examples and Usage

Basic example – Displaying social authentication buttons with default settings.

[fs_auth_buttons /]

Advanced examples

Displaying social authentication buttons with a custom title and a custom prefix for the button titles.

[fs_auth_buttons title="Sign in or Register" title_prefix="Join with" /]

Displaying social authentication buttons with a custom redirect URL after successful authentication.

[fs_auth_buttons redirect="https://www.yourwebsite.com/welcome" /]

Combining all the parameters to fully customize the social authentication buttons.

[fs_auth_buttons title="Sign in or Register" title_prefix="Join with" redirect="https://www.yourwebsite.com/welcome" /]

PHP Function Code

In case you have difficulties debugging what causing issues with [fs_auth_buttons] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode('fs_auth_buttons', [$this, 'socialAuthShortcode']);

Shortcode PHP function:

function socialAuthShortcode($atts, $content = '')
    {
        if (is_user_logged_in()) {
            return '';
        }

        if (!$this->isEnabled()) {
            return '';
        }

        $data = shortcode_atts(array(
            'title'        => __('Login or Signup', 'fluent-security'),
            'title_prefix' => __('Connect with', 'fluent-security'),
            'redirect'     => ''
        ), $atts);

        if (empty($data['redirect'])) {
            $data['redirect'] = get_permalink();
        }

        $buttons = [
            'github' => [
                'link_class' => 'fs_auth_btn fs_auth_github',
                'icon'       => '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" role="img" aria-labelledby="ahu5wq2nrtsicu3szbxaract8as7mhww" aria-hidden="true" class="crayons-icon"><title id="ahu5wq2nrtsicu3szbxaract8as7mhww">github</title><path d="M12 2C6.475 2 2 6.475 2 12a9.994 9.994 0 006.838 9.488c.5.087.687-.213.687-.476 0-.237-.013-1.024-.013-1.862-2.512.463-3.162-.612-3.362-1.175-.113-.288-.6-1.175-1.025-1.413-.35-.187-.85-.65-.013-.662.788-.013 1.35.725 1.538 1.025.9 1.512 2.338 1.087 2.912.825.088-.65.35-1.087.638-1.337-2.225-.25-4.55-1.113-4.55-4.938 0-1.088.387-1.987 1.025-2.688-.1-.25-.45-1.275.1-2.65 0 0 .837-.262 2.75 1.026a9.28 9.28 0 012.5-.338c.85 0 1.7.112 2.5.337 1.912-1.3 2.75-1.024 2.75-1.024.55 1.375.2 2.4.1 2.65.637.7 1.025 1.587 1.025 2.687 0 3.838-2.337 4.688-4.562 4.938.362.312.675.912.675 1.85 0 1.337-.013 2.412-.013 2.75 0 .262.188.574.688.474A10.016 10.016 0 0022 12c0-5.525-4.475-10-10-10z"></path></svg>',
                'title'      => sprintf(__('%s Github', 'fluent-security'), $data['title_prefix']),
                'url'        => add_query_arg([
                    'fs_auth'            => 'github',
                    'fs_type'            => 'redirect',
                    'intent_redirect_to' => $data['redirect']
                ], wp_login_url())
            ],
            'google' => [
                'link_class' => 'fs_auth_btn fs_auth_google',
                'icon'       => '<svg xmlns="http://www.w3.org/2000/svg"  viewBox="0 0 48 48" width="24px" height="24px"><path fill="#FFC107" d="M43.611,20.083H42V20H24v8h11.303c-1.649,4.657-6.08,8-11.303,8c-6.627,0-12-5.373-12-12c0-6.627,5.373-12,12-12c3.059,0,5.842,1.154,7.961,3.039l5.657-5.657C34.046,6.053,29.268,4,24,4C12.955,4,4,12.955,4,24c0,11.045,8.955,20,20,20c11.045,0,20-8.955,20-20C44,22.659,43.862,21.35,43.611,20.083z"/><path fill="#FF3D00" d="M6.306,14.691l6.571,4.819C14.655,15.108,18.961,12,24,12c3.059,0,5.842,1.154,7.961,3.039l5.657-5.657C34.046,6.053,29.268,4,24,4C16.318,4,9.656,8.337,6.306,14.691z"/><path fill="#4CAF50" d="M24,44c5.166,0,9.86-1.977,13.409-5.192l-6.19-5.238C29.211,35.091,26.715,36,24,36c-5.202,0-9.619-3.317-11.283-7.946l-6.522,5.025C9.505,39.556,16.227,44,24,44z"/><path fill="#1976D2" d="M43.611,20.083H42V20H24v8h11.303c-0.792,2.237-2.231,4.166-4.087,5.571c0.001-0.001,0.002-0.001,0.003-0.002l6.19,5.238C36.971,39.205,44,34,44,24C44,22.659,43.862,21.35,43.611,20.083z"/></svg>',
                'title'      => sprintf(__('%s Google', 'fluent-security'), $data['title_prefix']),
                'url'        => add_query_arg([
                    'fs_auth'            => 'google',
                    'fs_type'            => 'redirect',
                    'intent_redirect_to' => $data['redirect']
                ], wp_login_url())
            ]
        ];

        if (!$this->isEnabled('google')) {
            unset($buttons['google']);
        }

        if (!$this->isEnabled('github')) {
            unset($buttons['github']);
        }

        ?>

        <div class="fm_login_wrapper">
            <?php if ($data['title']): ?>
                <h3><?php echo esc_attr($data['title']); ?></h3>
            <?php endif; ?>
            <?php echo wp_kses_post($content); ?>
            <div class="fm_buttons_wrap">
                <?php foreach ($buttons as $button): ?>
                    <a class="<?php echo esc_attr($button['link_class']); ?>"
                       href="<?php echo esc_url($button['url']); ?>">
                        <?php echo Arr::get($button, 'icon'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped  ?>
                        <?php echo esc_html($button['title']); ?>
                    </a>
                <?php endforeach; ?>
            </div>
        </div>

        <style>
            .fm_login_wrapper {
                padding: 20px;
                max-width: 600px !important;
                margin: 0 auto;
                text-align: center;
            }

            .fs_auth_btn {
                white-space: nowrap !important;
                flex-grow: 1 !important;
                background-color: #24292e;
                color: #fff;
                text-decoration: none;
                padding: 5px 10px;
                line-height: 1;
                vertical-align: top;
                display: flex;
                align-items: center;
                border-radius: 5px;
                justify-content: center;
                margin-bottom: 10px;
            }

            a.fs_auth_btn.fs_auth_google {
                color: #24292e;
                background: white;
                border: 1px solid #23292f;
            }

            .fs_auth_btn svg {
                margin-right: 5px;
            }

            .fs_auth_btn.fs_auth_github svg {
                fill: white;
            }

            .fs_auth_btn.fs_auth_github:hover {
                background: black;
                color: white;
            }

            .fs_auth_btn.fs_auth_google:hover {
                background: white;
                color: black;
            }

            .fs_buttons_wrap {
                display: flex;
            }

            .fs_buttons_wrap a {
                margin: 10px;
            }

            @media only screen and (max-width: 600px) {
                .fs_buttons_wrap {
                    display: flex;
                    flex-wrap: wrap;
                    flex-direction: column;
                }
            }
        </style>

        <?php
    }

Code file location:

fluent-security/fluent-security/app/Hooks/Handlers/SocialAuthHandler.php

Conclusion

Now that you’ve learned how to embed the Fluent Security Plugin shortcodes, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *