The latest version of simple history added the filter simple_history/log/do_log that can be used to “shortcut” the logging. If you add that filter in the beginning of your update-script it can skip logging all your updates.
Let me know if you need further help with the filter. And please also let me know if you solve it using the filter or any other method 🙂
Hi Pär
My script saves users with wp_insert_user, here is a part of the code.
// Merge data
$userdata = array_merge($userdata, $add_userdata);
// Save/Update user
$do_user_id = wp_insert_user( $userdata );
// If error
if (is_wp_error( $do_user_id )) {
_savetolog( $userdata, null, 'error' );
_savetolog( $do_user_id, null, 'error' );
continue;
}
How can I add simple_history/log/do_log to only log add user but not update user? Or if it’s not possible, how do I add shortcode to disable log on wp_insert_user?
I think I just found a small bug in that filter, but when the next version of Simple History is released you should be able to use this litte snippet. Add it before your merge-data-code above (if your code is in a loop you should probably add this before you start looping):
// Prevent logging of anything using the "User Logger"
add_action( "simple_history/log/do_log", function( $doLog, $level = null, $message = null, $context = null, $loggerInstance ) {
if ( isset( $loggerInstance->slug ) && $loggerInstance->slug == "SimpleUserLogger" ) {
$doLog = false;
}
return $doLog;
}, 10, 5 );
Hi again,
I just released version 2.4 of Simple History. Now you should be able to use the code above and all user edits should be skipped/not logged.
Let me know if it works! 🙂
Hi Pär,
I tried but it didn’t work. The final code had to be changed to add_filter not add_action. I also had to adapt this to custom post type so here is the solution and it works.
add_filter( "simple_history/log/do_log", function( $doLog, $level = null, $message = null, $context = null, $loggerInstance ) {
$doLog = false;
return $doLog;
}, 10, 5 );
Thanks!
Hi Pär
It didn’t work. I had to change to add_filter instead of add_action, but I think it was a typing error from you :). I also had to adapt this filter to a custom post type insert so the final code looks like this.
add_filter( "simple_history/log/do_log", function( $doLog, $level = null, $message = null, $context = null, $loggerInstance ) {
$doLog = false;
return $doLog;
}, 10, 5 );
Thanks!
Hi Pär,
It didn’t work, I think it was a typing error. I had to change to add_filter insted of add_action. I also had to adapt filter to a custom post type insert so the final code looks like this.
add_filter( "simple_history/log/do_log", function( $doLog, $level = null, $message = null, $context = null, $loggerInstance ) {
$doLog = false;
return $doLog;
}, 10, 5 );
Thanks!
Hi Pär,
It didn’t work, I think it was a typing error. I had to change to add_filter insted of add_action. I also had to adapt filter to a custom post type insert so the final code looks like this.
add_filter( "simple_history/log/do_log", function( $doLog, $level = null, $message = null, $context = null, $loggerInstance ) {
$doLog = false;
return $doLog;
}, 10, 5 );
Thanks!
Hi Pär,
It didn’t work, I think it was a typing error. I had to change to add_filter insted of add_action. I also had to adapt filter to a custom post type so I return false without any exeptions.
Thanks!
Ok, but you managed to disable the logging during the user import? In that case I’m setting this thread to resolved! 🙂