0

I am looking to display content based on multiple different user roles.

So, if a user has the role subscriber + one of other roles, the content will display, if no, other message will display. I need to display multiple badges at My Account page (mytheme>woocommerce>myaccount>dashboard.php) based on user's roles secondary roles.

At the moment, I have this code, but doesn't work:

<?php

//* Role de SU

//* Roles needed
//* 'su_biblioteca_das_sombras', 
//* 'su_escudo_mc_para_tocado',
//* 'su_informante',
//* 'su_mc',
//* 'su_mc_tocado', 
//* 'mc_tocado_de_sombras_urbanas',
//* 'su_mc_da_faccao',
//* 'su_mc_de_sombras_urbanas',
//* 'su_marcas_da_corrupcao'
//* 'su_marque_corrupcao',
//* 'su_membro_das_sombras',
//* 'su_precursor_das_sombras',
//* 'su_renomado_nas_sombras',
//* 'rs_ruas_sombrias',
//* 'rs_ruas_sombrias_virtual',
//* 'sombras_urbanas',
//* 'su_tocado_informante',
//* 'su_tocado_renomado_das_sombras',
//* 'su_tocado_pelas_sombras',
//*
//* echo '<img src="'; 
//* echo get_template_directory_uri();
//* echo '/images/sombrasurbanas1.jpg" Title="Você participou do FC de Sombras Urbanas!" />';

global $user_login, $current_user;
    $user_info = array(
        'customer'
    );
    $roles = array (
        'su_biblioteca_das_sombras',
    );

if (array_intersect( $roles, $user_info)) {

echo 'success';

} else {

echo 'failure';

}

?>

Edit: I have a new code, but still doesn't work:

<?php

//* Role de SU

global $user_login, $current_user;

    get_currentuserinfo();

$user = wp_get_current_user();

if ( in_array( 'sombras_urbanas', (array) $user->roles ) ) {
        echo 'teste';
    } else {
        echo '';
    }

?>
  • From your code, you don't use any of the current_user roles or data. Your roles are hardcoded in arrays. Is it full? – Mtxz Oct 13 '18 at 15:36
  • Yes. I'm not a developer, but I'm trying to do this based on informations from web and a small knowledge of Wordpress. – Eva Morrissey Oct 16 '18 at 00:44

0 Answers0