Struggle to get get_current_user_id() in wordpress [closed]
Struggle to get get_current_user_id() in wordpress [closed]
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 days ago.
Improve this question
enter image description here
I am trying to get the user ID of the currently logged in user when save the coupon data to database. However, i am getting user id = 0. my error_log also shows that user is not logged in. I am making my own plugin and the code snipper is in my plugin's main php file. I am also using Astra Theme and Ultimate Member plguin
Clear cookies and cache data
You can try this code to get current user:
global $current_user;
$user_id = $current_user->ID;
or
global $current_user;
$user_id = get_current_user_id();
Or use this WordPress function
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
December 30, 2023
Turbo Multi-language Translator
Make the better internet purchasing globaly
Turbosify SEO Speed Booster
5.0 (7)•Free plan available
Get better conversions by improving store loading speed
Installed
Turbo Multi-language Chat - AI Customer service in one hand
December 30, 2023