Hot answers tagged

30

This happens because you are missing the neccessary nonce in the URL, which is being checked in wp-login.php case 'logout' : check_admin_referer('log-out'); ... Use wp_logout_url in order to retreive the URL including the nonce. If you want to redirect to a custom URL, simply pass it as an argument. <a href="<?php echo wp_logout_url('/...


22

You just need to add your filter hook like this: function myplugin_cookie_expiration( $expiration, $user_id, $remember ) { return $remember ? $expiration : 600; } add_filter( 'auth_cookie_expiration', 'myplugin_cookie_expiration', 99, 3 ); You can add it to your theme’s functions.php file.


15

If you can't use wp_logout_url() function, You can turn off this validation using this code: add_action('check_admin_referer', 'logout_without_confirm', 10, 2); function logout_without_confirm($action, $result) { /** * Allow logout without confirmation */ if ($action == "log-out" && !isset($_GET['_wpnonce'])) { $redirect_to ...


14

OK, simple solution after digging in the WordPress code. // get all sessions for user with ID $user_id $sessions = WP_Session_Tokens::get_instance($user_id); // we have got the sessions, destroy them all! $sessions->destroy_all(); This will log the user with ID $user_id out of WordPress. Use case: My use case for this is when a user is approved ...


8

Using this code in the functions.php does the trick: function wpse_44020_logout_redirect( $logouturl, $redir ) { return $logouturl . '&amp;redirect_to=' . get_permalink(); } add_filter( 'logout_url', 'wpse_44020_logout_redirect', 10, 2 ); Note - The above code works only on non-admin pages. To make this work on any page you should replace: return $...


5

