Show info to author only 时间:2011-05-14 作者:greenbandit 我正在编写自己的插件。工作原理如下: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; } 想知道我怎样才能做到这一点? 2 个回复 最合适的回答,由SO网友:Chip Bennett 整理而成 只需比较显示名称:$currentuser = get_currentuserinfo(); if ( get_the_author() == $currentuser->displayname ) { // current user is the post author; do something } Theget_the_author() 函数返回displayname, 应该能够与displayname 参数,该参数是$currentuser 对象 SO网友:aaronwaggs 您可以使用current\\u user和post变量获取此信息。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; } 结束 文章导航