下面是一个代码段,它将作者角色分配给电子邮件为[email protected]您需要修改哪些内容以满足您的需要:
add_action( \'user_register\', \'user_register_cb\', 10, 1 );
function user_register_cb( $user_id ){
$user_info = get_userdata( $user_id );
$email = $user_info->user_email;
$domain = \'.co.uk\';
$pos = strpos( $email, $domain );
if( $pos === 0 ){
// You can assign any other role
}else{
$user_info->set_role( \'author\' );
}
}
您可以在函数中添加这些代码。php的主题,如果你认为你的主题不会改变。否则,mu插件是最好的解决方案。要使用mu插件,请转到/wp-content/并找到名为“mu-plugins”的文件夹。如果该名称中没有文件夹,则创建一个文件夹,将其命名为“mu plugins”,在其中创建一个文件,给出任何您喜欢的名称并将代码粘贴到其中。您不需要激活该插件。Mu插件意味着必须使用插件,因此它将始终自动激活。如果您使用mu插件,那么在代码的开头添加一个php开始标记。