Replacing just the URL is not enough. You have to tell WordPress what to do with the new URL. Sample code, creates a log-out URL like example.com/logout=1 and redirects to front page or custom URL after logging the user out: add_filter( 'logout_url', 't5_custom_logout_url', 10, 2 ); add_action( 'wp_loaded', 't5_custom_logout_action' ); /** * Replace ...


5

You can try below code. It won't log you out after changing password. $userdata['ID'] = 1; //user ID $userdata['user_pass'] = 'new_password'; wp_update_user( $userdata ); Enjoy ;)


4

If you only want to modify logout and not login, then use wp_logout_url(). Conversely you can use wp_login_url() for just the login URL. Example of an logout link: <a href="<?php echo wp_logout_url( home_url() ); ?>" title="Logout">Logout</a> You can still use the function wp_loginout() but the redirect will work on both login and out. ...


4

You can filter 'logout_url' and return a custom value if you are in the admin area: add_filter( 'logout_url', 'wpse_58453_logout_url' ); function wpse_58453_logout_url( $default ) { // set your URL here return is_admin() ? 'http://example.com/custom' : $default; }


4

You also need to define a matching COOKIEHASH for both sites - a random 32 bit string will do. By default, COOKIEHASH is an MD5 hash of the site URL, and is used to generate the default names for all authentication-related cookies. Hence why, at the moment, your cross-domain login isn't working (the names of the cookies aren't consistent, as COOKIEHASH will ...


4

Take a look at the source: 832 if ( $remember ) { 833 /** 834 * Filter the duration of the authentication cookie expiration period. 835 * 836 * @since 2.8.0 837 * 838 * @param int $length Duration of the expiration period in seconds. 839 ...


4

Add submenu with a custom link, /wp-login?action=logout, like the image below: Add code like below in functions.php: function wpa_remove_menu_item( $items, $menu, $args ) { if ( is_admin() || ! is_user_logged_in() ) return $items; foreach ( $items as $key => $item ) { if ( 'Login / Register' == $item->title ) ...


4

That button sends an AJAX request that runs wp_ajax_destroy_sessions(). It's not really abstracted in such a way that you can re-use it outside of AJAX, but if you copy the source into your own function, minus the JSON parts, then you could perform the same action yourself. The key part is this bit, which will destroy all sessions for a given user ID: $...


3

You can use the wp_logout_url() template tag to generate a logout link. You can specify the URL that the user will be redirected to as the first pramiter: wp_logout_url( 'http://example.com' ); The above code will generate a URL that looks a bit like this: /wp-login.php?action=logout&_wpnonce=ba51bbcdc3&redirect_to=http://example.com/unsubscribe. ...


3

If you create a custom link in your menu, set the label to “Logout”, and set the URL to http://yourdomain.com/wp-login.php?action=logout. Then add this function to your functions.php file: function change_menu($items){ foreach($items as $item){ if( $item->title == "Logout"){ $item->url = $item->url . "&_wpnonce=" . ...


3

This really does belong in a plugin, but you can just as easily drop it in your theme's functions.php function default_login_redirect( $redirect, $request_redirect ) { if ( $request_redirect === '' ) $redirect = home_url(); return $redirect; } add_filter( 'login_redirect', 'default_login_redirect', 10, 2 );


3

Here's how I managed to set it up for one client. The code (which should go into the theme's functions.php) assumes there's an existing menu item titled 'Login'. Works fine but may not be the best way, so critique is welcome. function wpse0520_modify_login_menu_item( $item ) { if(isset($item->title)){ if( $item->title =='Login' ) { ...


3

I asked on the WordPress MU Domain Mapping plugin support page and it turns out it was a setting in the plugin that needed to be turned off. I turned off Redirect administration pages to site's original domain and it's working now. Thanks for your ideas and help!


3

this string is displayed when you get a nonce mismatch, something that should not happen much under normal usage. If it does haen enough to make you aware to it then you should investigate the cause. Anyway, no easy filter for that string so you will have to use the translation api to replace it. add_filter ( 'gettext', 'wpse_120304', 10, 3 ); function ...


3

This happens because of a missing nonce parameter in the URL. Every WordPress action, including login/logout, validates the nonce first, to make sure the request comes from a known source.


3

If you are changing the password for the current logged-in user, it will log you out. You have to log in again: // Get current logged-in user. $user = wp_get_current_user(); // Change password. wp_set_password($new_password, $user->ID); // Log-in again. wp_set_auth_cookie($user->ID); wp_set_current_user($user->ID); do_action('wp_login', $user->...


3

This allows for the message to be overwritten specifically for the loggedout message while leaving all other messages alone. Here is more documentation on the filter. add_filter( 'wp_login_errors', 'my_logout_message' ); function my_logout_message( $errors ){ if ( isset( $errors->errors['loggedout'] ) ){ $errors->errors['loggedout'][0] = ...


2

Have a look here - http://codex.wordpress.org/Function_Reference/wp_logout_url Easy as adding this: <a href="<?php echo wp_logout_url( get_permalink() ); ?>" title="Logout">Logout</a>


2

Use the following to display Register/Site Admin & Log in/Log out link in menu: add_filter('wp_nav_menu_items','show_register_login_link'); function show_register_login_link($nav) { // The "Register" link is not offered if the Administration > Settings > General > Membership: Anyone can register box is not checked. return $nav....


2

This message is raised by wp_nonce_ays() which is called by check_admin_referer(). Your browser has probably not sent a referer header, so WordPress could not validate the nonce. This may be a problem in your browser settings or your network connection.


2

I discovered the Hikari Hooks Troubleshooter (http://hikari.ws/hooks-troubleshooter/) this weekend to find what plugins were loading my header with competing open graph metadata. Enable it, and visit the frontend. There will be a modal dialog over your site which should list the hooks into wp_logout. One of these will be the offending plugin. If you're ...


2

Pontus Abrahamsson is right, that is a legal code, but here is another one that I'm using in my theme. <a href="<?php echo wp_logout_url('$index.php'); ?>">Logout</a>


2

The wp_logout function will log a user out. Here's an example that will log someone out and redirect to the login page when the url contains the query string ?my_logout_flag: add_action('init', 'wpse52743_check_logout'); function wpse52743_check_logout(){ if( isset( $_GET['my_logout_flag'] ) ) { wp_logout(); wp_redirect( wp_login_url() )...


2

It's not clear, but I'm assuming you want a 'log out' url, that brings the user back to the current page? get_permalink() however, get's the permalink of the current post in the loop (if you're using it outside the loop, you'll find that it takes the user to the last post in the loop after they log out). To get the url of whatever page you're currently ...


2

Try using wp_loginout(). It automatically handles those conditions.


Only top voted, non community-wiki answers of a minimum length are eligible