User context in plugin button
I'm working on a plugin that adds a button for each post, in the post-tools section. I'm trying to figure out how I can get the user and post context in my plugin code when this button is clicked, but not sure where to start.
Do you know of a plugin with similar functionality that I can review and see how it was done?
To get the current post, in the context of the button click, use the data-pid selector.
var pid = $(this).closest('[data-pid]').data('pid');
Now for the current user, you would submit a socket or route call with your pid, and check server-side.
For sockets, you get socket.uid https://github.com/NodeBB/NodeBB/blob/8ea5c060f50d1231c3ae3f7cbf5b2fe23ecf51e6/src/socket.io/notifications.js#L10
For routes, you get req.uid https://github.com/NodeBB/NodeBB/blob/54c951cc816b83168083000ae3e08af6c07d4c73/src/controllers/user.js#L12