Make WordPress Core

Opened 7 years ago

Closed 7 years ago

#6747 closed defect (bug) (fixed)

function maybe_create_table() declared in two files

Reported by: mastermind Owned by:
Milestone: 2.6.1 Priority: low
Severity: blocker Version: 2.6
Component: General Keywords: has-patch
Focuses: Cc:


The function maybe_create_table() is a nice helper for plugins that need to create a database table. As it is not available by default, one has to include the file which contains this function. So far so good.

However, maybe_create_table() is declared in /wp-admin/install-helper.php as well as in /wp-admin/includes/upgrade.php.

If, as a matter of coincidence, both of the above files are loaded, then this will of course throw a "Fatal error: Cannot redeclare maybe_create_table() in /var/www/htdocs/elnl.zirona.de/wp-admin/includes/upgrade.php on line 735"

This is not only theoretical, but I actually encountered this in the following situation:

A plugin of mine uses a function activate_plugin(), called via register_activation_hook(__FILE__, 'activate_plugin');. That function loads /wp-admin/install-helper.php to use the function maybe_create_table(). When I tried to import content to the blog (Manage -> Import -> WordPress), the page would die with the Fatal error.

The solution was to temporarily deactivate the table creating routine from the activation function.

Attachments (1)

upgrade.diff (2.0 KB) - added by solsen230 7 years ago.

Download all attachments as: .zip

Change History (8)

@solsen2307 years ago


comment:1 @solsen2307 years ago

I uploaded a patch that should fix this. Untested.

Changes - Removed maybe_create_table() and maybe_add_column() functions in the upgrade.php file referenced in ticket. require_once'd install-helper.php to make these functions still available to upgrade.php.

comment:2 @solsen2307 years ago

  • Keywords has_patch added

comment:3 @solsen2307 years ago

  • Keywords has-patch added; has_patch removed

comment:4 @azaozz7 years ago

  • Version changed from 2.5 to 2.6

Don't think install-helper.php was meant to be used by plugins that need to create tables. There's dbDelta() defined in upgrade.php for this. Still, wrapping these functions in !function_exists() just in case.

comment:5 @azaozz7 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [8610]) Prevent fatal error if plugin uses install-helper.php, fixes #6747 for 2.7

comment:6 @azaozz7 years ago

  • Milestone changed from 2.7 to 2.6.1
  • Resolution fixed deleted
  • Status changed from closed to reopened

Re-open for 2.6.1

comment:7 @azaozz7 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [8611]) Prevent fatal error if plugin uses install-helper.php, fixes #6747 for 2.6.1

Note: See TracTickets for help on using tickets.