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.

I'm writing my own plugin.

works like this:

function myfunc (){
    $a = 'hello';
    // the sentence what Am looking for: 
    if ( user is logged and is the author of current post / page ){
        $a= 'author';
    }
    return $a; 
}

Wondering how I can do that sencence / function?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Just compare display names:

$currentuser = get_currentuserinfo();

if ( get_the_author() == $currentuser->displayname ) {
     // current user is the post author; do something
}

The get_the_author() function returns displayname, which should be able to be compared against the displayname parameter that is a part of the $currentuser object.

share|improve this answer
    
Thank you!, it works like a charm! –  greenbandit May 14 '11 at 22:35
    
Happy to help ! –  Chip Bennett May 14 '11 at 22:37
add comment

You can get this information using the current_user and post variables.

function myfunc (){
    global $current_user, $post;
    $a = 'hello';
    // check if current user id matches post author id
    if ( $current_user->ID == $post->post_author ){
        $a = 'author';
    }
    return $a; 
}
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.