An unexpected WordPress option change often looks like a database problem: the setting is saved, but after a new request, cron job, or page reload, it returns to its previous value. In reality, the cause may be a plugin, theme, form handler, REST request, or background process that calls update_option() again.
Checking the wp_options table shows only the current value, not who overwrote it. To find the source, you can temporarily add an MU plugin with a pre_update_option_option_name filter. It will log when the option changes and provide a PHP call chain that usually reveals the source of the problem.
Why WordPress Options Change Without an Obvious Reason
Options store global settings for WordPress, plugins, and themes. Saving usually relies on update_option(), but the change may happen inside other code after a form is submitted, settings are synchronized, an import runs, a user authenticates, or a cron job executes.
A plugin may not write a value only once during activation. It may check the option on every request and restore it if it considers the current value invalid. Another common scenario is a settings page submitting an incomplete array, after which the plugin saves it over the previous value and removes some existing parameters.
The most common sources of these changes are:
- A plugin with its own settings page
- A child theme or custom theme
- WP-Cron, Action Scheduler, or another scheduler
- A site import or migration
- A REST API request, AJAX request, or CLI command
- A callback attached through update_option or another filter
- Code that directly modifies the database table
What to Check Before Adding Tracing
First, make sure the option being changed is the one you are tracking. The name in the wp_options table may differ from the field name used in a settings form. For arrays, it is also important to distinguish the entire option from an individual key inside it: WordPress stores the array as one value.
Compare the change time with events on the site. If the value changes only at a particular time, suspect cron or an external integration. If it changes immediately after opening a settings page, the page code or an automatic configuration check is a likely cause.
It is useful to record the following temporarily:
- The exact option name
- The old value and the expected value
- The URL or action after which the change occurs
- Whether the problem repeats in the administrative area, on the front end, or only during cron execution
- Which plugins or themes were recently updated or configured
How to Add an MU Plugin for Tracing
Create a file named trace-option.php in the wp-content/mu-plugins/ directory. MU plugins load automatically and do not need to be activated through the administrative panel. If the mu-plugins directory does not exist, you can create it manually.
In the example below, replace my_option with the actual option name. Priority 999 helps you see the value after most other filters have run. The tracer does not modify the data; it only passes the new value farther along the filter chain.
The code intentionally does not log the old and new values. An option may contain passwords, tokens, API keys, or personal data, so the option name and backtrace are sufficient for initial troubleshooting.
Make sure PHP or WordPress error logging is enabled in a controlled environment. If error_log() does not write a message, check your hosting configuration and WP_DEBUG_LOG settings.
<?php
$trace_option = 'my_option';
add_filter(
'pre_update_option_' . $trace_option,
function ($new_value, $old_value, $option_name) {
if ($new_value === $old_value) {
return $new_value;
}
$request_uri = isset($_SERVER['REQUEST_URI'])
? $_SERVER['REQUEST_URI']
: 'CLI/cron';
error_log(sprintf(
'[option-trace] Changed %s; request=%s; backtrace=%s',
$option_name,
$request_uri,
wp_debug_backtrace_summary()
));
return $new_value;
},
999,
3
);
How to Read the Log Entry
After adding the tracer, repeat the action that causes the problem: open the relevant page, save the settings, or wait for the scheduled task to run. Then look for a log entry containing the [option-trace] marker.
The wp_debug_backtrace_summary() function returns a shortened call chain. It may contain function names, class methods, and files that led to update_option(). If you see a specific plugin prefix, a class name, or a callback with a clear name, it is the main candidate to investigate.
A backtrace does not always show the exact line of code that wrote the value. It may show only the path to update_option(), especially when the change occurs through a settings abstraction. In that case:
- Find all update_option() and delete_option() calls in the plugin code
- Search for the option name throughout the plugin directory
- Check callbacks attached to admin_init, init, rest_api_init, wp_ajax_*, and cron hooks
- Check whether saving is triggered by a settings page handler
- Compare callback priorities if multiple components modify the option
What to Do If the Tracer Shows Nothing
The pre_update_option_option_name filter runs when an existing option is updated through the standard Options API. It does not cover every possible way data can change, so the absence of a log entry does not mean the problem has disappeared.
Check the following possibilities:
- The value is being created for the first time with add_option(), rather than updated with update_option()
- A network option is being changed in a multisite installation, which requires pre_update_site_option_* filters
- The code runs a direct SQL query against wp_options
- You are tracing the wrong option name
- The cache, transient, or another storage system is changing instead of the option itself
- The log entry is being written to a different file, such as the PHP-FPM, web server, or CLI process log
Common Diagnostic Mistakes
Do not immediately prevent the change by returning the old value from the filter. This can hide the problem, break legitimate settings saves, or trigger repeated write attempts. First identify the source; use blocking only as a short-term emergency measure.
You should also avoid logging complete option values without masking them. Large serialized arrays can quickly inflate the log, and their contents may include secrets. If comparing values is necessary, log only the type, array size, hash, or specific safe keys.
Another mistake is leaving the MU plugin on production after the investigation is complete. A backtrace is generated every time the option changes, and intensive logging can increase server load and log file size. Once you have sufficient evidence, remove the file or disable the code and clear temporary logs according to your security policy.
How to Fix the Root Cause
Once you identify the responsible component, review the logic that creates the new value. The problem is often not update_option() itself, but code that passes an incomplete array, applies default values on every request, or treats an empty value as a sign of corrupted configuration.
For array-based settings, it is safer to retrieve the current option first, change only the required key, and save the result. When processing forms, validate allowed fields, data types, and user permissions. Do not write the option on every request unless necessary; update it only when the value has actually changed.
If a third-party plugin is responsible, check its updates, known issues, and compatibility. In a staging environment, you can temporarily disable the suspected component and repeat the scenario. If the problem disappears, fix the plugin, its configuration, or your custom integration code rather than masking the symptom with a filter.
Frequently asked questions
Can I trace all option changes at once?
Technically, you can attach a general pre_update_option filter, but on an active site this will create a large amount of noise and many log entries. Start with the specific option that is changing unexpectedly.
Will the backtrace show the exact plugin that changed the option?
Often, yes: the call chain may show the plugin's functions, methods, or files. However, the backtrace can be shortened and may not contain the exact line of code, so confirm the result by searching for the option name and update_option() calls.
Why does the value change even though the filter does not run?
The code may be using add_option(), update_site_option(), a direct SQL query, or another storage system. Also check the option name, the cron process, and the file where messages are being logged.
Is it safe to leave this MU plugin on production?
Only for a short time and with limited logging. A backtrace may contain internal class names, paths, and request context, while frequent writes increase server load. Remove the tracer after the investigation.
Conclusion
You do not need to analyze the entire database immediately when looking for unexpected option changes. A temporary pre_update_option_option_name filter can show when the write occurs and the context in which it happened.
Use tracing as a diagnostic tool: identify the component, review its logic, fix how the value is generated, and remove the MU plugin when the investigation is complete. This is more reliable than unconditionally blocking option updates and leaving the real cause hidden.