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
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();
Β Β Β Β Β Β Β Β Β Β Β });
Β Β Β Β Β Β Β }
Β Β Β });
Thank Admin very much. It worked as expected, Wpdiscuz is a great plugin. Admin is also great
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.