• Resolved marikamitsos

    (@marikamitsos)


    Hello,

    We followed the code on this post and we now get all visitors logged including bots.

    How could we alter the code so as to have pages/posts viewed ONLY by logged-in users leaving out admins bots as well as complete strangers?

    Thank you in advance for your great work
    marikamitsos

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter marikamitsos

    (@marikamitsos)

    We figured it out and posting it here in case anyone else needs the code.

    // Simple History: Log page/post views ONLY by non-admin users
    add_action('wp_footer', function() {
        // Do not log non logged users (visitors or bots) or admins
        if (!is_user_logged_in() || current_user_can('edit_users')) {
            return;
        }
    
        // Log both page and post views as well
        // is_singular https://developer.ww.wp.xz.cn/reference/functions/is_singular/
        if (is_singular()) {
            apply_filters('simple_history_log_info', 'A user viewed the page/post "{page_title}"', [
                'page_title' => get_the_title()
            ]);
        }
    });

    Enjoy

    • This reply was modified 7 years, 7 months ago by marikamitsos.
    Plugin Author Pär Thernström

    (@eskapism)

    Great to hear that you solved it + thanks a lot for sharing your solution!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Log ONLY logged-in users (except admins)’ is closed to new replies.