I have a custom form in WordPress. A JavaScript (angularjs) posts the form to the admin area when the admin is logged in. How can this script call get current user id? The form is accessible only when admin user logs in.
It is always returning 0.
I have a custom form in WordPress. A JavaScript (angularjs) posts the form to the admin area when the admin is logged in. How can this script call get current user id? The form is accessible only when admin user logs in.
It is always returning 0.
You should be using the following action, which will allow calls to the function
current_user_id.You could also just pass the user ID to the script using the
wp_localize_scriptfunction from your themes enqueue scripts action.