Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm writing my first own Wordpress plugin. It's working great so far, except that now I need to create a few DB tables upon plugin activation.

So I put

register_activation_hook( __FILE__, 'create_tables');

in my main plugin file, and defined the function create_tables (which is tested and works) in the same file.

The problem is that the hook does not fire at all. I investigated, and it seems this is because:

  • My main plugin file is really in /usr/share/wordpress/wp-content/plugins/myplugin/myplugin.php, and this is exactly what __FILE__ contains.
  • However, it would seem Wordpress actually goes looking to /var/www/wordpress/wp-content/plugins for plugins.
  • The latter is in principle fine as /var/www/wordpress is actually a symbolic link to /usr/share/wordpress.

However Wordpress actually only fires the activation hook when I use the /var/www/... path (the symbolic link one), and not the /usr/share/... path (the real one) when registering the activation hook. Indeed, when I replace the above call with

register_activation_hook( '/var/www/wordpress/wp-content/plugins/myplugin/myplugin.php', 'create_tables');

...then the activation hook gets fired fine when I activate the plugin.

But this is not a good option. I do not want to harcode a path. This plugin is supposed to run elsewhere later. How to fix this properly?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.