post
Criar uma lista de usuarios para login rapido com User Switching, ACF e WordPress
Publicado em: 02/11/2022
Abaixo um exemplo de código usando os plugins User Switching e ACF PRO para trazer usuários relacionados a outro usuário:
<?php $array_clientes_rep = get_field('usuarios_do_representante', 'user_'. get_current_user_id()); //var_dump($array_clientes_rep); //echo json_encode($array_clientes_rep); if ( method_exists( 'user_switching', 'get_old_user' ) ) { $old_user = user_switching::get_old_user(); if ( $old_user ) { printf( '<a class="et_pb_button et_hover_enabled" href="%1$s">Voltar para %2$s</a>', esc_url( user_switching::switch_back_url( $old_user ) ), esc_html( $old_user->display_name ) ); } } if($array_clientes_rep[0]) { ?> <p> <strong>Clientes relacionados:</strong> </p> <?php foreach($array_clientes_rep as $cliente_rep) { ?> <div class="box_cliente_rep"> <div class="box_cliente_rep_icone"> <i class="fa-regular fa-user" style="font-family: FontAwesome;font-style: normal;"></i> </div> <div class="box_cliente_rep_info"> <p> <span class="nome"><?= $cliente_rep['user_firstname'] ?></span> <br> <span class="email"><?= $cliente_rep['nickname'] ?></span> </p> </div> <div class="box_cliente_rep_login"> <?php if ( method_exists( 'user_switching', 'maybe_switch_url' ) ) { $url = user_switching::maybe_switch_url( get_user_by( 'id', $cliente_rep['ID'] ) ); if ( $url ) { printf( '<a href="%1$s">Logar</a>', esc_url( $url ), esc_html( $target_user->display_name ) ); } } ?> </div> </div> <style> .box_cliente_rep { display: flex; align-items: center; border-radius: 8px; background: #fff; box-shadow: 0 10px 10px rgb(0 0 0 / 7%); margin: 10px auto; padding: 10px 20px; border: 1px solid #eee; } .box_cliente_rep > div:nth-child(1) { width: 8%; } .box_cliente_rep > div:nth-child(2) { width: 82%; } .box_cliente_rep > div:nth-child(3) { width: 10%; } .box_cliente_rep_info .nome { font-weight: bold; } .box_cliente_rep_info { font-size: 12px; line-height: 18px; } </style> <?php } } ?> <style> #user_switching_switch_on { display: none !important; } </style>
Configurações do campo no ACF:


Link de compartilhamento
Compartilhe esse conteudo nas redes sociais ou por mensagem usando o link curto abaixo. Basta clicar em cima do link para copiar.
bruno.art.br/pb/2112
ID de Referência: 2112
Sugira uma publicação
Envie uma mensagem para mim, e sugira alguma publicação de algum tema que tenha dificuldades de resolver.