• Resolved dleigh

    (@dleigh)


    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!

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Pär Thernström

    (@eskapism)

    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!

    Thread Starter dleigh

    (@dleigh)

    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!

    Plugin Author Pär Thernström

    (@eskapism)

    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.

    Thread Starter dleigh

    (@dleigh)

    Would there be a way to filter only logging certain options or excluding options, etc. ?

    Thanks.

    Plugin Author Pär Thernström

    (@eskapism)

    The code is pretty much this:

    https://gist.github.com/bonny/bbef255345b03df48c7a4828b7eba758

    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.

    Thread Starter dleigh

    (@dleigh)

    So, once implemented, I would modify get_options_to_log() in simple-history-log-options-update.php to only log what I want – correct?

    Plugin Author Pär Thernström

    (@eskapism)

    Yes, exactly. It still needs to be an array however, even if you only add one value there.

    Thread Starter dleigh

    (@dleigh)

    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?

    Plugin Author Pär Thernström

    (@eskapism)

    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 🙂

    Plugin Author Pär Thernström

    (@eskapism)

    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-logger and then place the file below in this folder (so you have simple-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!

    https://gist.github.com/bonny/29e0818051525b1a4f52c75a58244a3c

    Thread Starter dleigh

    (@dleigh)

    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!

    Plugin Author Pär Thernström

    (@eskapism)

    @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.

    Plugin Author Pär Thernström

    (@eskapism)

    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'],
    ]
    );
Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘logging options table activity’ is closed to new replies.