Paid Addons Support Forum Only

Please note, that here we only support Paid Addons issues and questions.

gVectors Support staff works from 6am to 6pm (GMT+0)

All questions related to wpForo and wpDiscuz free plugins should be asked in the corresponding plugin support forum:

 

wpDiscuz Support Forum   wpForo Support Forum

Logout with JS - Wpdiscuz  

  RSS

levanhieu
(@levanhieu)
New Member
Joined: 7 months ago
Posts: 3
05/11/2019 2:39 am  

Hi Admin, I have a question that wants help.
I am using Wpdiscuz and allow users to login from social networks. By default, logout will easily see the logout link. For security, I created a button and processed it using Javascript. However, I cannot get the logout link. That's the problem.
I processed in /wpdiscuz/assets/js/wpdiscuz.js and added:
// ============================== LOGOUT FUNCTION ================ == //
$ (document) .delegate ('. wpdiscuz-log', 'click', function () {
     if (isUserLoggedIn){
     location.href = "<? php echo wp_loginout (get_permalink (), false)?>";
     }
});
Looking forward to the help. Thanks very much

This topic was modified 7 months ago by levanhieu

Quote
Topic Tags
Elvina
(@elvina)
Noble Member Moderator
Joined: 9 months ago
Posts: 1046
05/11/2019 12:11 pm  

Hi @levanhieu,

This is working partly. The PHP code added by you in js file doesn't work correctly.

To get it resolved, please follow the steps below:

1. Delete all your previous changes.

2. Add the following JS code in the plugin js files.

add_action('wp_ajax_wpdLogout', function () {
   $user = wp_get_current_user();
   if ($user->ID) {
       wp_logout();
   }
});

Important: the changes will be lost after wpdiscuz update. You should keep somewhere locally the code.

2. PHP code should be added in the  active theme functions.php file:

$(document).delegate('.wpdiscuz-log', 'click', function () {
       if (isUserLoggedIn) {
           $.ajax({
               type: 'POST',
               url: wpdiscuzAjaxObj.url,
               data: {
                   action: 'wpdLogout'
               },
           }).done(function () {
               location.reload();
           });
       }
   });

ReplyQuote
levanhieu
(@levanhieu)
New Member
Joined: 7 months ago
Posts: 3
05/11/2019 7:06 pm  

Thank Admin very much. It worked as expected, Wpdiscuz is a great plugin. Admin is also great


ReplyQuote
Elvina
(@elvina)
Noble Member Moderator
Joined: 9 months ago
Posts: 1046
05/11/2019 8:30 pm  

We'd really appreciate and be thankful if you leave a good review on plugin page. This is the best way to say thank you to this project and support team.


ReplyQuote
Share: