You’re running your code on the wp_loguout
hook, which is after the user has logged out, so of course there’s no current user ID. There’s no current user at all.
If you look at the documentation for the wp_logout
hook, you will see that the ID of the user that was logged out is passed to any hooked functions. You need to use that if you want the logged out user’s ID:
function do_anything( $user_id ) {
// $user_id is now the logged out user's ID.
}
add_action( 'wp_logout', 'do_anything' );
Also, you really should not be creating a new connection to the database and using SQL if you want to update user meta. You should be using the proper function, update_user_meta()
:
function do_anything( $user_id ) {
update_user_meta( $user_id, 'alg_wc_ev_is_activated', '0' );
// etc.
}
add_action( 'wp_logout', 'do_anything' );
Related Posts:
- main menu page redirects to user ID
- Create a global variable for use in all templates
- Can i check if user is doing any ajax request?
- How can I default to all WordPress roles when parameter is not included in shortcode?
- get_users(…) only returns one user
- Get users that likes the post
- Call to undefined function get_userdata() in plugin
- Use post ID in functions.php file adminside
- create front-end users post list by specific category
- php return username of currently viewed author profile
- Use of antispambot with $curauth->email
- Uses for function: wp_update_user
- Change wordpress’ database data using ajax – how to get current user id?
- Allow a user or role to view drafts and previews, but not other admin privileges?
- How to block specific user id in custom login form?
- Display current user metadata on WordPress page
- Add another role to a user when they click a button?
- is_user_logged_in() not working in homepage
- Can’t get_users info by using json_encode
- Matching multi user
- Private messaging – Getting and displaying the avatar/url of a message recipient
- Get author meta of all writers
- Display a list of users with avatar filterable with alphabets
- Cross origin ajax request always returns 0 when calling get_current_user_id();
- Custom Admin Menu Report for Specific User ID
- Hide ID for WordPress User Role Subscriber
- Image media upload metabox
- User’s total comment count excluding comments on their own posts
- How to remove the cufon script from Dzonia Lite theme [closed]
- How to remove or change the “W” icon in “My Sites”?
- get a simple array of all of the term names that exist in all taxonomies
- Login/logout in header
- How to display posts by current user in a drop down
- Logged in user ID as post ID
- How does WordPress insert Paragraphs in posts
- WordPress Access allowed to fewer pages till user logs in
- Linking text within textarea of custom meta box
- User management system similar to wordpress one?
- Show css depending on activity type in BuddyPress activity-loop [closed]
- only show container with next/prev links if they exist?
- How to combine wordpress_logged_in cookies in one cookie?
- Populate dropdown with Child Pages based on Parent Page chosen
- Show all posts by author
- How can I remove a function that has been added to wordpress with add_filter?
- Change the WP Video Shortcode Output
- Show categories then when clicked on a category list all sub category and when clicked show all posts in that sub category
- remove wp floating submenu in wp dashboard
- How to put “Read more” link in Custom Excerpt inside p tag?
- Two Different Links for Same Product – WooCommerce [closed]
- ACF: how do I get the fields and its values of a specific group?
- How to store data from multiple forms using ajax and php
- How to control WordPress image metadata (using Imagick)?
- How to add seperate classes to no-search-result and found-search-result pages on wordrpess search – is_search()
- Get value from shortcode to do something
- PHP 8, AJAX mail form to function.php doesn’t work
- How do I add custom bulk actions to multiple custom post types?
- Error when adding excerpt to the content through functions.php
- Automatically adding new post categories to menu
- Add data attribute to each li in menu
- Get post id in a function when edit/add a post
- Making BuddyPress Activity Stream (Post Type) Featured Images Clickable [closed]
- How to check if a meta value has already been assigned to any user?
- Custom user login page by creating a plugin
- How to complete two other input fields, completed the first
- Prev/Next child navigation for current page modifications?
- Adding rel tag to all external links
- How can I apply_filters from inside a function?
- function to assign user role based on a field from usermeta
- what is the best practice to add new field to an api route
- Retrieve $_POST data submitted from external URL in WordPress(NOT API)
- Programmatic Login from 3rd Party site
- Pass Category Name, Description and Photo into variables to pass to jQuery
- Use DOMDocument with ob_start breaks my HTML code
- Auto-update products after they were published – Woocommerce
- How to prevent WP_Query function from returning all posts when empty?
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- JS file work only in index page
- Display a specific category of products in shop page and disable code for specific actions
- Woocommerce related product text
- esc_html_e() is not translating string in wordpress [closed]
- Removing “wpautop” (auto tags) only on certain pages?
- Fatal error: Uncaught Error: Call to undefined function test()
- How to pick the default selected value in wordpress dropdown?
- Using WP-API and SSE not authenticating user ID
- Woocommerce: hook action/filter I could use to add variation id and price with each attribute opt on WooCommerce Rest api
- Validate functions before inserting then into functions.php
- How to retrieve current wordpress profile page URL?
- Firing schema via code in functions.php doesn’t work
- A non-numeric value encountered in /wp-includes/functions.php on line 68
- Get page that displays all children of taxonomy parent
- Ajax request not sending to server and returning – wp-admin/admin-ajax.php 400
- get author_name from queried post
- Add New User, extra fields which are required?
- Why ajax doesn’t work on certain wordpress hooks?
- Is it possible to intercept all ajax requests and get the parameters and the returns?
- How to call plugin function per site in a multisite?
- Print last modified date only on posts
- different id for same element visual composer [closed]
- user_profile_update_errors hook not executing
- WooCommerce: How can I get orders with a custom ID in order meta data object?