• Resolved Ole

    (@olpo24)


    Hi,
    first of all thank you for this amazing plugin.

    In the settigs there is a oiption to set “Log views from” everyone, or logged in or logged out visitors.

    I need a setting “exclude Admin and current post author”.
    Is there a way to achieve this? Maybe a filter?
    (I didn’t find anything on the github wiki)

    Kind regards,

    Ole

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Hector Cabrera

    (@hcabrera)

    Hi @olpo24,

    For this you could use the wpp_trackable_post_types filter hook to have WordPress Popular Posts track views only if the visitor is not logged in / not an admin / not the author of the current post/page. For example:

    /**
     * Don't track page views if user is an administrator
     * or if user is the author of the entry.
     *
     * @param  array $post_types
     * @return array
     */
    function maybe_do_not_track_views($post_types) {
    	if ( is_user_logged_in() ) {
    		$post_id = get_queried_object_id();
    		$current_user = wp_get_current_user();
    		$author_id = get_post_field('post_author', $post_id);
    		$current_user_is_admin = current_user_can('manage_options');
    
    		if ( $current_user_is_admin || $current_user->ID == $author_id ) {
    			return array('do_not_track');
    		}
    	}
    
    	return $post_types;
    }
    add_filter('wpp_trackable_post_types', 'maybe_do_not_track_views', 10, 1);
    Thread Starter Ole

    (@olpo24)

    Hi @hcabrera

    Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Log views from…’ is closed to new replies.