So I’m slowly answering my own question… so I thought I’d post to help others out if they are looking to do the same…
Please correct me if I’m wrong on any of these points, I’d hate to be misleading or confusing, but this is the way I understand it…
1) Use a plugin… Writing_a_Plugin
All the half-arse leads into the good WP documention can really throw you for a loop. You can create a dynamic table in the wp database…
->Copy the index.php in your “wp_content/plugin directory”
->Name it whatever you want… we’ll use “mynewplugin.php” for this
->Open mynewplugin.php
->Delete everything out of it
->Setup your mynewplugin.php as so…plugin name(just the bare minimum):
<?php
/*
Plugin Name: My New Plugin
*/
?>
-> Open your WordPress account and goto your editor under plugins
-> Select your “My New Plugin” in the drop down
2) So that’s where that code goes
Goto Creating_Tables_with_Plugins and read, re-read and follow what it says…
3) Editing for your own use
You can define global vars to use in other places by setting $my_new_vars in the mynewplugin.php
Basically I changed this:
function jal_install_data() {
global $wpdb;
$welcome_name = "Mr. WordPress";
$welcome_text = "Congratulations, you just completed the installation!";
$rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'name' => $welcome_name, 'text' => $welcome_text ) );
}
To this:
global $jsa_user_name;
$jsa_user_name = "TestGuy";
global $jsa_post_title;
$jsa_post_title = "PO-0 Just a fake post for testing";
function jsadb_install_data() {
global $wpdb;
global $jsa_user_name;
global $jsa_post_title;
$rows_affected = $wpdb->insert( $table_name, array( 'time' => current_time( 'mysql' ), 'name' => $jsa_user_name, 'text' => $jsa_post_title ) );
}
I’m assuming that creating the global vars $jsa_user_name and $jsa_post_title will allow me to add data by calling jal_install_data (which I renamed jsa_add_data)
My next question is do functions work in WP like they do in other programming languages… HERE… no, the scope of a function’s variables can only be used in that function if you redefine the global…like above:
global $jsa_user_name;
$jsa_user_name = "TestGuy";
global $jsa_post_title;
$jsa_post_title = "PO-0 Just a fake post for testing";
function jsadb_install_data() {
global $wpdb;
global $jsa_user_name;
global $jsa_post_title;