WP-REST is great tool to connect 3rd party applications to your website and interact with it.
If you want to use it deeply in your website, you need to go to official website and read its handbook.
but what if you just want to use it for some small task and you don’t want to lose more time on reading docs? Then you might need JS code for frontend, and some backend codes for initialization and processing.
In this article i am giving you ready to use snippet, you just put it to your theme’s functions.php and it works.
Of course you will need to change the codes inside response function. In my example i am giving you an example which counts post_views.
Let’s create simple WordPress rest api custom endpoint. Here we go:
If you have several admin accounts, it is usual to see some options, settings changes where there is no any trace to see who has done that any change.
Of course it is not about Post, Page updates, they have some information about who updated the given post object.
But for the rest wp-admin pages there is no such trace collector.
Such kind of data can be useful if you have suspicion that someone you don’t have stolen admin password and logs in to your wp-admin as a wordpress ghost admin. So this snippet might be helpful when you want to stop/prevent wordpress admin panel hack too.
So, let’s write small snippet which will collect, who and when did any activity inside wp-admin.