• Resolved gruntek

    (@gruntek)


    Hi,
    I fail to figure out how to exclude users by role. I know I need to use the filter simple_history/log/do_log, but when I look at the exaple on github I just can’t understand how to use it to exclude user role.

    May I ask for assistance here?

    Greatings,
    Adam

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author eskapism

    (@eskapism)

    Hi! Maybe something like this (I have not actual tried the code, but something like this should be the solution):

    
    <?php
    
    // Do not log actions performed by users who can edit posts.
    add_filter('simple_history/log/do_log', function ($do_log) {
    
        $current_user = wp_get_current_user();
    
        // Bail if no user found.
        if (!$current_user) {
            return $do_log;
        }
    
        // Do not log if user can edit posts.
        if ($current_user->has_cap('edit_posts')) {
            return false;
        }
    
        return $do_log;
    }, 10, 5);
    

    Hi, the code above didn’t work for me, but with the edit below it did.

    add_filter('simple_history/log/do_log', function ($do_log) {
        if ( !current_user_can('edit_posts') ) {
            return false;
        } else {
            return $do_log;
        }
        return $do_log;
    }, 10, 5);

    My only concern is how much it can spend processing, I have a site of 30,000 users and would like to record only the administrators’ edit logs.

    @eskapism can you tell if there is CPU impact on a site with so many users? thanks!

    • This reply was modified 3 years, 2 months ago by Eder Ribeiro.

    I just tested, apparently no bugs or slowdowns when implementing the plugin along with the filter above.

    thanks!

    Plugin Author eskapism

    (@eskapism)

    Good to hear you solved it and that you see no bugs or slowdowns ??.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Exclude role from logging’ is closed to new replies.