Redirecionamento de usuários e funções de usuários WordPress

Picture of Ivon Filho

Ivon Filho

Procurando desenvolvedor freelancer para seu projeto?

<?php
 if ( is_user_logged_in() ) {
//echo "";
}
else { 
//echo do_shortcode( '[woocommerce_my_account ]' );
}
?>

A:

<?php if(current_user_can('editor')) { ?> 
    <!-- Stuff here for editors -->
<?php } ?>

<?php if(current_user_can('administrator')) { ?>
    <!-- Stuff here for administrators -->
<?php } ?>

B:

<?php if( current_user_can('editor') || current_user_can('administrator') ) {  ?>
    // Stuff here for administrators or editors
<?php } ?>

C:

$user = wp_get_current_user();
$allowed_roles = array('editor', 'administrator', 'author');
<?php if( array_intersect($allowed_roles, $user->roles ) ) {  ?>
   // Stuff here for allowed roles
<?php } ?>

D:

<?php if( current_user_can('edit_others_pages') ) {  ?>
    // Stuff here for user roles that can edit pages: editors and administrators
<?php } ?>

Referência: https://wordpress.stackexchange.com/questions/131814/if-the-current-user-is-an-administrator-or-editor

Rolar para cima