How to get multiple Action Hooks in an Array

Hi I am writing a small plug-in which I get some content from outside of WordPress and I want a small script to trigger whenever a new post, page or comment is added. Also if any Widgets, themes and Plug-ins are Activated or De-Activated.

My guess is that I should be using the action hooks for this but since there are multiple actions so how to get all those actions in some array or so.

Read More
class getStatic {

    var $_renderTasksOn =
        array(

              <!-- How do I call those actions in an array here -->

        )

function gerStatic() {

    <!-- Here goes the script to get external data -->
}

}

I am very new to programming hence kindly help with the code. How do I use those action hooks?

Kindly help.

Related posts

Leave a Reply

1 comment

  1. If you want to hook into multiple actions, you have to call add_action multiple times. However, this is not so hard. Let’s take your plugin class as an example:

    class WPSE6526_getStatic // Always prefix your plugin with something unique, like your name. Here I used the question number
    {
        var $_renderTasksOn = array( 'wp_insert_post', 'wp_insert_comment', ... );
    
        function WPSE6526_getStatic()
        {
            // The constructor of this class, which will hook up everything
            // This is the 'trick' to this question: a loop on your list and `add_action` for each item
            foreach ( $this->_renderTasksOn as $hookname ) {
                add_action( $hookname, array( &$this, 'getStatic' ) );
            }
        }
    
        function getStatic()
        {
            // Your code
        }
    }
    
    add_action( 'plugins_loaded', 'wpse6526_getStatic_init' );
    function wpse6526_getStatic_init()
    {
        $GLOBALS['wpse6526_getStatic_instance'] = new WPSE6526_getStatic();
    }