如果评论者的电子邮件基于数组匹配,则打印作者角色

问题描述 投票:0回答:1

如果评论者的电子邮件匹配,我想根据数组定义的值打印作者角色。

这里定义了配置数组。

// Get Comment

$comment = get_comment();
// Get Commenters email
$match_email = $comment->comment_author_email;


// Config arrays


$config = [
    'verified_email' => [
        '[email protected]' => [
            'role' => 'Seo Expert',
        ],
        '[email protected]' => [
            'role' => 'Manager',
        ]
    ]
];

这是foreach循环。


foreach ($config as $group => $users) {
    foreach ($users as $author => $email) {

        if (($email === $match_email) && have_comments()) {
            echo $email['role'];
            break;
        }

    }

}

如果电子邮件 ID 匹配,如何从配置数组值打印作者角色。

php wordpress multidimensional-array comments user-roles
1个回答
0
投票

根据目前的情况,我可以看到 if 里面的

$email
应该替换为
$author
:

if ($author === $match_email && have_comments()) {
            echo $email['role'];
            break;
}
© www.soinside.com 2019 - 2024. All rights reserved.