Problem in creating table through plugin code

The above code should be placed in a function and then hook that with plugin activation hook? Here’s sample structure of plugin-name.php file. Note – Use CREATE TABLE IF NOT EXISTS instead only create table Code Updated on – 2012-08-04 <?php // this code goes into your my_plugin_name.php file function install_my_plugin() { global $wpdb; $table_name … Read more

What files to keep after upgrading WordPress?

Delete everything but wp-content and wp-config.php, copy the fresh installation into the directory. On upgrading WordPress will use the database to see what should be done, not the files. Not all files are deleted automatically, because some of them might still be used by outdated plugins or external scripts (the old feed files are good … Read more

Custom database table for plugin not creating on activation

Here’s an updated version of pf_rb_install(). In the table creation SQL, $table_name should not be in quotes. The quotes should have triggered an error which would appear in PHP’s error.log file. Also, there should be two spaces after the PRIMARY KEY (id) portion of the SQL statement. register_activation_hook( __FILE__, ‘pf_rb_install’ ); function pf_rb_install() { global … Read more

Why does dbDelta() not catch MysqlErrors?

As @Charleston Software Associates mentioned, the DESCRIBE query should not be executed if the table doesn’t exist. The best solution, as he pointed out, is to prevent the error from occurring in the first place. To do so, patch wp-admin/includes/upgrade.php as follows: Change the following line from dbDelta(): $tablefields = $wpdb->get_results(“DESCRIBE {$table};”); to: //Begin core … Read more

How to define composite keys with dbDelta()

The problem If the table already exists your code will still try to execute the following queries: 1) ALTER TABLE wp_voicemail_call CHANGE COLUMN user_id user_id BIGINT(9) UNSIGNED NOT NULL 2) ALTER TABLE wp_voicemail_call CHANGE COLUMN call_id call_id BIGINT(9) UNSIGNED NOT NULL 3) ALTER TABLE wp_voicemail_call CHANGE COLUMN opened opened BOOL DEFAULT 0 NOT NULL 4) … Read more