I have a Wordpress site and I have a client side vanilla JavaScript app (context for the app, it's basically a small drawing app which shapes appear on the screen and the user must draw within the shapes. Afterwards the canvas is saved as a JPEG and saved on a server)
Using the method described with some tweaking
https://dev.to/stevewhitmore/take-your-wordpress-site-further-with-vue-js-179n
I made the client side vanilla JS app into a plugin, loaded it to a page and it works.
In order to see this page the user must be logged in to my Wordpress site. The next step for my app is to see which user is logged in and using the app, so I can send the user's info (name and id) alongside the saved JPEG to my server. What I am imagining is, when the app launched I do a GET request somewhere and get it? Or are there many many many more steps in between?
What I am expecting is when the app launches the user info is "grabbed" with a GET request?
CodePudding user response:
There are two ways of doing it.
- If you want to do it within your JS app (meaning in Javascript context), then you can send a get request to WP REST API (https://developer.wordpress.org/rest-api/reference/users/#definition-example-request-2), and it will return you the logged-in user info in JSON format.
- Since you've developed this JS app, so you must be enqueuing the JS file somewhere inside your php code by using wp_enqueue_script function. So inside your code after enqueuing the JS file, you can use wp_loaclize_script function, and send some addtional data (User info) to your JS file, and then you can use that info in your JS app.
I hope this will yield you your desired result.