Reputation: 386
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