logging options table activity
-
Hi,
Does Simple History (or Simple History Premium) log calls to update_options() or delete_options()? If not, would it be possible to add that functionality?
Thanks!
-
Hi! Not at the moment – but this is something I can easily add. If you like you can send me an email at the adress found at https://simple-history.com/contact/ and later this week I should have a working version that I can send for you to test. If you have any specifics about how you would like the output of the options-logging to be just let me know!
Good to hear. We have a case of the license key of a particular paid plugin “disappearing” every few months. I believe I’ve found some code which explains it, but I’d love to “catch it in the act” so to speak by seeing a log where I found out what was deleting the option. I don’t know what you can trap, but I guess what I’m hoping to see is which option was deleted/updated, date and time, and hopefully which file executed the call to update_options/delete_options.
Might that be too many operations? I just don’t know, so maybe some way to filter that in the search (or even in the logging). Those are my preliminary ideas.
Thanks!
I think that would work fine. It will store a lot of data, but you only need to have the “options logger” enabled during the “debug period”. The logger can show a short debug backtrace to hopefully determine what caused the options to be removed/updated. Drop me an email if you would like a beta version with this functionality.
Would there be a way to filter only logging certain options or excluding options, etc. ?
Thanks.
The code is pretty much this:
Add this code to a new file and include that and modify the array in
get_options_to_log()to include the name(s) of the options you would like to track and then modifications, adds, and deletions of that option should be logged.So, once implemented, I would modify get_options_to_log() in simple-history-log-options-update.php to only log what I want – correct?
Yes, exactly. It still needs to be an array however, even if you only add one value there.
Logical.
And simple-history-log-options-update.php is part of the core of the plugin so I imagine that across plugin updates, I’ll need to maintain any changes there that I make?
It depends on how you add this file. I would not add it to any existing plugin (not even Simple History) but rather a new plugin or directly in your theme if you have a custom theme. Let me know if you need it as a separate plugin, I can quickly fix that 🙂
Ok I did create a plugin of it now instead.
Below is the update code. Just create a folder in your plugins folder, i.e.
simple-history-options-loggerand then place the file below in this folder (so you havesimple-history-options-logger/simple-history-options-logger). Then go to wp admin » plugins and activate the plugin. Then it’s not modified by other theme or plugin updates. Good luck!Wow – so generous of you!
So for this particular plugin, I’ve chosen 10 options to “monitor”. One of them is obviously being referenced by a cron job as it is showing up with a log entry every couple of minutes.
Unfortunately this is the message returned:
Option “wawp_disabled” updated from “” to “”
I looked at the code but it’s not obvious to me where it’s doing its comparison from the old to the new value and how it might interpret this as a “difference” between the old and new value.
Any ideas?
Thanks!
@dleigh Sorry for the late reply. When looking at the code again I think the reason you see “” instead of a value is most likely because the old and new values are objects or arrays. I didn’t think of that when I wrote the code. If you click the data/time of the event a modal is shown where you can see a more “raw” version of the data. See if old_value or new_value have values that are not “” there.
After some more testing I think you should change the code below comment “// Log the update” to this to prevent further problems with arrays or objects:
// Log the update.
\SimpleLogger()->info(
sprintf( 'Option "%s" updated', $option ),
[
'context' => 'options',
'option' => $option,
'old_value' => $old_value,
'new_value' => $value,
'backtrace' => $backtrace_info['trace'],
'backtrace_summary' => $backtrace_info['summary'],
]
);
The topic ‘logging options table activity’ is closed to new replies.