John Kent
John Kent

Reputation: 386

Why 'init' hook doesn't work?

I try to add an action to 'init' hook, but when I open any page I don't get the result which is defined in the callback.

Could you say what to do?

(permissions to the file system are present. I located a code, which is inside the callback, directly into activate method and it worked)

class MyPlugin
{
    public function activate()
    {
        add_action('init', function() {
            $file = fopen(__DIR__.'myFile.txt', "w");
            fwrite($file, 'it works');
            fclose($file);
        });
    }

$myPluggin = new MyPlugin();

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

P.S.: When I call do_action('init') manually it works. But how to get it work automatically?

Upvotes: 1

Views: 1265

Answers (1)

John Kent
John Kent

Reputation: 386

I found the answer to my question, (it's written here):

only two hooks are fired after the plugin's activation hook: 'activated_plugin' and 'shutdown'

Upvotes: 1

Related Questions