Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

if ( is_user_logged_in() ) {
    echo 'Hello ' . wp_get_current_user()->display_name;
}
share|improve this answer
    
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? –  whiteletters and blankspaces Jun 26 '13 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? –  TheDeadMedic Jun 26 '13 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. –  whiteletters and blankspaces Jun 26 '13 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? –  TheDeadMedic Jun 26 '13 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. –  TheDeadMedic Jun 26 '13 at 11:48
show 4 more comments

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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