0

Thank you in advance for your time.

I want to perform the following conditonal if:

if (current user didnt log out and is in the same login session )

{
Do_something;
}

How to express it using Codex functions? I want to add it to the following if but in vain.

if (
    is_single() 
    && !empty($current_user)
    && $post->post_author == $current_user->ID
  ) {
    remove_action('wp_head', 'process_postviews');
  }

Your usual help is always appreciated.

2 Answers 2

1
if ( is_user_logged_in() ) {
    echo 'Hello ' . wp_get_current_user()->display_name;
}
8
  • Thank you for your quick feedback to my post. In fact, I already use the if statement you provided since my website is already a private community. The problem I have is that I am using a plugin that displays post number of views and it is incremented even if the same user refreshes the page. Could you please check the attached link? Commented Jun 26, 2013 at 11:27
  • Your code snippet & your question are trying two different things. Do you want to ensure that one user = one view, regardless how many times they refresh? Or do you want to exclude view counts by the author of the post? Commented Jun 26, 2013 at 11:35
  • I want to ensure one user = one view, during one login. Excluding view counts by the author is already performed thanks to S_HA_DUM answer in linked post. In that hack we used remove_action. Commented Jun 26, 2013 at 11:36
  • Then you'll need a bit more logic than simply removing the action. Can you link to the plugin you're using? Commented Jun 26, 2013 at 11:38
  • 1
    This really warrants a new question. I suggest something like "WP Postviews - Prevent multiple counts by same user", then briefly explain your situation in a little more detail & link to the plugin. Commented Jun 26, 2013 at 11:48
0

the solution to this issue is in the link below, provided by TheDeadMedic. It uses the cookies principle and some array management.

Prevent multiple counts by same user - WP PostViews plugin

Note that the there are linked posts to this post, that can be helpful to understand the whole situation.

Good luck.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.