function remove_view_counter_wpse_102637() {
if ( ! empty( $_COOKIE[ USER_COOKIE . '_views' ] ) ) {
$viewed = array_map( 'intval', explode( ',', $_COOKIE[ USER_COOKIE . '_views' ] ) );
if ( in_array( $post->ID, $viewed ) )
remove_action( 'wp_head', 'process_postviews' );
}
global $post;
$current_user = wp_get_current_user();
if (
is_single()
&& !empty($current_user)
&& $post->post_author == $current_user->ID
) {
remove_action('wp_head', 'process_postviews');
}
}
add_action('wp_head', 'remove_view_counter_wpse_102637',1);
function wpse_104324_prevent_multiple_views( $meta_id, $object_id, $meta_key, $meta_value ) {
if ( $meta_key === 'views' ) {
if ( ! empty( $_COOKIE[ USER_COOKIE . '_views' ] ) )
$viewed = array_map( 'intval', explode( ',', $_COOKIE[ USER_COOKIE . '_views' ] ) );
else
$viewed = array();
$viewed[] = $object_id;
setcookie(
USER_COOKIE . '_views',
implode(
',', $viewed
),
time() + 31536000,
COOKIEPATH,
COOKIE_DOMAIN,
false,
true
);
}
}
add_action( 'updated_post_meta', 'wpse_104324_prevent_multiple_views', 10, 4 );
add_action( 'added_post_meta', 'wpse_104324_prevent_multiple_views', 10, 4 );