回到那天,我写了一个函数来检查它(你可以把它放在functions.php 并从您的页面中调用):
public function check_if_user_is_author($user_id, $post_id) {
global $wpdb;
$res = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->posts ." WHERE ID = %d AND post_author = %d LIMIT 1", $post_id, $user_id));
if(isset($res) && count($res) > 0) {
return $res[0];
} else {
return false;
}
}
此外,理论上,您只需获取post对象,并将作者ID与当前登录的用户ID进行比较。免责声明:以下代码未经测试。
$current_user_id = get_current_user_id();
$post_data = get_post($your_att_id, ARRAY_A);
$author_id = $post_data[\'post_author\'];
if( $current_user_id == $author_id ) {
// good, current logged-in user is author of attachment
}