• I’m working on a plugin, and need to know if the user has
    activated it. I noticed in wp-admin/plugins.php there’s
    an action called activate_ + trim($_get(plugin)).

    If I read it right, it would send off to a function called
    activate_plugin.php. However, you can’t create a function
    with a period in its name. Has anyone used these successfully?

    I browsed through wp-admin/plugins.php to see the call code,
    and wp-includes/functions.php (line 1235) but didn’t see
    anything that would either get rid of the .php or remove
    the period to give activate_pluginphp.

    Any help appreciated!

    Thanks,
    Loyd

Viewing 5 replies - 1 through 5 (of 5 total)
  • activate_your-plugin.php is an action hook. To learn more about what that means, see the Codex here.

    Basically, that means that you could write a function, say lgoodbar_function, and have it fire off whenever your plugin is activated. The code would look like this:

    function lgoodbar_function () {

    ... do exciting stuff when my plugin is activated !...

    }

    add_action('activate_your-plugin.php','lgoodbar_function');

    Thread Starter lgoodbar

    (@lgoodbar)

    Thanks very much, that was exactly what I was looking for!
    Loyd

    Im trying to use:

    add_action(‘activate_your-plugin.php’,’lgoodbar_function’);

    But I must do something wrong cause nothing works.
    Im trying to create tables and I’ve read all about $wpdb and how to use activate_ hook to trigger my install.php when plugin installed. Maybe I type in the wrong pluginurl or maybe I put my install.php the wrong place. Can someone please help me with an example or maybe a hint about how to debug my installer.

    To be more specific this is what I try, but I cannot get it to work. My plugin “myplugin.php” is ofcourse placed in
    /plugins/myplugin.php

    and my install.php is placed in the same directory.
    This is the code:

    function my_install() {

    global $wpdb;
    $wpdb->show_errors();

    $sql = “CREATE TABLE myTable (
    id MEDIUMINT(9) AUTO_INCREMENT,
    content TEXT,
    PRIMARY KEY (images_id), );”;

    require_once(ABSPATH . wp-admin/upgrade-functions.php’);
    dbDelta($sql);
    }

    add_action(‘activate_myplugin.php’, ‘my_install’);

    UPS, sorry Im a newbe:

    function my_install() {
    global $wpdb;

    $sql = “CREATE TABLE my_images (
    id MEDIUMINT(9) AUTO_INCREMENT,
    content TEXT,
    PRIMARY KEY (id),
    );”;

    require_once(ABSPATH . ‘wp-admin/upgrade-functions.php’);

    dbDelta($sql);
    }

    add_action(‘activate_my_plugin.php’,’my_install’);

    BUT it still doesn’t work?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘activate plugin function WP 2.0 (development)’ is closed to new replies.