← All posts

Runtime Code

By · · Updated

Some WordPress settings can only be set very early, before WordPress starts. They are PHP constants, such as WP_POST_REVISIONS or WP_DEBUG, and they normally live in the wp-config.php file. To change one, you have to open that file and edit it by hand.

The Docket Cache runtime code makes this easier. It is a small piece of code that you add to wp-config.php once. After that, you can change these settings under Runtime Options on the Docket Cache Configuration screen, and Docket Cache sets the constants for you.

How it works#

The runtime code sits in wp-config.php, just above the line that starts WordPress. When a page loads, it reads a second file, runtime.php, from the Docket Cache data folder (wp-content/docket-cache-data by default). That file holds the settings you chose under Runtime Options.

The wp-config.php file with the runtime code just above the line that loads wp-settings.php. First, the runtime code reads runtime.php, which sets constants such as AUTOSAVE_INTERVAL, WP_POST_REVISIONS and EMPTY_TRASH_DAYS, only if they are not set already. Then WordPress starts and uses those constants.
The runtime code loads your Runtime Options before WordPress starts

A few things keep this safe.

Installing the runtime code#

We do not add the code without asking you first. When you change a Runtime Option, Docket Cache checks wp-config.php for the code. It reads the file with PHP's token_get_all function, which looks through the file without running it. If the code is missing, Docket Cache shows an install box with the code inside.

When you change a Runtime Option, Docket Cache checks whether the runtime code is installed. If it is, the setting is saved to runtime.php and used from the next page. If not, the install box is shown. You can copy the code yourself, or click Install if WordPress can write the file. Docket Cache then adds the code and loads your home page. If it works, you are done. If it fails, the old file is put back.
What happens when you change a Runtime Option

You then have two choices.

The Docket Cache Configuration screen with the runtime code box. It shows the code to copy into wp-config.php, with Install and Un-Install buttons, and an Update Runtime Code button under Actions on the right.
The runtime code box on the Configuration screen. When the code is already installed, as here, it also shows an Un-Install button.

On a Bedrock site, the settings live in config/application.php instead, and the code goes just after the line Config::apply();. There is no Install button on Bedrock, so copy the code yourself.

Updating or removing it#

The Runtime Code box under Actions, on the right of the Configuration screen, lets you update or remove the code at any time. As with installing, you can do it by hand, or click Install or Un-Install.

From the command line, use these commands.

wp cache runtime:install
wp cache runtime:remove

See WP-CLI for more.

The Runtime Options#

Each Runtime Option sets one WordPress constant.

Runtime Option WordPress constant What it does
Auto Save Interval AUTOSAVE_INTERVAL How often the editor saves a draft while you write
Post Revisions WP_POST_REVISIONS How many old versions of each post to keep
Trash Bin EMPTY_TRASH_DAYS How many days deleted items stay in the bin
Cleanup Image Edits IMAGE_EDIT_OVERWRITE Keeps only the latest copy when you edit an image, instead of every version
Disallows WP Auto Update Core WP_AUTO_UPDATE_CORE Turns off automatic WordPress updates
Disallows Plugin / Theme Editor DISALLOW_FILE_EDIT Hides the plugin and theme file editor in the admin
Disallows Plugin / Theme Update and Installation DISALLOW_FILE_MODS Stops anyone installing or updating plugins, themes and WordPress from the admin
Deactivate Concatenate WP-Admin Scripts CONCATENATE_SCRIPTS Loads admin scripts one by one instead of joined into one file
Deactivate WP Cron DISABLE_WP_CRON Stops WordPress running scheduled tasks when pages load
WP Debug WP_DEBUG Turns on WordPress debug mode
WP Debug Display WP_DEBUG_DISPLAY Shows errors on the page while debug mode is on
WP Debug Log WP_DEBUG_LOG Saves errors to a log file while debug mode is on

WP Debug Display and WP Debug Log only appear when WP Debug is turned on. On a multisite network, Runtime Options are only shown on the main site. See Admin Interface for the rest of the Configuration screen.