Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6775811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:57:05+00:00 2026-05-26T15:57:05+00:00

I want to write PHP script (standalone) for comment approval. Objective : I use

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:57:06+00:00Added an answer on May 26, 2026 at 3:57 pm

    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.

    <?php
    include('wp-load.php');
    
    echo 'Running comment approval...<br>';
    $wp_error = false;
    
    if(isset($_GET['commentid']) && isset($_GET['status']) )
    {   
    
    
            $comment_id = $_GET['commentid'];
            $comment_status_to_set = $_GET['status'];
    
            $current_status = wp_get_comment_status( $comment_id );
    
            echo 'Current comment status is ' . $current_status .'<br>';
            echo 'Setting status to ' . $comment_status_to_set . '<br>';
    
            $res = wp_set_comment_status($comment_id, $comment_status_to_set, $wp_error);        
    
            $new_current_status = wp_get_comment_status( $comment_id ); 
            echo 'Now status is ' . $new_current_status . '<br>';
    }
    else
    {
        echo 'No comment parameters passed in url';
    }
    
    ?>
    

    And here is the usage for wp_set_comment_status, from the source code:

    • @param int $comment_id Comment ID.
    • @param string $comment_status New comment status, either ‘hold’, ‘approve’, ‘spam’, or ‘delete’.
    • @param bool $wp_error Whether to return a WP_Error object if there is a failure. Default is false.
    • @return bool False on failure or deletion and true on success.

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a PHP script that I can use from the command
I want to write a php script that keeps the apache_log file open and
Simple question I guess, I want to use PHP to write an update to
I'm totally rookie as to PHP. I want to write a PHP script in
I want to write a php script, which lists all the items in the
I want to write a PHP script that will run as a cron job
I want to write a PHP script which, given a URL, copies the whole
So i want to write a php script who checks in the data base
I want to write either a perl (CGI) or php script on a server
I want to write a crawler script with php and it is necessery to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.