I want to write PHP script (standalone) for comment approval.
Objective:
I use Aksimet for comment filtering. After Akismet’s filtering, few comments get passed and come to my email for approval. I will get comment ID from there and pass it to the script in get parameter (manually).
This way I do not need to login to WP every time. The script will just approve comment so there is not much risk or harm. If script works then It will take less time and I can approve comment any time even from office.
I tried setting the moderation bit in MySQL directly to see if it works or not! The answer is yes and no. It approves the comment but it does not refresh the post. So, my cache show post without new comment. I use Super cache plugin.
The challenge is to write script OUTSIDE of WP environment. So, that I can access the script without Admin login.
Please suggest trick for this and how to start for this.
I spent a little time and got this working. The key is that you can use the WP API in your script by including wp-load.php.
I have tested this below and it works in my WordPress. It uses GET parameters ‘commentid’ and ‘status’. I leave it to you to extend, test for error conditions, provide appropriate security mechanisms, etc.
And here is the usage for wp_set_comment_status, from the source code:
Also, so those who are curious know how I went about solving this… basically I checked the /wp-includes/ directory of WP to see if there were any comment related files. There is a file called comment.php in there, which has most, if not all, of the main comment manipulation functions that the wordpress API uses.