0

I have created a plugin where I want to call two different functions on activation.

Is there a best way to do this?

Should I use register_activation_hook twice? As in:

register_activation_hook( __FILE__, 'function_1' );
register_activation_hook( __FILE__, 'function_1' );

Or call the two functions from within an activation function, as in:

register_activation_hook( __FILE__, 'my_activation_function' );
function my_activation_function () {

    function_1();
    function_2();

}

Any ideas? Thanks.

  • Just a note: adding multiple instances of register_activation_hook does work - though it may not be the right way to do it. – Pat Gilmour Jun 21 '14 at 2:56
3

My approach to this would be to have a start_activation() method that calls the other methods.

register_activation_hook( __FILE__, array( 'my_plugin_loader', 'start_activation' ) );

class my_plugin_loader {
    function start_activation() {
        $this->func1(); // or self::func1();
        $this->func2(); //    self::func2(); for static methods
     }
     function func1() {
         // do stuff
     }
     function func2() {
         // do other stuff
     }
 }

I'm not saying it is the "right" way, just how I would approach it.

  • This is what I've gone for, though using the procedural way in my original post. It works fine. Thanks for the method/OOP variant! – Pat Gilmour Jun 21 '14 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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