From a0e4adc705842aec66815bacec5b13acc9673c99 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Thu, 7 May 2026 17:55:09 +0200 Subject: [PATCH] FEATURE Reordering admin menu for backend --- mu-plugins/carhop-post-types.php | 84 +++++++++++++++++++++++++------- 1 file changed, 67 insertions(+), 17 deletions(-) diff --git a/mu-plugins/carhop-post-types.php b/mu-plugins/carhop-post-types.php index b78d073..2eb80c4 100644 --- a/mu-plugins/carhop-post-types.php +++ b/mu-plugins/carhop-post-types.php @@ -251,23 +251,23 @@ function carhop_create_posttype() ); - // -------EXPOSITIONS------- // - register_post_type( - 'reportages', - array( - 'labels' => array( - 'name' => __('Reportages'), - 'singular_name' => __('Reportage'), - ), - 'public' => true, - 'has_archive' => true, - 'rewrite' => array('slug' => 'reportages'), - 'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode(''), - 'show_in_rest' => true, - 'supports' => array('title', 'revisions'), - 'menu_position' => 4, - ) - ); + // -------EXPOSITIONS------- // + register_post_type( + 'reportages', + array( + 'labels' => array( + 'name' => __('Reportages'), + 'singular_name' => __('Reportage'), + ), + 'public' => true, + 'has_archive' => true, + 'rewrite' => array('slug' => 'reportages'), + 'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode(''), + 'show_in_rest' => true, + 'supports' => array('title', 'revisions'), + 'menu_position' => 4, + ) + ); } add_action('init', 'carhop_create_posttype'); @@ -279,3 +279,53 @@ function carhop_hide_default_post_type() remove_menu_page('edit-comments.php'); } add_action('admin_menu', 'carhop_hide_default_post_type'); + + + + +/* ---------------------------------------------------------------------- + REORDER ADMIN MENU & POST TYPE ORDER ON MENU BAR + ------------------------------------------------------------------------*/ +/** + * Filters WordPress' default menu order + */ +function carhop_new_admin_menu_order($menu_order) +{ + // define your new desired menu positions here + // for example, move 'upload.php' to position #9 and built-in pages to position #1 + $new_positions = array( + 'edit.php?post_type=auteurs' => 3, + 'edit.php?post_type=actualites' => 4, + 'edit.php?post_type=analyses-etudes' => 5, + 'edit.php?post_type=dbmob' => 6, + 'edit.php?post_type=outils-pedagogiques' => 7, + 'edit.php?post_type=fonds-archives' => 8, + 'edit.php?post_type=expositions' => 9, + 'edit.php?post_type=activites' => 10, + 'carhop-presse' => 11, + 'edit.php?post_type=recherches' => 12, + 'edit.php?post_type=reportages' => 13, + 'edit.php?post_type=page' => 14, + 'upload.php' => 15, + 'theme-general-settings' => 16, + 'rank-math' => 20, + ); + // helper function to move an element inside an array + function carhop_move_element(&$array, $a, $b) + { + $out = array_splice($array, $a, 1); + array_splice($array, $b, 0, $out); + } + // traverse through the new positions and move + // the items if found in the original menu_positions + foreach ($new_positions as $value => $new_index) { + if ($current_index = array_search($value, $menu_order)) { + carhop_move_element($menu_order, $current_index, $new_index); + } + } + return $menu_order; +}; +add_action('admin_menu', function () { + add_filter('menu_order', 'carhop_new_admin_menu_order'); + add_filter('custom_menu_order', '__return_true'); +});