Looking at another example, I think the url is just the file name, so your hook would look like this:
add_action(‘activate_myplugin.php’, ‘my_activate_function’);
The example I learned from is YARQ
http://openmonday.org/2006/07/31/yet-another-random-quote/
Cheers!
pf
If your plugin is in a folder, use
add_action(‘activate_folder/plugin.php’, ‘function’);
Note, it has to be forward slash, backslash doesn’t seem to work (escapes the character)
Aaron
A better way might be to find out what your current filename is, relative to the plugins directory, and use that. Just coding off the top of my head here…
$myrelpath = preg_replace('.*wp-content.plugins.','',__FILE__);
add_action('activate_'.$myrelpath,'function');
This should work whether the plugin is in a subdirectory or not.
I’ve tried both solutions and I cannot make it work, I could really use some hint here:
I’ve tried:
add_action(‘activate_folder/plugin.php’, ‘function’);
and also:
$myrelpath = preg_replace(‘.*wp-content.plugins.’,”,__FILE__);
add_action(‘activate_’.$myrelpath,’function’);
But it seems that my function for installing my SQL TABLES
doesn’t get initiated. Is there something that I’m missing?
I have read CREATING TABLES WITH PLUGINS, but nothing seems to help.
I have put my install-function in its own php-file and placed it in ../plugins/ along with my plogin.php file.
Hi nkoenig,
Try this code:
$activateFunction = ‘activateMyPlugin’; // change this;
add_action( ‘activate_’ . preg_replace( ‘/.*wp-content.plugins./’,”,__FILE__ ), $activateFunction );
I’ve tried:
add_action(‘activate_folder/plugin.php’, ‘function’);
First, you’re not using that literally, are you? You do realize that you need to change the folder and filename to the folder and filename of your plugin, right? Also you need to change the function to the name of your function, yes? The second version does the same thing, it just figures out the filename and path for you, you still need to change the ‘function’ to whatever your install function is called.
I have put my install-function in its own php-file and placed it in ../plugins/ along with my plogin.php file.
Okay, if it’s in its own PHP file, then you need to include or require it in the actual plugin’s PHP file. Or just not have it in a separate file at all.