In your code, get_current_user_id()
will return 0
because this hook fires after the logout has happened, ie, there is no current user ID.
If you want the $user_id
to be available to your function, you have to pass it in. Note: the $user_id
parameter was added in WordPress 5.5.0. If you’re using an older version, this won’t work the way you want.
function update_login_status_on_logout( $user_id ) {
if ($user_id) {
update_user_meta($user_id, 'login_status', 'logged_out');
}
}
add_action('wp_logout', 'update_login_status_on_logout');
References
Related Posts:
- Build a content and excerpt grid loop with paging and options for # of posts
- Why does “get_option” pull in the older value in options.php, rather than the newer value, on submission of a form?
- How to add 2 posts under another post? Formatting should be intact
- Use wp_get_recent_posts with search term
- Remove query string specific key value
- How to prevent WP_Query function from returning all posts when empty?
- Display a specific category of products in shop page and disable code for specific actions
- Get users that likes the post
- Remove echo from shortcode
- Security for data obtained from the database
- WP_Query | IF within $args array | Help me only add specific arguments if the argument is not blank
- change the default order of posts only for specific categories
- Post not populating for custom post type based on category selection
- Custom query vars filters problem with pagination
- How to get post category list as select in front-end?
- Displaying Event within two given time frames
- Let current user know pending posts counts using wp_query
- Output product category link from WP_Query
- Isn’t Returning Value While Using SELECT COUNT(*) FROM {$wpdb->prefix}
- “pre_get_posts” orderby custom date field in different format?
- How to exclude meta no index pages from wp_list_pages
- WP query posts BUT show the most recent and one per author
- Ajax filter with loadmore button
- posts_per_page displays only 2 posts instead of 4 posts
- Delete post meta by serialized meta value
- Modify post image in full size
- WP_Query To Display Product Of Brand On Taxonomy Page
- Custom Post type Ajax search results
- My query keeps looping infinitely ! how to stop it?
- How can I display a query in a page?
- Display Year and Month from custom field + Age Calculator
- insert thumbnail image from php script
- Weird Behaviour: Not all WordPress Posts appearing
- List sibling pages widget, exclude current page
- How to get category pages to look like a certain archive page?
- How to modify this function to exclude also the post belonging to a specific category?
- a problem in class in class-wp-hook.php
- /page/2/ redirect to 404
- Add adjacent post function inside custom recent post function
- Allowed memory size of 268435456 bytes exhausted (tried to allocate 7146491840906359738 bytes)
- How do I get the author’s page url from their ID?
- Dynamically Override Fancy Title – Part II
- How do I know what variables are passed in a filter/action and what their meaning is?
- Wrap each shortcode in array to div
- Warning: array_pop() expects parameter 1 to be array, boolean given
- Check if Product is in a Specific Category in Functions.php
- Adding ads code between comments
- How to Display Image Meta underneath EVERY image in EVERY post
- Limiting woocommerce line_total decimal length
- Can’t search posts using WP_QUERY inside AJAX Function
- Swapping wp_dropdown_categories function with wp_category_checklist
- Display fields as values in array from external SQL DB
- only show container with next/prev links if they exist?
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- JS file work only in index page
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Custom shortcode outputs plain text instead of HTML at top of post
- how can i use $_COOKIE[] + PostID to execute the below code?
- What’s the uses of wp_cache_set() or wp_cache_add()?
- Create Page To Count Comments For Each Post In WordPress Site
- Configuring a meta query with multiple post types that have the same relationship on a single page
- WordPress theme options error
- height should be set to auto to avoid pixelation in the post thumbnail function
- Get posts from multiple post type
- Can i put my shortcode inside a variable in php files?
- Moving code from theme header to functions.php
- Can’t access site after making changes to the functions.php [closed]
- Best way to use a large array in function
- Setting user nickname and displayname to shortened email
- Simple AJAX notification when the new post is added to the database
- Upload multiple files in randomly generated folder using wp_upload_bits
- Personalize checkout text
- Custom route and query
- How do I create a function that modifies a message in the wp-login.php file?
- Adding an interior ‘hero’ area with some added php title customization
- WP_Query() load selected post
- Call to undefined function error in plugin
- How do I correct the code in php? [closed]
- Creating customized php files in theme folder
- Menu not styling. New menus functionality giving me a headache
- Disclaimer that will show every refresh of the page
- Dynamically switch file in get_template_directory_uri() | Function [closed]
- WP_Query for woocommerce products with a pattern as a post_title
- Providin exception to WordPress wp_nav_menu Custom CSS Classes
- Woocommerce My acount page
- Display featured image of post type category
- Child theme overirde template-tags in a theme built on underscores in inc/template-tags
- Menu not updating for logged in users after redirect
- Add parent menu item in sub-menu in custom nav_walker
- Save the outputted image into the Media Library, with a different filename and extension
- Custom Taxonomy as Link
- How to fix blank pagination links?
- allow previews outside wordpress folder (Outsourcing WP previews)
- adsense code showing on random post thumb
- Advanced Taxonomy query, with 3 post types
- How to extend the page editor?
- I need a button to appear when not loged in and another when logged in, I need help fixing code PLEASE!
- How to hide .js files on wordpress website using php or wp plugins or any? [closed]
- How do I display WooCommerce products in my query to rows of 3?