1

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?

| improve this question | | | | |
1

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.

| improve this answer | | | | |
1

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; 
}
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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