File: /home/frenchy/www/_trash/wp-content/themes/biig/functions/admin.inc.php
<?php
/* ########################
Admin / login : ajout de la favicon client
*/
add_action('login_head', 'add_favicon');
add_action('admin_head', 'add_favicon');
function add_favicon()
{
$favicon_url = get_template_directory_uri() . '/images/favicons/favicon.ico';
echo '<link rel="shortcut icon" href="' . $favicon_url . '" />';
}
// Ajoute le symbol SVG en admin pour que les pictos apparaissent dans les blocs Gutenberg
function add_svg_symbols_to_admin()
{
get_template_part('assets/svg/symbols.svg');
}
add_action('admin_footer', 'add_svg_symbols_to_admin', 1);
/* ########################
Suppression des commentaires
*/
add_filter('comments_open', function ($open, $post_id) {
$post = get_post($post_id);
if ('post' == $post->post_type) {
$open = false;
}
return $open;
}, 10, 2);
/* ########################
Gestion du contenu et de l'ordre des items de la sidebar d'admin
*/
// add_filter('custom_menu_order', '__return_true');
// add_filter('menu_order', function ($menu_ord) {
// if (!$menu_ord) {
// return true;
// }
// return array(
// 'index.php', // Dashboard
// 'separator1', // First separator
// 'edit.php?post_type=page', // Pages
// 'edit.php', // Posts
// 'edit-comments.php', // Comments
// 'separator2', // Second separator
// 'upload.php', // Media
// 'options-general.php', // Settings
// 'users.php', // Users
// 'themes.php', // Appearance
// 'plugins.php', // Plugins
// 'tools.php', // Tools
// 'separator-last', // Last separator
// );
// });
// Custom des colonnes dans la liste des CPT Comité Exécutif
// Cf doc : https://www.smashingmagazine.com/2017/12/customizing-admin-columns-wordpress/
add_filter('manage_personne_posts_columns', 'filter_posts_columns');
function filter_posts_columns($columns)
{
$columns = array(
'cb' => $columns['cb'],
'nom' => __('Nom'),
'prenom' => __('Prénom'),
'role' => __('Rôle'),
'equipe' => __('Équipe'),
'photo' => __('Photo')
);
return $columns;
}
// Remplit les colonnes avec les valeurs dans la liste des CPT Comité Exécutif
add_action('manage_personne_posts_custom_column', 'personne_column', 10, 2);
function personne_column($column, $post_id)
{
if ('nom' === $column) {
echo get_field('nom_personne', $post_id);
}
if ('prenom' === $column) {
echo get_field('prenom_personne', $post_id);
}
if ('photo' === $column) {
$visuel = get_field('photo_personne', $post_id);
$size = 'thumbnail';
$thumb = $visuel['sizes'][$size];
$width = $visuel['sizes'][$size . '-width'];
$height = $visuel['sizes'][$size . '-height'];
echo '<img src="' . $thumb . '" width="' . $width . '" height="' . $height . '" />';
}
if ('equipe' === $column) {
$terms = get_the_terms($post_id, 'equipes');
foreach ($terms as $term) {
echo $term->name;
}
}
if ('role' === $column) {
echo get_field('fonction_personne', $post_id);
}
}
// Filtre du CPT Personne selon la taxonomie
function filter_personne_by_taxonomies($post_type, $which)
{
// Apply this only on a specific post type
if ('personne' !== $post_type)
return;
// A list of taxonomy slugs to filter by
$taxonomies = array('equipes');
foreach ($taxonomies as $taxonomy_slug) {
// Retrieve taxonomy data
$taxonomy_obj = get_taxonomy($taxonomy_slug);
$taxonomy_name = $taxonomy_obj->labels->name;
// Retrieve taxonomy terms
$terms = get_terms($taxonomy_slug);
// Display filter HTML
echo "<select name='{$taxonomy_slug}' id='{$taxonomy_slug}' class='postform'>";
echo '<option value="">' . sprintf(esc_html__('Toutes les équipes', 'wpstartertheme'), $taxonomy_name) . '</option>';
foreach ($terms as $term) {
printf(
'<option value="%1$s" %2$s>%3$s (%4$s)</option>',
$term->slug,
((isset($_GET[$taxonomy_slug]) && ($_GET[$taxonomy_slug] == $term->slug)) ? ' selected="selected"' : ''),
$term->name,
$term->count
);
}
echo '</select>';
}
}
add_action('restrict_manage_posts', 'filter_personne_by_taxonomies', 10, 2);