I’ve written a plugin to manually (admin button push) delete several hundred posts that are created by another plugin. That other plugin creates posts based on an external API.
I’m running into a situation where occasionally the API plugin is starting to creating new posts midway through the deletion.
I’m wondering if there is a way to use WP’s core maintenance mode for just a few seconds to pause everything else on the site from running while the delete runs?
I’ve looked at update-core.php and update.php but it wasn’t quite obvious to me what it was doing to initiate and terminate maintenance mode. I was kind of hoping there was a function to set maintenance mode and another to clear maintenance mode, but I’m not seeing it. Open to other ways to avoid this race condition as well.
It could be easily done by creating
.maintenance
file in the root of your WordPress instance. Your script should look like this:WordPress checks whether or not maintenance file exists in the root and if it does, then checks
$upgrading
variable to show maintenance message only for 10 minutes.By default WordPress shows standard message during maintenance mode. It contains following text:
If you want to run your own script and generate unique maintenance output, then you can create
maintenance.php
file within your wp-content folder. WordPress loads that file if it exists and stops executing a process after calling the file.