Adding LoginPress Autologin Filters to Your WordPress Site

LoginPress Pro offers an Autologin Add-on. It best helps you create magic links for your users, based on their specific roles, that they can use to log in to your site.

With LoginPress Pro 3.0, many other useful features are added to the core functionality of the Add-on. You can further enhance the core functionality of the Add-on using filters.

This knowledgebase article will show you the LoginPress Autologin filters that you can use for several reasons, including:

LoginPress Autologin Filters

1. LoginPress Autologin Default Expiration

    By default, all the Autologin links expire after 7 days. However, you can change the default expiration time with a filter. The point worth noting is that it can be applied to new users and newly created links only.

    You only need to update the code to your site’s functions.php file.

    Note: It’s recommended to use a child theme to edit the functions.php file instead of the parent theme. You may lose the modified code when you update your theme. It might cause some adverse effects on your website.

    Here is the code for you:

    /**
     * This function increases the default time for new links of LoginPress Autologin.
     *
     * @param string $default_expire The date and time string.
     * @return string $default_expire The modified date and time string.
     */
    function loginpress_autologin_default_expiration( $default_expire ) {
    	$date           = gmdate( 'Y-m-d' );
    	$default_expire = gmdate( 'Y-m-d', strtotime( "$date -1 day" ) ); // PHP Date style:  yy-mm-dd.
    	return $default_expire;
    }
    add_filter('loginpress_autologin_default_expiration','loginpress_autologin_default_expiration');
    

    2. LoginPress Autologin Email Subject

      Autologin Add-on lets you send an Email to the users containing the autologin.

      If you don’t like the default subject of this email, then you can easily change the default Subject for the Autologin Link Email. All you need to do is to update the code in your site’s functions.php file.

      Here is the code for you:

      /**
       * Filter for modifying the autologin email subject.
       *
       * @param string $subject The subject of the email.
       * @param string $blog_name The blog name.
       * @return string $new_subject The new subject of the email.
       */
      function custom_autologin_email_subject( $subject, $blog_name ) {
      	// Modify the subject as needed.
      	$new_subject = sprintf( __( 'New Subject [%s]', 'loginpress-pro' ), $blog_name );
      	return $new_subject;
      }
      add_filter( 'loginpress_autologin_email_subject', 'custom_autologin_email_subject', 10, 2 );
      

      3. LoginPress Autologin Inactive Error

        LoginPress Autologin also introduces some errors in certain conditions.

        In this instance if your username is inactive and still needs to be verified from admin. It would show you an error stating that your account is inactive.

        You can easily change the default Inactive Error message for Autologin by updating the code in the functions.php file.

        Here is the code for you:

        /**
         * Filter for customizing the autologin inactive error message.
         *
         * @param string $error Default error message.
         * @return string Modified error message.
         */
        function custom_loginpress_autologin_inactive_error( $error ) {
            // Modify the error message as needed
            $modified_error = __( 'Your customized error message here', 'loginpiress-pro' );
            return $modified_error;
        }
        add_filter( 'loginpress_autologin_inactive_error', 'custom_loginpress_autologin_inactive_error' );
        

        4. LoginPress Autologin Disable Error

          In this instance, if the admin of the site disables your autologin link you will be shown an error message stating that your link is disabled.

          You can easily change the default Disable Error Message for Autologin by simply pasting a code in your functions.php file.

          Here is the code for you:

          /**
           * Filter for customizing the error message when autologin is disabled.
           *
           * @param string $error Default error message.
           * @return string Modified error message.
           */
          function custom_loginpress_autologin_disable_error( $error ) {
              // Modify the error message as needed
              $modified_error = __( 'Your customized error message for autologin disabled', 'loginpress-pro' );
              return $modified_error;
          }
          add_filter( 'loginpress_autologin_disable_error', 'custom_loginpress_autologin_disable_error' );
          

          5. LoginPress Autologin Expired Error

            You can also change the Autologin Expired Error message for Autologin. 

            Here is the code for you:

            /**
             * Filter for customizing the error message when the Auto Login link has expired.
             *
             * @param string $error Default error message.
             * @return string Modified error message.
             */
            function custom_loginpress_autologin_expired_error( $error ) {
                // Modify the error message as needed
                $modified_error = __( 'Your customized error message for expired autologin link', 'loginpress-pro' );
                return $modified_error;
            }
            add_filter( 'loginpress_autologin_expired_error', 'custom_loginpress_autologin_expired_error' );
            

            6. LoginPress Autologin Invalid Login Code

              Want to change the default Autologin Invalid Login code error message? No problem! Simply add the following code to your functions.php file.

              Here is the code for you:

              /**
               * Filter for customizing the error message when an invalid autologin code is provided.
               *
               * @param string $error Default error message.
               * @return string Modified error message.
               */
              function custom_loginpress_autologin_invalid_login_code( $error ) {
                  // Modify the error message as needed
                  $modified_error = __( 'Your customized error message for invalid autologin code', 'loginpress-pro' );
                  return $modified_error;
              }
              add_filter( 'loginpress_autologin_invalid_login_code', 'custom_loginpress_autologin_invalid_login_code' );
              

              7. LoginPress Autologin Email Message

                Want to change the default Autologin email message? No problem! Simply add the following code to your functions.php file.

                Here is the code for you:

                // Define a callback function for the filter
                function custom_loginpress_autologin_email_msg($message, $blog_name, $user_name, $code) {
                    // Build a custom message
                    $custom_message = "Hello $user_name,\n\n";
                    $custom_message .= "Welcome to $blog_name! Your autologin link is:\n";
                    $custom_message .= $code;
                
                    // Append some additional information
                    $custom_message .= "\n\nPlease keep this link confidential as it allows direct access to your account.";
                
                    // Return the modified message
                    return $custom_message;
                }
                
                // Add the filter
                add_filter('loginpress_autologin_email_msg', 'custom_loginpress_autologin_email_msg', 10, 4);
                

                That’s it. We hope you understand how to add the Autologin filter to your WordPress site. 

                If you have any doubts or questions related to this matter, please don’t hesitate to contact our support team.

                Still stuck? How can we help?

                Updated on April 24, 2024

                Documentation
                LoginPress Support
                triangular shape yellowish icon

                Frequently Asked Questions (FAQs)

                These FAQs answer the most common questions about our WordPress custom login page plugin.

                three shapes icon

                Where can I get support for LoginPress?

                If you need help with LoginPress, you can contact us here. We’ll be happy to answer any questions about the plugin.

                Do you have an affiliate program?

                Yes, we have an affiliate program that you can sign up for here. As an affiliate, you’ll earn a commission on every sale you refer to us.

                Do you offer refunds?

                Yes, we offer a 14-day money-back guarantee on all of our plans. If you’re unsatisfied with LoginPress, simply contact us within 14 days of your purchase, and we’ll process a refund.

                Can I upgrade my license after my initial purchase?

                Yes, you can upgrade your LoginPress license at any time. Simply log into your account and go to the My Downloads page. From here, you can upgrade your license and download the latest version of the plugin.

                Will LoginPress slow down my website?

                No, LoginPress will not slow down your website. The plugin is lightweight and only loads the necessary files when someone tries to access your login page.

                three shapes icon

                If you Still have Questions?

                Get In Touch