题
我正在写自己的插件。
这样的工作:
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;
}
想知道我该如何做到这一点 /功能?
解决方案
只需比较显示名称:
$currentuser = get_currentuserinfo();
if ( get_the_author() == $currentuser->displayname ) {
// current user is the post author; do something
}
这 get_the_author()
功能返回 displayname
, ,应该能够与 displayname
参数是 $currentuser
目的。
其他提示
您可以使用current_user和发布变量获取此信息。
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;
}