131 lines
3.8 KiB
PHP
131 lines
3.8 KiB
PHP
<?php
|
|
/* ---------------------------
|
|
ADMIN STYLES
|
|
---------------------------*/
|
|
|
|
// Amin Stylesheet
|
|
function metiers_du_patrimoine_custom_admin_stylesheet()
|
|
{
|
|
wp_enqueue_style('admin_styles', get_stylesheet_directory_uri() . '/css/admin-style.css');
|
|
}
|
|
|
|
add_action('admin_head', 'metiers_du_patrimoine_custom_admin_stylesheet');
|
|
|
|
/* ---------------------------
|
|
COMMENTS REMOVAL
|
|
---------------------------*/
|
|
|
|
function metiers_remove_meta_boxes()
|
|
{
|
|
# Removes meta from Posts #
|
|
// remove_meta_box('postexcerpt', 'post', 'normal');
|
|
// remove_meta_box('postcustom', 'post', 'normal');
|
|
// remove_meta_box('trackbacksdiv', 'post', 'normal');
|
|
remove_meta_box('commentstatusdiv', 'page', 'normal');
|
|
remove_meta_box('commentsdiv', 'page', 'normal');
|
|
remove_post_type_support('artisans', 'comments');
|
|
remove_post_type_support('chantiers', 'comments');
|
|
}
|
|
add_action('admin_init', 'metiers_remove_meta_boxes');
|
|
|
|
|
|
|
|
|
|
/* ---------------------------
|
|
CUSTOM POST STATUS
|
|
---------------------------*/
|
|
|
|
function custom_post_status()
|
|
{
|
|
register_post_status('offline', array(
|
|
'label' => _x('offline', 'post'),
|
|
'public' => true,
|
|
'exclude_from_search' => false,
|
|
'show_in_admin_all_list' => true,
|
|
'show_in_admin_status_list' => true,
|
|
'label_count' => _n_noop('Unread (%s)', 'Unread (%s)'),
|
|
));
|
|
}
|
|
add_action('init', 'custom_post_status');
|
|
|
|
|
|
|
|
function add_to_post_status_dropdown()
|
|
{
|
|
global $post;
|
|
|
|
// Ajoute une option 'offline' au menu déroulant des statuts
|
|
echo "<script>
|
|
jQuery(document).ready(function() {
|
|
jQuery('select[name=\"post_status\"]').append('<option value=\"offline\">offline</option>');
|
|
";
|
|
// Vérifie si le statut du post actuel est 'offline' et le pré-sélectionne
|
|
if ($post->post_status === 'offline') {
|
|
echo "jQuery('#post-status-display').text('offline');
|
|
jQuery('select[name=\"post_status\"]').val('offline');";
|
|
}
|
|
echo "
|
|
});
|
|
</script>";
|
|
}
|
|
add_action('post_submitbox_misc_actions', 'add_to_post_status_dropdown');
|
|
|
|
|
|
// Ajouter un filtre pour afficher les posts avec le statut 'offline'
|
|
add_filter('views_edit-artisans', function ($views) {
|
|
global $wpdb;
|
|
|
|
$post_type = 'artisans';
|
|
$status = 'offline';
|
|
|
|
// Compte le nombre de posts avec le statut 'offline'
|
|
$count = $wpdb->get_var($wpdb->prepare(
|
|
"SELECT COUNT(*) FROM $wpdb->posts WHERE post_type = %s AND post_status = %s",
|
|
$post_type,
|
|
$status
|
|
));
|
|
|
|
if ($count > 0) {
|
|
$class = (isset($_GET['post_status']) && $_GET['post_status'] === $status) ? 'current' : '';
|
|
$views[$status] = sprintf(
|
|
'<a href="edit.php?post_type=%s&post_status=%s" class="%s">%s <span class="count">(%d)</span></a>',
|
|
$post_type,
|
|
$status,
|
|
$class,
|
|
__('Offline', 'metiers-patrimoine-theme'),
|
|
$count
|
|
);
|
|
}
|
|
|
|
return $views;
|
|
});
|
|
|
|
|
|
|
|
|
|
// Ajouter un statut personnalisé dans la colonne des statuts, uniquement dans la vue "Tous"
|
|
function add_custom_post_status($post_states, $post)
|
|
{
|
|
// Vérifier si on est dans l'admin et si le post appartient au CPT 'artisans'
|
|
if ('artisans' === $post->post_type) {
|
|
global $pagenow;
|
|
|
|
// Vérifier si on est sur la page d'index des articles (Tous les articles)
|
|
if ('edit.php' === $pagenow && !isset($_GET['post_status'])) {
|
|
|
|
// Ajouter le statut "Publié" si l'article est publié
|
|
if ('publish' === $post->post_status) {
|
|
$post_states[] = __('Publié', 'metiers-patrimoine-theme'); // Affiche "Publié"
|
|
}
|
|
|
|
// Ajouter votre statut personnalisé (ex : "offline") si c'est le cas
|
|
if ('offline' === get_post_status($post->ID)) {
|
|
$post_states[] = __('Offline', 'metiers-patrimoine-theme'); // Affiche "En attente"
|
|
}
|
|
}
|
|
}
|
|
|
|
return $post_states;
|
|
}
|
|
add_filter('display_post_states', 'add_custom_post_status', 10, 2);
|