Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use comment_new_status_comment-comment_type action in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 4, 2023
5 minutes read

Working with WordPress hooks can be both exciting and daunting at the same time. You might have come across the comment_new_status_comment-comment_type action hook and wondered how to put it to good use. Let’s dive into what this hook does and how you can utilize it effectively in your projects.

The dynamic parts of this hook, $new_status and $comment->comment_type, refer to the new comment status and the type of comment, respectively. To start using the comment_new_status_comment-comment_type action, you need to register it using add_action. You can include this in the functions.php file of your active theme or, better yet, in a custom WordPress Plugin to ensure your customizations remain intact even after theme updates.

Here’s how you can make the most out of this hook with some live examples:

Example 1: Basic Hook Implementation

This example demonstrates the basic usage of the hook. It shows how to execute a function when a comment’s status changes.

    function weplugins_execute_on_comment_new_status($comment_ID, $comment) {
        // Code to execute when the comment status changes
    }
    add_action("comment_new_status_comment-comment_type", "weplugins_execute_on_comment_new_status", 10, 2);
    

Example 2: Custom Functionality on Comment Status Change

In this example, we implement custom functionality that triggers when the hook is executed. Adjust the code as needed for your specific requirements.

    function weplugins_custom_comment_action($comment_ID, $comment) {
        // Custom functionality based on comment status
    }
    add_action("comment_new_status_comment-comment_type", "weplugins_custom_comment_action", 10, 2);
    

Example 3: Removing a Hook Callback

If you need to remove a registered hook, use the remove_action function as demonstrated below.

    remove_action("comment_new_status_comment-comment_type", "weplugins_execute_on_comment_new_status", 10, 2);
    

When removing a hook, ensure the callback function name, priority, and number of arguments match those used during registration.

If you need any assistance or customization for using this hook, feel free to Contact Us. We’re here to help!

Access Premium WordPress Plugins

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.