working on metaboxes

This commit is contained in:
Antoine M 2025-02-18 11:21:50 +01:00
parent f4f65f0245
commit 848c8a7a37

View File

@ -159,9 +159,9 @@ function metiers_new_admin_menu_order($menu_order)
$new_positions = array(
'edit.php?post_type=artisans' => 3,
'edit.php?post_type=chantiers' => 4,
'edit.php?post_type=page' => 6,
'upload.php' => 7,
'export_datas' => 8,
'edit.php?post_type=page' => 7,
'upload.php' => 8,
'export_datas' => 9,
'theme-general-settings' => 11,
'rank-math' => 20,
);
@ -185,3 +185,119 @@ add_action('admin_menu', function () {
add_filter('menu_order', 'metiers_new_admin_menu_order');
add_filter('custom_menu_order', '__return_true');
});
function hide_meta_boxes_by_default()
{
// List of meta boxes to hide by default
$hidden_meta_boxes = array(
'post' => array(
'postexcerpt', // Excerpt
'trackbacksdiv', // Trackbacks
'postcustom', // Custom Fields
'commentstatusdiv', // Discussion
'commentsdiv', // Comments
'authordiv', // Author
'slugdiv' // Slug
),
'page' => array(
'postexcerpt', // Excerpt
'trackbacksdiv', // Trackbacks
'postcustom', // Custom Fields
'commentstatusdiv', // Discussion
'commentsdiv', // Comments
'authordiv', // Author
'slugdiv' // Slug
)
);
// Get the current user ID
$user_id = get_current_user_id();
// Get the hidden meta boxes for the current user
$hidden = get_user_meta($user_id, 'metaboxhidden_post', true);
// Merge the existing hidden meta boxes with the new ones
$hidden = array_unique(array_merge((array) $hidden, $hidden_meta_boxes['post']));
// Update the user meta with the new hidden meta boxes
update_user_meta($user_id, 'metaboxhidden_post', $hidden);
// Repeat for pages
$hidden = get_user_meta($user_id, 'metaboxhidden_page', true);
$hidden = array_unique(array_merge((array) $hidden, $hidden_meta_boxes['page']));
update_user_meta($user_id, 'metaboxhidden_page', $hidden);
}
// Hook the function to the admin_init action
// add_action('admin_init', 'hide_meta_boxes_by_default');
function hide_wpml_language_metabox()
{
// Supprime la meta box "Langue" de WPML dans l'éditeur de post
remove_meta_box('icl_div', 'post', 'side');
remove_meta_box('icl_div', 'page', 'side');
// Ajoutez d'autres types de post si nécessaire
}
// Applique la fonction pour masquer la meta box "Langue"
// add_action('admin_menu', 'hide_wpml_language_metabox');
function add_user_role_to_admin_body_class($classes)
{
$current_user = wp_get_current_user();
if (!empty($current_user->roles)) {
foreach ($current_user->roles as $role) {
$classes .= ' role-' . $role;
$classes .= ' salut fred';
}
}
return $classes;
}
// Applique le filtre pour ajouter la classe au corps de l'interface admin
add_filter('admin_body_class', 'add_user_role_to_admin_body_class');
function add_custom_taxonomy_menu_item()
{
add_menu_page(
'Métiers', // Titre de la page dans le navigateur
'Métiers', // Texte à afficher dans le menu
'edit_others_posts', // Capacité requise pour voir le menu
'edit-tags.php?taxonomy=metiers&post_type=artisans', // URL de la taxonomie
'', // Pas de fonction de rappel, car nous redirigeons
'dashicons-tag', // Icône (facultatif)
50 // Position dans le menu (facultatif)
);
add_menu_page(
'Éléments du batiment', // Titre de la page dans le navigateur
'Éléments du batiment', // Texte à afficher dans le menu
'edit_others_posts', // Capacité requise pour voir le menu
'edit-tags.php?taxonomy=elementsbatiments&post_type=artisans', // URL de la taxonomie
'', // Pas de fonction de rappel, car nous redirigeons
'dashicons-tag', // Icône (facultatif)
58 // Position dans le menu (facultatif)
);
}
// Ajoute l'élément de menu lors de l'initialisation de l'admin
add_action('admin_menu', 'add_custom_taxonomy_menu_item');
function add_custom_update_button()
{
global $post;
if ($post->post_status === 'publish') {
$update_url = admin_url('post.php?post=' . $post->ID . '&action=edit');
echo '<a href="' . esc_url($update_url) . '" class="button button-secondary" style="margin-left:10px;">Mettre à jour l\'article</a>';
}
}
add_action('post_submitbox_misc_actions', 'add_custom_update_button');