• Resolved thejoker101

    (@thejoker101)


    According to this page codex.wordpress.org/Creating_Tables_with_Plugins, this is the code you should use when creating tables with plugins. This is for when you create your table. This should prevent the action from being performed all the time, just when the plugin is activated.


    if (isset($_GET['activate']) && $_GET['activate'] == 'true') {
    add_action('init', 'jal_install');
    }

    However, this action gets performed everytime a plugin is activated. Which isn’t correct at all.

    On the plugin activation page, though, it attaches the plugin name to the $_GET, but it gets removed as it goes through the wp-admin/plugins.php file for processing.

    So, how do I know that only my plugin was activated?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Greetings. I’m the author of the article, so hopefully I’ll be able to clear things up.

    However, this action gets performed everytime a plugin is activated. Which isn’t correct at all.

    This is correct actually. AFAIK, it is not possible in WP 1.5 to hook a specific plugin activation. So, the code works around that. The dbDelta function is special in that it updates the table structure without doing anything else. So in this case, the dbDelta function is called every time ANY plugin is activated, and then if the MySQL structure does not match the structure in the file, then it changes the structure to match. Otherwise it just moves on and doesn’t create any errors. The dbDelta() function is useful when you make updates to the MySQL structure in different versions of your plugin.

    So basically, there is no harm done when another plugin activates and it checks the database for the table. Does this clear it up for you?

    -Jalenack

    P.S. WP 1.6 will have plugin activation hooks (with plugin names as well) so that it will be very simple to do all this. We can only wait 🙂

    Thread Starter thejoker101

    (@thejoker101)

    Actually, my problem is with the dbdelta function – take a look at this thread: http://wordpress.org/support/topic/38882.

    If dbdelta() worked for me, then, as you say, there isn’t any harm. Only, for me at least, dbdelta isn’t working.

    Aah, I missed that thread. Could you post the code you’ve got? (pastebin, not here) .. I’m sure we’ll be able to figure out the problem with dbDelta()

    Thread Starter thejoker101

    (@thejoker101)

    Code is here: http://pastebin.com/320680

    What is commented out is what I’d like to have work. The only change to the wp_posts table is this line:
    restricted tinyint(1) NOT NULL default ‘0’,
    (line 35 on pastebin)

    The code below it was me trying to figure out why it wasn’t working.

    Many thanks.

    Ah, I think dbDelta() is not the function we want in this case. The maybe_add_column() function looks promising. Scope it out in wp-admins/upgrade-functions.php

    Thread Starter thejoker101

    (@thejoker101)

    Huzzah! It works just like it should.

    I have another plugin with dbdelta problems as well, though I think that one actually needs dbdelta, as it is creating whole tables.

    I’ll post again here in a few with those problems.

    Thread Starter thejoker101

    (@thejoker101)

    Here is my other code: http://pastebin.com/320791

    What I don’t understand is that when I do each sql statement individually in phpMyAdmin, it works just fine.

    When I execute this statement, it will create the last table only.

    I don’t get it. Many thanks for your help.

    Don’t do CREATE TABLE IF NOT EXISTS, just CREATE TABLE .. dbDelta handles the if exists part and what not

    Thread Starter thejoker101

    (@thejoker101)

    Ah, I never noticed that part. Thanks again; it works like a charm.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Creating New Plugins’ is closed to new replies.