How to Logout user after resetting the password - wordpress

I want my user to logout after they reset their password from my account page.
I have tried to reset cookies, tried wp-logout method.. It worked for few tests I have done then again, it's not working..

You can try by redirecting the user to the logout page link if their password reset is successful using
wp_redirect ()

After trying so many ways to do this, finally changed in "class-wc-form-handler.php" file in woocommerce plugin under "includes" folder. Or you can also override this in your functions.php Under "public static function save_account_details()" use wp_logout(); before "wp_safe_redirect( wc_get_page_permalink( 'myaccount' ) );"

Related

wp_login and is_user_logged_in

I am developing an extension for a plugin and would like to run some code after every time a user logs in. Because I extend a plugin, I wanted to use the already written functions, which inside use is_user_logged_in() calls. If I register for the wp_login action and run is_user_logged_in in my action hook it returns false, which sounds really weird.
Code I was running:
add_action('wp_login', 'exhib_persist_cookies_after_login');
/*
* This method will persist the favorite posts from the cookies just after someone logs in.
*/
function exhib_persist_cookies_after_login() {
//Check if all the required functions are available
if (is_user_logged_in()) {
error_log("persist: USER LOGGED IN");
}
else {
error_log("persist: USER NOT LOGGED IN");
}
}
And in the log I see USER NOT LOGGED IN.
Anyone has a clue why is it happening? I thought is_user_logged_in is checking for the auth cookie, which is according to the doc is already set before wp_login is getting called.
Or anyone has an another idea what action should I register, which only fires once a user logged in and the is_user_logged_in returns there true?
Before you even look at why the modification isn't working, you should think about changing how you're modifying the plugin. Directly modifying a plugin is dangerous. It breaks the upgrade path preventing you from applying upgrades in the future which could resolve critical issues with the plugin itself. The same functionality could be achieved by creating a simple plugin that contains nothing but the code you want to run.

Wordpress Delete User after Success

I have a form we want users to access only once, anonymously. We hand out randomly generated usernames and passwords to allow anonymity. I would like to delete user, log off and redirect after successful submission.
I am able to delete the user with wp_delete_user($thisId); but alwyas have a "Cannot modify header information - headers already sent" error. I'm not sure how to approach this one.
I am processing in header.php
If you process in header.php it's too late because the server is already sending the page.
Try hooking your "delete_user" function in a previous action such as init or wp like this (in functions.php):
add_action('init', 'my_delete_user_process');
function my_delete_user_process(){
// Do your stuff
$user_id = get_current_user_id()
wp_delete_user($user_id);
// Do your stuff
}

How to keep Wordpress logged in permanently

I'm trying to use WordPress as a website CMS for a kiosk. Each kiosk needs a unique username therefore it must be logged in to WordPress.
I believe WordPress does not use Session ID's therefore how can I ensure the user is never logged out of the site even after X days of inactivity?
Thanks in advance.
How about just simply using the auth_cookie_expiration filter
add_filter('auth_cookie_expiration', function(){
return YEAR_IN_SECONDS * 2;
});
There seems to be mixed accepted answers. First, you should never modify the wordpress core code. Ever. Secondly, per the wordpress developer codex, the "auth_cookie_expiration" filter is what needs to be used here.
add_filter ( 'auth_cookie_expiration', 'wpdev_login_session' );
function wpdev_login_session( $expire ) { // Set login session limit in seconds
return YEAR_IN_SECONDS;
// return MONTH_IN_SECONDS;
// return DAY_IN_SECONDS;
// return HOUR_IN_SECONDS;
}
I've actually created a plugin to deal with this very issue. It uses the idea of persistent login to actually keep users logged into your wordpress website all the time, kind of link how Facebook does it.
Check it out, hope it helps!
WP Persistent Login
You can try configuring the session time for Wordpress. Unfortunately, Wordpress doesn't allow you to easily manipulated this.
You can try out this plugin: http://wordpress.org/extend/plugins/configure-login-timeout/
You can use the plugin "WP Login Timeout Settings" to achieve this. Under "Settings → Login timeout", it then allows you to configure the login timeout for both a normal login and one with the "Remember Me" box ticked.
That's just the same as what the "configure-login-timeout" plugin does, which was already recommended. Just that "WP Login Timeout Settings" seems to be a bit more actively maintained at the moment.

Problems with logout if without session in wordpress

I implement the facebook in my wordpress website and everything is working ok except one situation.
If I logout from facebook, and then I click logout in website, I get the error:
FB.logout() called without an access token.
So I replace the logout code with this:
return javascript:if(FB.getAccessToken()){FB.logout(function(){location.href='" . $url . "'})}else{location.href='" . $url . "'}";
(This is done in a wordpress hook, so that I can have the wordpress logout url)
But now, when I click logout in this situation I get a js error:
Unsafe JavaScript attempt to access frame...
How can I be able to logout safely from facebook and wordpress.
FB.Logout doesn't have an error callback and doesn't throw any js error, so it's difficult to check that situation.
Thank you!
You need to get the login status first from Facebook, and only if logged in can you call FB.logout. Try the following code.
FB.getLoginStatus(handleSessionResponse);
function handleSessionResponse(response) {
//if we dont have a session (which means the user has been logged out, redirect the user)
if (!response.authResponse) {
return;
}
//if we do have a non-null response.session, call FB.logout(),
//the JS method will log the user out of Facebook and remove any authorization cookies
FB.logout(response.authResponse);
}

