On a site standard means passes authorization.
If on the page to display <?php echo get_current_user_id() ?> , It will display the authorized user (id)
But if through AJAX:
$.ajax({ url: url, method: 'POST', processData: false, data : $formInfo.serialize(), cache: true, xhrFields: { withCredentials: true }, That returns 0 from the server, i.e. not authorized I tried to enable sending cookies, withCredentials: true , but did not work. How to send an AJAX request from an authorized client.
On the server I created my own plugin for accepting AJAX requests. Already running and authorization, and registration.
register_rest_route('wc/v2', 'users/set-info', array( 'methods' => 'POST', 'callback' => 'pl_user_endpoint_set_info', )); function pl_user_endpoint_set_info($request = null) { $response = array(); $parameters = $request->get_body_params(); $response['response'] = $parameters; $response['message'] = get_current_user_id(); $response['cookie'] = $_COOKIE;//проверка, пришли ли куки return new WP_REST_Response($response, 200); }
Plugin registered to action rest_api_init
add_action('rest_api_init', 'pl_wp_rest_endpoints'); The code is sent to the client from the form, but I have not yet processed the parameters, I would first need to know how to do this, so that the server would understand that the client is authorized.
