Activating plugin that uses upgrade functions (dbDelta) fails
|Reported by:||jhodgdon||Owned by:||ryan|
Some plugins need to have their own database tables, and it's convenient for them to use the "dbDelta" function that is defined (currently) in wp-admin/includes/upgrade.php to maintain the tables (i.e. using the same method that the core of WordPress does to upgrade to new DB versions).
So, a plugin might include the following line in its activate function, in order to include the file that contains that function:
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
This worked fine through WordPress 2.3.x, but in 2.5 bleeding (tested in ), including that file causes the following error to appear when you activate the plugin (I'll attach my very short test plugin as an attachment to the ticket):
Plugin could not be activated because it triggered a fatal error.
Fatal error: Cannot redeclare bugtest_test_activate() (previously declared in /opt/www/eclipsework/WPDev/wp-content/plugins/test.php:16) in /opt/www/eclipsework/WPDev/wp-content/plugins/test.php on line 17
Contrary to the error message, the plugin is activated, however, and functions correctly after that point. The problem is apparently that it is being included twice, and the second time, of course, the functions are already there and cannot be redeclared.
There needs to be a way for plugins to include the dbDelta function, without these activation errors. I'll investigate and propose a patch.
Change History (18)
- Cc jhodgdon added
- Severity changed from normal to critical
- Summary changed from In 2.5 bleeding, activating plugin that uses upgrade functions gives spurious warning to Activating plugin that uses upgrade functions (dbDelta) fails