添加用户时不同用户角色的不同用户自定义字段

Different User custom fields for different user roles at add user time

我在我的 wordpress 网站中创建了各种用户角色。

我想根据特定用户角色添加额外的自定义字段。

例如,如果用户角色是律师,则 "state" 字段会在添加和更新时添加到用户。

我已经为此创建了自定义字段 "state" 并且 selected 用户等于 lawyer.But 此状态字段仅在更新时出现。

我想在添加用户时添加此字段,当用户 select 角色律师时,此字段需要在添加用户和更新用户时显示。

我需要为此添加 ACF PRO 版本吗?我现在用的是ACF基础版。请指教如何实现它?

请检查这个钩子。

add_action('show_user_profile', 'my_add_extra_profile_fields');
function my_add_extra_profile_fields($user) 
{
  if ($user->has_cap('subscriber'))
  {
     //Code here
  }
}