I did not test the following code, 但它应该做你想做的事(或者至少为你指明正确的方向)。
function captains_user_row_actions($actions, $user) {
// remove the ability to edit a non-team-member
$cap_team_id = get_user_meta(wp_get_current_user()->ID, \'team-meta\', true);
$user_team_id = get_user_meta($user->ID, \'team-meta\', true);
if (\'users.php\' === $GLOBALS[\'pagenow\'] && $cap_team_id !== $user_team_id)
unset($actions[\'edit\']);
return $actions;
}
add_action(\'user_row_actions\', \'captains_user_row_actions\', 10, 2);
// EDIT将以下内容添加到
functions.php
还要处理直接编辑的文件:
function my_captain_func() {
$cap_team_id = get_user_meta(wp_get_current_user()->ID, \'team-meta\', true);
$user_team_id = get_user_meta($_GET[\'user_id\'], \'team-meta\', true);
if ($cap_team_id !== $user_team_id && ! current_user_can(\'edit_pages\')) {
wp_redirect(admin_url()); // or wherever you like
exit;
}
}
if (\'user-edit.php\' === $GLOBALS[\'pagenow\'])
add_action(\'wp_loaded\', \'my_captain_func\');