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.

class getStatic {

    var $_renderTasksOn =

              <!-- 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.

1 Answer 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();
  • Wow thanks a lot Jan. That is exactly what I was looking for. Thanks once again for helping. You really saved me a lot of time.
    – Vikram
    Jan 7, 2011 at 14:29
  • @Vikram: I'm glad I could help, and welcome to this site! I hope to see more good questions and answers from you here in the future.
    – Jan Fabry
    Jan 7, 2011 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.