Using WordPress ‘make_db_current()’ PHP function

The make_db_current() WordPress PHP function updates the database tables to a new schema.

Usage

To update all tables to the latest defined schema:

make_db_current();

To update a specific set of tables:

make_db_current('specific_tables');

Parameters

  • $tables (string, optional): Which set of tables to update. Default is ‘all’. Default: ‘all’.

More information

See WordPress Developer Resources: make_db_current()

Examples

Update All Tables

Update all database tables to the latest schema.

make_db_current();

Update Specific Tables

Update only specific tables to the latest schema.

make_db_current('posts, comments, users');

Conditional Update

Update all tables only if the database version is less than a certain value.

$database_version = get_option('db_version');

if ($database_version < 12345) {
    make_db_current();
}

Update After Plugin Activation

Update database tables to the latest schema when a plugin is activated.

function my_plugin_activation() {
    make_db_current();
}
register_activation_hook(__FILE__, 'my_plugin_activation');

Update Tables After Theme Switch

Update the database tables to the latest schema when switching to a new theme.

function my_theme_switch() {
    make_db_current();
}
add_action('after_switch_theme', 'my_theme_switch');