I’m working on a plugin that was creating a table successfully.
However, I decided to test it in a fresh install of WordPress (on my local server) and now the table is not being created in my activation code. Instead I am getting the error message:
The plugin generated 149 characters of unexpected output during
activation. If you notice “headers already sent” messages, problems
with syndication feeds or other issues, try deactivating or removing
this plugin.
Here is my code:
function nc_create_location_table() {
// makes the location table
global $wpdb;
global $simple_location_version;
$table_name = $wpdb->prefix . "nc_location";
$installed_ver = get_option( "simple_location_version" );
if( $installed_ver != $simple_location_version ) {
$sql = "CREATE TABLE " . $table_name . " (
location_id MEDIUMINT(9) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (location_id),
name VARCHAR (100),
street_no VARCHAR (5),
street_name VARCHAR (75),
city VARCHAR (75),
province_state VARCHAR (75),
postal_code VARCHAR(10),
country VARCHAR (75)
);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql);
update_option("simple_location_version", $simple_location_version);
}
$tmp = get_option('nc_location_options');
if(($tmp['chkbox_reset']=='on')||(!is_array($tmp))) {
echo 'setting defaults';
$arr = array(
"nc_location_zoom"=>10,
"nc_location_width" => "200",
"nc_location_height" => "200",
"nc_location_drop_down_maptype" => "road",
);
update_option('nc_location_options', $arr);
}
}
register_activation_hook(__FILE__,'nc_create_location_table');
When I check my tables, I see that my table hasn’t been created, and also I am getting an error message.
If anyone can shine a light on why code that was working is now not working (and also, is it possible to see where the unexpected output is…as there’s no display as to what the error is other than this message)?