Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

register_activation_hook in construct doesn't work

Tags:

wordpress

I have an question about register_activation_hook in construct.

I have read, that this should be possible, but I don't know, currently nothing will be written to the error_log (for debugging).

Look here, the author say it should work http://www.plulz.com/how-to-create-a-plugin-for-wordpress

Here's my code

<?php
abstract class LW_Capability{
    const NAME = 'Capability';

    public function __construct(){
        register_activation_hook(
            __FILE__,
            array(
                $this,
                'activate'
            )
        );

        register_deactivation_hook(
            __FILE__,
            array(
                $this,
                'deactivate'
            )
        );
    }

    public function activate(){
        error_log('LW_Capability->activate');
    }

    public function deactivate(){
        error_log('LW_Capability->deactivate');
    }


}

class CapabilityEditRessource extends LW_Capability{
    const NAME = 'EditRessource';
}
?>

What do I do wrong? If I add an "die('parent')" to the LW_Capability, it will die. The Plugin can't be activated then (WP Blocks because of output).

Anyone here who does somthing similar?

Would be happy to hear from you.

Regards, Oli

like image 585
lippoliv Avatar asked Dec 29 '25 11:12

lippoliv


1 Answers

register_activation_hook(
        __FILE__,
        array(
            $this,
            'activate'
        )
    );

    register_deactivation_hook(
        __FILE__,
        array(
            $this,
            'deactivate'
        )
    );

could just be used in the main-file of the plugin ^^

I modifyed it to

register_activation_hook(
    __FILE__,
    array(
        $MyPluginInstance,
        'activate'
    )
);

register_deactivation_hook(
    __FILE__,
    array(
        $MyPluginInstance,
        'deactivate'
    )
);

And this functions calls manually the register / unregister-functions of the capability-class

like image 85
lippoliv Avatar answered Dec 30 '25 23:12

lippoliv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!