Title: Modify WP database via standalone script
Last modified: August 19, 2016

---

# Modify WP database via standalone script

 *  [greenalien](https://wordpress.org/support/users/greenalien/)
 * (@greenalien)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/modify-wp-database-via-standalone-script/)
 * I want to add a standalone php script on my server which modifies the WordPress
   database. This script would be called directly from an external system.
 * For example if I wanted to approve any comment made by user “Steve_Jobs”, I could
   look this up in the wp_comments table and set the comment_approved field to “
   1”.
 * That may or may not work. Looking at the wp_set_comment_status function in comment.
   php I doubt it would work. That function does the same UPDATE sql statement I
   would of done, but it does other stuff like clean the comment cache and update
   the comment count.
 * So calling wp_set_comment_status() to do the job might be better than messing
   with the database directly. I see the function depends on other things in the
   WordPress setup like the global $wpdb object and other functions. Which WordPress
   files do I need to include in my standalone script to keep things happy? i.e.
   which “require_once” statements do i need in order to make use of WordPress functions
   in a standalone script?
 * Not sure if I should be doing this as a WordPress plugin instead, because I’m
   not integrating anything into the blog as such. Nothing is being displayed in
   the blog theme and there’s no user interaction. It’s just a standalone script
   invoked by an external system.
 * What I’m actually trying to do is only allow valid usernames to post comments.
   Integration is tricky because my WordPress blog can’t access the user database
   of the external system. So the best I can do is get the external system to call
   a webpage (supplying any info needed) which validates the feedback.
 * One way could involve the following steps:
 * 1) User visits blog and submits feedback. They are asked to enter the same username
   which they use in the external system (no way to verify this at this stage).
 * 2) When the blog page refreshes, instead of saying “Your comment is awaiting 
   moderation” next to their feedback, it asks them to click something in the external
   system to activate their feedback.
 * 3) They click something in the external system which then automatically calls
   my php script. For example it would load myserver.com/verify_feedback.php?user
   =Steve_Jobs
 * 4) The php script looks up Steve_Jobs in the wp_comments table and sets comment_approved
   to “1”. Or more ideally calls wp_set_comment_status() to update this field instead.
 * Actually even better (And I’m a WordPress noob so not sure if its possible) would
   be the following…
 * 1) User visits blog via external system, and their valid username is passed at
   the same time. So I could add a stub/redirect page (or hack the WordPress file/
   theme) which takes the username from the URL and automatically registers them
   as a user of my WordPress blog. I would add extra info to the URL like a hash
   to prevent hacking. A WordPress cookie is stored, and they can freely leave blog
   comments with no comment verification needed. But I’m not sure if/how users are
   handled in WordPress. I see no “sign up” link for example. So I’m thinking the
   only users WordPress handles are admin?
 * By the way, the “external system” i refer to is some game software. Within the
   game its possible to both 1) load a webpage in the users default browser, and
   also 2) call a webpage directly (without user intervention and even without them
   knowing). In my first scenario I’d be making use of both those features. I only
   want registered users of the game software to be able to leave comments in my
   blog.
 * Thanks for any feedback/suggestions.

Viewing 1 replies (of 1 total)

 *  [haochi](https://wordpress.org/support/users/haochi/)
 * (@haochi)
 * [18 years, 1 month ago](https://wordpress.org/support/topic/modify-wp-database-via-standalone-script/#post-763373)
 * Cliff notes please.
 * Including wp-config.php should be enough, test it yourself.
 *     ```
       <?php
       include('wp-config.php');
       echo (function_exists('wp_set_comment_status'))?'yah':'nay';
       ?>
       ```
   
 * and then you will have to edit the wp_new_comment function in /wp-includes/comment.
   php and add whatever you need

Viewing 1 replies (of 1 total)

The topic ‘Modify WP database via standalone script’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [gaming](https://wordpress.org/support/topic-tag/gaming/)
 * [integrate](https://wordpress.org/support/topic-tag/integrate/)
 * [integration](https://wordpress.org/support/topic-tag/integration/)

 * 1 reply
 * 2 participants
 * Last reply from: [haochi](https://wordpress.org/support/users/haochi/)
 * Last activity: [18 years, 1 month ago](https://wordpress.org/support/topic/modify-wp-database-via-standalone-script/#post-763373)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
