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
- However, it would seem Wordpress actually goes looking to
- The latter is in principle fine as
/var/www/wordpressis actually a symbolic link to
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?