Force login on any button click

I would like to force login in on any button clicked on the page. An example can be found in this page:
https://gals.exprealty.com/homes/ga/milton/gamlsfarm85164988516498/15135-hopewell-rd-milton-ga-30004

Any plugin suggestions? Or anyone has coded this before?

  • Dimitris
    • Support Star

    Hello BBP

    You could use a little jQuery snippet to trigger the click event of a “Login” button that’s already present on the page.

    (function ($) {
      $(document).ready(function () {
        // get the click event from anywhere, replace '*' with the desired selectors
          $('*').click(function () {
          // trigger the click event for the Login button, replace '#login-btn' with your login button selector
          $('#login-btn').trigger('click');
        });
      });
    })(jQuery);

    I hope that helps! :slight_smile:

    Thank you,
    Dimitris

  • Dimitris
    • Support Star

    Hello BBP

    As you’ve mentioned to Nastia during a live chat session, the above code doesn’t cover touch events on mobile devices. You could try something like the following though:

    (function ($) {
      $(document).on('touchstart', function () {
        documentClick = true;
      });
      $(document).on('touchmove', function () {
        documentClick = false;
      });
      $(document).on('click touchend', function (event) {
        if (event.type == "click") documentClick = true;
        if (documentClick) {
          $('#login-btn').trigger('click');
        }
      });
    })(jQuery);

    Let me know how that goes!
    Thank you,
    Dimitris

  • BBP
    • Design Lord, Child of Thor

    Hi,

    Thanks for the reply. I have tried that yesterday but didn’t work so one of your mates modified that as below,

    (function ($) {
      $(document).ready(function () {
        // get the click event from anywhere, replace '*' with the desired selectors
          $('a, button, input').click(function () {
          // trigger the click event for the Login button, replace '#login-btn' with your login button selector
          $('#user_menu_u .submit_action').trigger('click');
        });
      });
    })(jQuery); 

    URL : https://listings.bbpestatesglobal.co.uk/wp-admin/post.php?post=22357&action=edit

    it did work great on desktop but freezing on mobile.

    further, i have deployed your code u modified few moments ago, again it doesnt work at all, nowhere.

    Please help.

  • BBP
    • Design Lord, Child of Thor

    also i have noticed that this code slows down the site to that extent the Cloudflare shows error of 5084, means it takes more than 100 secs to open the page.

    I have removed that code and waiting for a response from you plz.

  • Dimitris
    • Support Star

    Hello there BBP

    I have tried that yesterday but didn’t work so one of your mates modified that as below

    My code wasn’t based on your website and it was a more generic approach. In order to make it work, you should have changed the trigger of the login button to correspond to the actual login button of your website.
    I’m glad that you’ve made that along with Katya, keep in mind that the code provided by her doesn’t work for clicking anywhere on the screens but in specific elements (a, button, input).

    further, i have deployed your code u modified few moments ago, again it doesnt work at all, nowhere.

    As said, it wasn’t intended to work, as it’s a generic example. Something like this should work though, please give it a try:

    (function ($) {
      $(document).on('touchstart', function () {
        documentClick = true;
      });
      $(document).on('touchmove', function () {
        documentClick = false;
      });
      $(document).on('click touchend', function (event) {
        if (event.type == "click") documentClick = true;
        if (documentClick) {
          $('#user_menu_u .submit_action').trigger('click');
        }
      });
    })(jQuery);

    Again, this snippet is for clicking anywhere on the screen.
    Please let me know if you only need this for the specific elements you used in Katya’s snippet.

    Finally a couple of notes. First, I moved the thread from Members forums to Support forums as it fits more here now, as we’re looking for a specific solution in one of your sites. Also, I noticed some duplicated replies from you, I believe there was a glitch in our system or your end, I took the initiative to remove these so we have a more clear thread. :slight_smile:

    Thank you,
    Dimitris

  • Dimitris
    • Support Star

    That’s strange… can you try to replace it then with the following snippet?

    (function ($) {
      $(document).ready(function () {
        $('a, button, input').on('click touch', (function () {
          $('#user_menu_u .submit_action').trigger('click');
        });
      });
    })(jQuery); 

    If it doesn’t work well, you may try to replace touch with touchstart and check again.

    Warm regards,
    Dimitris

  • Dimitris
    • Support Star

    I had to remove the code cause its resulting the site slowing down and 90% triggering 504 error code on cloudflare

    That’s pretty strange, this snippet shouldn’t be causing such load.

    sorry, but it doesnt work either. please see attached image 7.

    In order to better assist you, can you please grant temporary support access via WPMUDEV Dashboard plugin? No need to share any WP admin credentials, just navigate in WP admin area under WPMU DEV -> Support -> Support Access page and click on the “grant support access” button.

    You can find detailed information about it here:
    https://premium.wpmudev.org/docs/getting-started/getting-support/#chapter-5

    Please do reply back here when access is granted because we don’t get any notifications about it.

    Thank you,
    Dimitris

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.