88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php
|
|
function custom_dashboard_widget()
|
|
{
|
|
|
|
// get user name
|
|
$current_user = wp_get_current_user();
|
|
$user_name = $current_user->user_login;
|
|
wp_add_dashboard_widget(
|
|
'advisor-dashboard-widget', // ID du widget
|
|
'Dashboard Personnel ', // Titre
|
|
'custom_dashboard_widget_display' // Fonction d'affichage
|
|
);
|
|
}
|
|
|
|
function custom_dashboard_widget_display()
|
|
{
|
|
$current_user = wp_get_current_user();
|
|
$user_name = $current_user->user_login;
|
|
|
|
|
|
|
|
$args = array(
|
|
'post_type' => 'artisans',
|
|
'meta_key' => 'conseiller',
|
|
'meta_value' => $current_user->ID,
|
|
'posts_per_page' => -1
|
|
);
|
|
|
|
$user_attached_artisans = new WP_Query($args);
|
|
|
|
|
|
|
|
$required_actions_artisans = new WP_Query(
|
|
array(
|
|
'post_type' => 'artisans',
|
|
'meta_key' => 'conseiller',
|
|
'meta_value' => $current_user->ID,
|
|
'meta_query' => array(
|
|
array(
|
|
'key' => 'required_action',
|
|
'value' => true,
|
|
'compare' => '='
|
|
)
|
|
),
|
|
'posts_per_page' => -1
|
|
)
|
|
);
|
|
|
|
?>
|
|
<h3>Bonjour <?php echo $user_name ?> !</h3>
|
|
<div class="total-attached">
|
|
<p> Artisans associés : <?php echo count($user_attached_artisans->posts) ?></p>
|
|
</div>
|
|
<div class="required-actions">
|
|
<?php
|
|
$total = count($required_actions_artisans->posts);
|
|
?>
|
|
<?php if ($total == 0) : ?>
|
|
<p>Aucun artisan en attente d'action</p>
|
|
"count"><?php echo $total ?></span> action requise </h4>
|
|
<?php else : ?>
|
|
<h4>Actions requises<span class="count">(<?php echo $total ?>)</span></h4>
|
|
<?php endif; ?>
|
|
|
|
<ul>
|
|
<?php foreach ($required_actions_artisans->posts as $index => $artisan) : ?>
|
|
<?php if ($index >= 4) break; ?>
|
|
|
|
<?php $mdp_status = get_field('mdp_status', $artisan->ID);
|
|
write_log($mdp_status);
|
|
?>
|
|
<li>
|
|
<a href="<?php echo get_edit_post_link($artisan->ID) ?>">
|
|
<?php echo $artisan->post_title ?>
|
|
</a>
|
|
<span class="status-state status-state--<?php echo $mdp_status['value'] ?>"><?php echo $mdp_status['label'] ?></span>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
|
|
<a class="cta cta--button" href="<?php echo home_url('/wp-admin/admin.php?page=mdp-dashboard') ?>">Pannel de gestion</a>
|
|
<?php
|
|
}
|
|
|
|
// Ajouter le widget au tableau de bord
|
|
add_action('wp_dashboard_setup', 'custom_dashboard_widget');
|