Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 197243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T16:50:09+00:00 2026-05-11T16:50:09+00:00

I’m trying to learn to write a WordPress plugin by setting myself a goal

  • 0

I’m trying to learn to write a WordPress plugin by setting myself a goal of writing a user generated glossary plugin after I asked people on Twitter what would be useful (well I may as well use my learning experience to be useful for more than just me).

Anyway, on installation the plugin sets up a database table, and adds some test data to it. Then when the content is displayed a foreach loop changes each phrase and replaces it with a DHTML floaty box.

The problem is, however, I can’t work out what’s going on with the register_activation_hook; it may be being called and the SQL is failing or it may not be being called (either way I don’t have an extra table in the database after I activate the plugin).

The hook looks like this:

register_activation_hook(__FILE__, "bot_install");

And the bot_install code like this

function bot_install()
{
    global $wpdb;
    $table = $wpdb->prefix."sh_gloss";

    $structure = "CREATE TABLE $table (
        id INT(9) NOT NULL AUTO_INCREMENT,
        phrase VARCHAR(80) NOT NULL,
        desc VARCHAR(255) NOT NULL,
    UNIQUE KEY id (id)
    );";
    $wpdb->query($structure);

    // Populate table
    $wpdb->query("INSERT INTO $table(phrase, desc)
        VALUES('Scott Herbert', 'Rockstar Programmer')");

}

OK so firstly please forgive the ego database entry, it’s just for testing…

Secondly is there something I should have seen that I’ve missed?
And thirdly (and most importantly) how can I debug “bot_install”? Can I just add statements like:

echo "in xxxx";

or will that mess up the headers (since I guess all this code is ran before the main output).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T16:50:10+00:00Added an answer on May 11, 2026 at 4:50 pm

    I know nothing about WordPress, but…since there is no error handling in the code, how do you know that $wpdb is a valid database connection handle, and how could the code detect that something is not working – for example, the CREATE TABLE statement failed? The code apparently blindly (blithely) assumes nothing can or will go wrong, but my experience is that things can and do go wrong.


    I’m still not the expert, but the URL referenced says:

    Run Any Query on the Database

    The query function allows you to execute any SQL query on the WordPress database. It is best to use a more specific function (see below), however, for SELECT queries.

    <?php $wpdb->query('query'); ?> 
    

    query

    (string) The SQL query you wish to execute.

    The function returns an integer corresponding to the number of rows affected/selected. If there is a MySQL error, the function will return FALSE. (Note: since both 0 and FALSE can be returned, make sure you use the correct comparison operator: equality == vs. identicality ===).

    […]

    Examples

    Delete the ‘gargle’ meta key and value from Post 13.

       $wpdb->query("
           DELETE FROM $wpdb->postmeta WHERE post_id = '13'
                 AND meta_key = 'gargle'");
    

    So, presumably, if the CREATE TABLE operation fails, you will get a FALSE back from it, which you can test with the appropriate operator – I’m not sure which one it is.

    Further down, on the subject of errors, the page says:

    Show and Hide SQL Errors

    You can turn error echoing on and off with the show_errors and hide_errors, respectively.

    <?php $wpdb->show_errors(); ?>
    <?php $wpdb->hide_errors(); ?> 
    

    You can also print the error (if any) generated by the most recent query with print_error.

    <?php $wpdb->print_error(); ?> 
    

    Finally, for debugging while under initial development, it won’t matter too much if the response is garbled as long as you can see the information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 429k
  • Answers 430k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Recommend you to use this code: QTableView *tableView = new… May 15, 2026 at 1:46 pm
  • Editorial Team
    Editorial Team added an answer It is safe and fully correct behaviour. That is the… May 15, 2026 at 1:46 pm
  • Editorial Team
    Editorial Team added an answer Yes, this is possible with the IFileOperation shell interface, available… May 15, 2026 at 1:46 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.