Hi Jan,
the tables are only created once the WP dashboard of that site is visited. We don’t want to execute the check for migration tasks (DB table creation) on each frontend request, that’s why they are executed on the admin_init hook. This hook only runs in the admin dashboard.
Please test it out, by logging into the admin dashboard of one of your subsites. That should run the migration and create the DB table for that subsite.
The WP site without that DB table should still work OK, just the DB errors will be logged.
Take care!
@capuderg Thanks for the details π
We run and maintain > 100 sites in the Multisite with the plugin. Any chance to provide a WP-CLI command for the DB update with one of the next updates?
Logging in to each of these sites after updates is quite ineffective and contrary to our any automation deployment strategy.
WP-CLI would reduce the efford to a 1 line shell script and about 1 minute “work”.
Thanks alot and best regards,
Jan
Hi Jan,
you could also run the plugin migrations by running wp_mail_smtp()->init_migrations(). We added this method in v3.0.
So, adding something like this code below would run the migrations once a day and they would be triggered by frontend requests as well:
// Fire DB migrations once per day on "init" action instead of "admin_init" for correct DB tables creation on subsites.
if (
! \WPMailSMTP\WP::in_wp_admin() &&
! \WPMailSMTP\WP::is_doing_ajax() &&
is_multisite() &&
! is_network_admin() &&
! wp_doing_cron() &&
! get_transient( 'wp_mail_smtp_multisite_init_migrations_daily' )
) {
remove_action( 'admin_init', [ wp_mail_smtp(), 'init_migrations' ] );
add_action( 'init', [ wp_mail_smtp(), 'init_migrations' ] );
set_transient( 'wp_mail_smtp_multisite_init_migrations_daily', true, DAY_IN_SECONDS );
}
As long as your subsites have some traffic, the migrations should run within a day or two.
Let me know if that will resolve your issues.
Take care!
-
This reply was modified 4 years, 3 months ago by
Gregor Capuder. Reason: added is_multisite() check
@capuderg Thanks for the input. That are all information relevant to solve the migration using WP-CLI π
For anyone asking or searching: In a WordPress Multisite you can run the DB migration in all sites with this command:
wp site list --field=url | xargs -n1 -I % wp --url=% eval 'if (function_exists("wp_mail_smtp")) { wp_mail_smtp()->init_migrations(); }'
Best,
Jan
Hi Jan,
thank you for sharing the WP CLI solution with others.
I just want to point out, that this is only possible with WP Mail SMTP v3.0 or higher (before this version, the init_migrations method did not exist).
Thanks again and have a nice day!