我有一个帖子类型,可以插入电子邮件作为帖子。我还根据这些电子邮件创建了用户。这就是我添加帖子类型的方式。
$post_array = array(
\'post_content\' => $mail[\'body\'],
\'post_title\' => $mail[\'header\']->subject,
\'post_type\' => \'my-post-type\',
\'post_author\' => $user_name,
\'post_status\' => \'publish\',
\'meta_input\' => array(
\'User\' => ucwords(strstr($mail[\'header\']->fromaddress, \'<\',true)),
\'From\' => preg_replace(\'~[<>]~\', \'\', strstr($mail[\'header\']->fromaddress, \'<\')),
\'Email\' => $mail[\'header\']->Date,
\'ticket_id\' => preg_replace(\'~[<]~\',\'\',strstr($mail[\'header\']->message_id, \'@\',true)),
),
);
wp_insert_post( $post_array );
这就是我添加用户的方式:
if(email_exists($email)){
add_post_meta($post_id, \'username\', $email, True);
add_post_meta($post_id, \'email\', $user, True);
}
else{
$userdata = array(
\'user_login\' => ucwords(strstr($mail[\'header\']->fromaddress, \'<\',true)),
\'user_pass\' => \'\',
\'user_nicename\' => ucwords(strstr($mail[\'header\']->fromaddress, \'<\',true)),
\'display_name\' => ucwords(strstr($mail[\'header\']->fromaddress, \'<\',true)),
\'user_email\' => strstr($mail[\'header\']->fromaddress, \'<\'),
\'role\' => \'support_customer\',
);
wp_insert_user($userdata);
}
下面是我如何添加用户角色的代码:
$result= add_role(\'support_customer\', __(
\'Support Customer\', \'faqpress\'),
array(
\'read\' => true, // true allows this capability
\'edit_posts\' => true,
\'delete_posts\' => true, // Use false to explicitly deny
\'publish_posts\' => true,
));
现在,我希望帖子的作者与我刚才创建的用户相同。我如何做到这一点?