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
- PHP code in page template vs functions
- How to preserve PHP modifications while upgrading WordPress?
- Shortcode created to check language not works
- Best way of adding CSS which can be manipulated by the user via theme option panels?
- How to Append to the_excerpt() Function
- Listing all sub-pages?
- Why do filters/actions require an argument count?
- there’s a way to include a minimal WP for check only the current user, its roles (caps?) and then release/free it?
- Delete option value from array using update_option()
- Recent post display using shortcode
- syntax issue on php 7.4
- How can I use wp_insert_comment to write a comment when a post is edited?
- How to remove the excerpt in the Dzonia Lite theme
- How to get a list of all possible values of a specific user meta key?
- How do you add customer capability after Woocommerce purchase?
- Get first URL from post content
- functions.php is being included twice, creating PHP fatal errors
- Hide Hamburger Menu On Specific Page (Front Page/Home Page)
- How to put a variable in a instance in the widget
- get a simple array of all of the term names that exist in all taxonomies
- Logged in user ID as post ID
- Show categories then when clicked on a category list all sub category and when clicked show all posts in that sub category
- How to store data from multiple forms using ajax and php
- How to control WordPress image metadata (using Imagick)?
- 3 Slashes appear after Apostrophe in custom fields after updating product-site
- Trying to retrieve post meta
- Error call_user_func_array() expects parameter 1 to be a valid callback when using image_size_names_choose
- Change CSS based on is_user_logged_in
- Run a code only on theme activation only during first activation
- Shortcode from a function not working
- Is it possible to return content, and then also continue to do other things?
- Creating WordPress Shortcode with Variable
- Add meta tags to a custom header
- How to use mysql LIKE with wpdb?
- woocommerce related product title length
- Query for user roles
- Displaying Event within two given time frames
- How to prevent a function from running based on host (ie web vs local)?
- How to call custom function outside from the admin page?
- Is there a way to create a “copy post” link?
- Reject all malicious URL requests functions.php
- Apply function.php filter only if url not has /amp/
- Preventing direct access to a page in WordPress
- How to use data URL in WordPress?
- Flushing the slug base has no effect and does not change
- Uploading/integrating custom user registration page
- Multiple cron jobs vs daily cron job doing multiple things? Which one yields better performance and scalability?
- JQuery modal not loading video on popup, only displaying it after multiple reopenings
- Get user by meta data key and velue
- Logo custom width not implementing
- custom post type column countdown
- Using wordpress functions in class and change my code to OOP PHP
- Creating wordpress user registration form
- Add missing alt tag to featured images for “storefront” theme
- Notice: Undefined index: post_title error
- Unable to pass arguments to function used in add_action
- What is the proper way to call a function (from functions.php) on a link click?
- Load admin bar without wp_head or wp_footer [duplicate]
- Allow user to select location and then set cookie for location in WordPress
- Highlight Single Page Ancestor
- Registration form not registering First and Last name
- Removing get_template_part in child theme
- How to ‘remember’ a site member’s last visited page?
- How to connect database table to each registered wordpress user.
- Merge / Combine two php functions for Previous and Next Link with Thumbnail
- str_replace not responding in functions.php [closed]
- Change default comments form title [duplicate]
- How to get the rating value of each comment
- Adding php within a return statement [closed]
- Displaying categories
- Error in php code
- Check if username doesn’t exists
- Replace the image of a product with its video in the shop page
- Show div only if product has attribute
- Is there a hook that I can use when a fatal error occurs?