If you’re like me and manage dozens of WordPress sites, you’ve probably got a shared code base which allows you to upgrade the WordPress filesystem easily.. But most likely you’ve also found it painful to have to visit each wp-admin individually and click the “Update WordPress Database” button. Ever wanted to script this task to run from the command line? Here you go 🙂
The script below allows you to specify the path to one WordPress installation.. For multiple sites/installs just put this script in a loop.
Thanks to wp-cli for pointing me in the right direction.
// specify path to your wordpress root - no trailing slash
$wp_root = '/path/to/wordpress/root';
// load wordpress
require "{$wp_root}/wp-load.php";
// ensure we don't run out of memory
@ini_set( 'memory_limit', -1 );
// load admin API
require "{$wp_root}/wp-admin/includes/admin.php";
// load upgrade API
require "{$wp_root}/wp-admin/includes/upgrade.php";
// upgrade database
wp_upgrade();






