$display_name = get_the_author_meta('display_name');
$config = array(
'premium_users' => [
'rahat' => [
'color' => 'blue',
'icon' => 'fa-check-circle'
],
'jondoe' => [
'color' => 'orange',
'icon' => 'fa-check'
]
],
'secondary_users' => [
'smith' => [
'color' => 'purple',
'icon' => 'fa-check'
]
],
);
$verified_author = "";
foreach ($config as $group => $users) {
foreach ($users as $author => $data) {
if ($author === $display_name && $group === 'premium_users') {
$verified = '<'.$wrap.' class="i-'.$data['icon'].' '.
$data['color'].'"></'.$wrap.'>';
echo $verified_author;
break;
}
}
if($group === 'premium_users') {
echo $group;
}
I want to Echo all users list with premium_user if [‘premium_users’] defined.
Please modify this function. Get value from config if defined [premium_user] then echo all users that have premium or secondary user.
2
Answers
Your user information is 2 levels deep into your config array and your foreach loop is checking level 1 of the array. Change your loop to this…
Loop over the first level’s elements and use the same lookup technique with
isset()
.