wp-cli / maintenance-mode-command

Activates, deactivates or checks the status of the maintenance mode of a site.
MIT License
9 stars 5 forks source link

Need custom `retry-after:` #31

Open nisbet-hubbard opened 1 week ago

nisbet-hubbard commented 1 week ago

Feature Request

Describe your use case and the problem you are facing

When you consider that there isn’t a GUI equivalent for it, maintenance-mode is really one of the unique features of CLI, unfortunately not as widely known as it should be.

Currently, we still have to rely on our maintenance mode snippet in functions.php, however, because the retry-after: 600 of CLI is hardcoded.

Describe the solution you'd like

Sysadmins usually know how long the maintenance work is going to take. So ideally we’d want to be able to tell crawlers precisely how long to wait before visiting again.

A retry-after flag would be very much appreciated.

swissspidy commented 6 days ago

Just to clarify, when you say retry-after: 600 is hardcoded, are you referring to the following line?

https://github.com/wp-cli/maintenance-mode-command/blob/71969348fe93452a3fedfcdd64fdc5725e906f9f/src/MaintenanceModeCommand.php#L153

That value is also hardcoded in WordPress core itself in wp_is_maintenance_mode()

nisbet-hubbard commented 5 hours ago

Thanks for this info! So maybe we can just do something like the following?

function maintenance() {
if (!current_user_can('edit_themes') || !is_user_logged_in()) {
    require_once ABSPATH . WPINC . '/functions.php';
    wp_load_translations_early();

    header( 'Retry-After: $var' );
    wp_die(
        __( 'Briefly unavailable for scheduled maintenance. Check back in a minute.' ),
        __( 'Maintenance' ),
        503
    );
}
}

add_action('get_header', 'maintenance');