Wordpress Contact Form plugin stuck loading forever when sending a form

In this page, I'm using the Contact Form 7 plug in (at the very bottom).
When I fill the form and press send the form stay loading forever.
Any suggestions?
code:
<p>您的姓名 〈需填寫〉<br />
[text* your-name] </p>
<p>您的電子郵件信箱 〈需填寫〉<br />
[email* your-email] </p>
<p>主旨<br />
[text your-subject] </p>
<p>您的信件內容<br />
[textarea your-message] </p>
<p>[submit "傳送"]</p>
(there's isn't really too much code since is a Wordpress plugin).
I'm using Wordpress 3.0.1 and Contact Form 7 (3.3.1)
Step:1
Go to ftp:
wp-content/plugins/contact-form-7/contact-form-7.php
In contact-form-7.php
Step:2
Find:
if ( ! defined( 'WPCF7_LOAD_JS' ) )
define( 'WPCF7_LOAD_JS', true);
Replace:
if ( ! defined( 'WPCF7_LOAD_JS' ) )
define( 'WPCF7_LOAD_JS', false );
upload your file and Try it done.
Try another contact form plugin to see if you can send any email at all. Check your webhost error logs for php errors.
Use the developer tools in your browser to check for Javascript errors. Contact Form 7 uses javascript for some of the form processing, and you may have a Javascript conflict.
The issue might be a server problem. Ask your webhost if there are issues using php mail. Try sending an email manually using php mail; see How to send an email using PHP?
Also, try WordPress › WP Mail SMTP « WordPress Plugins which allows you to test send email via SMTP and will show a log of server actions and which will let you possibly find the issues.
Since I don't want to edit any plugin files I went with the filter options:
// WPC7 forms were not submitting, this fixes that
add_filter( 'wpcf7_verify_nonce', '__return_true' );
add_filter( 'wpcf7_load_js', '__return_false' );
It might be conflict with other plugins, like another contact form? In my case I was using MMForms-Community and Contact Form 7 is the reason.. So in other words, I can not use both as they conflict with each other from WP version 3.0 and up.
Editing contact-form-7.php as mentioned above helped but my emails would not arrive in my inbox, but they were in my sent box.
Similar to my configuration:
Google Cloud for hosting WordPress (WP)
Google’s G Suite for email (smtp.gmail.com)
Contact Form 7 - WP Plugin
Postman SMTP - WP Plugin
Main email - John-Doe#example.com
Alias email - info#example.com
I was able to get the emails to my inbox by using the main-email account in the From location in Postman SMTP instead of the gmail alias because the main was needed for authentication.
Worked: From: John-Doe#example.com To: info#example.com
Did not work: From: info#example.com To: info#example.com
The text below is from the chat session with Google’s Support.
The reason why you have to use a different domain is because the web forms get confused and try to deliver the email at your web host rather than your mail host, they see your domain in the recipient and say "hey this is the same domain where the site is hosted at, it should be the same, lets save some effort looking at the domain’s MX records and lets leave it right here".
The From: field needs to be your primary email address since it requires authentication (aliases can’t authenticate), the TO: field has to be preferably an email not from your domain name, like the test alias example.com.test-google-a.com.
If you are sending it from a website is different, the behavior when it gets dropped is just when you use Gmail web mail or a mail client. For web forms, send the emails to the aliases from the test example.com.consulting.test-google-a.com.
I want to add to VijaiJerald's answer. That particular solution didn't work for me, but it did work when I changed as he proposed:
if ( ! defined( 'WPCF7_LOAD_JS' ) ) {
define( 'WPCF7_LOAD_JS', true);
}
Replace with:
if ( ! defined( 'WPCF7_LOAD_JS' ) ) {
define( 'WPCF7_LOAD_JS', false );
}
But also the following line:
if ( ! defined( 'WPCF7_VERIFY_NONCE' ) ) {
define( 'WPCF7_VERIFY_NONCE', false);
}
Replace with:
if ( ! defined( 'WPCF7_VERIFY_NONCE' ) ) {
define( 'WPCF7_VERIFY_NONCE', true );
}
I also want to note that literally no other solution worked for me (disabling all plugins, changing the WP_DEBUG value, resetting the browser, reinstalling Wordpress, updating and upgrading all plugins, disabling all custom CSS and JavaScripts, etc...) so this might help people that have this issue. I also want to note that while it wasn't working on my laptop (tried multiple browsers), I didn't had this issue on my phone at all.
Usually infinite loading is caused by a problem in your theme. You can overwrite the style/code of Contact Form 7 with javascript and a piece of css.
You can solve this problem with the following piece of javascript:
document.addEventListener( 'wpcf7submit', function( event ) {
jQuery('head').append('<style type="text/css">.aw-no-spinner:before{display:none!important}</style>');
jQuery('body').find('.processing').addClass('aw-no-spinner');
}, false );
jQuery('.wpcf7-submit').on('click', function( event ) {
jQuery('body').find('.processing').removeClass('aw-no-spinner');
});
In this example we use the built-in hook of contact form 7: wpcf7submit
When this event is fired then our piece of code is executed. This piece of code adds an extra class to the loading wrapper of contact form 7. And also we add a piece of css to the head so we don't have to put this in a separate CSS file.
We have also incorporated this solution into a WordPress plugin for users who prefer not to add code to their website or do not have a child theme.
This is the link to the plugin, but you can also use the piece of code described above.
https://wordpress.org/plugins/awcf7-stop-spinning/

Resources