Support » Plugins » activate_ and deactivate_ hooks not working?

  • Do these two hooks work?

    function myVariables_deactivate(){

    add_action(‘deactivate_plugindir/myVariables.php’, ‘myVariables_deactivate’);

    From what I can tell, this should delete an option I previously set. However, the option is not removed from the database when I deactivate this plugin.

    Also, I would like to set this plugin up so that a database table is created when the plugin is activated, but that won’t work either. The only way I can get WordPress to create a table is by checking for existence of the table when the custom admin panel loads (if the table is not in the db, it is created). I’ve tried using the activate_ hook for this and it does NOT work.

Viewing 1 replies (of 1 total)
  • I thought I had this problem too, but turns out it was my function!

    I checked my function by calling it by another hook, maybe the admin_menu is a good one?

    When activating a plugin no output is given so its harder to spot your errors.

    Also try using the following to make sure you get the correct location of your plugin:

    $activateFunction = 'my_function'; // change this;
    echo 'activate_' . preg_replace( '/.*wp-content.plugins./','',__FILE__ );

    The correct format is activate_pluginfile.php with the plugindir only used if you have placed the plugin in a sub folder e.g.:

    /wp-content/plugins/myplugin.php = activate_myplugin.php
    /wp-content/plugins/mystuff/myplugin.php = activate_mystuff/myplugin.php

    Hope this helps!


Viewing 1 replies (of 1 total)
  • The topic ‘activate_ and deactivate_ hooks not working?’ is closed to new replies.