From 8710140b7411ee5bb3aa9f8733d7c1ca7f7c97c7 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Wed, 31 Jan 2024 19:46:13 +0100 Subject: [PATCH] introducing option page --- includes/admin.php | 87 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/includes/admin.php b/includes/admin.php index 969ded5..fbcf218 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -1,4 +1,48 @@ __('Texte interface', 'homegrade-theme__texte-backoffice'), + 'menu_title' => __('Texte interface', 'homegrade-theme__texte-backoffice'), + 'menu_slug' => 'theme-general-settings', + 'capability' => 'activate_plugins', + 'redirect' => false, + 'icon_url' => 'dashicons-admin-site-alt', + 'position' => 2, + )); + // Add sub page. + $press_kit_admin_page = acf_add_options_sub_page(array( + 'page_title' => __('Presse'), + 'menu_title' => __('Presse'), + 'parent_slug' => $homegrade_option_page['menu_slug'], + )); + } +} +// add_options_page( 'MyPlugin Options', 'MyPlugin Options', 'activate_plugins', 'myplugin-options', 'myplugin_options' ); + + +add_action('acf/init', 'register_theme_settings_option_page'); + // #### ADMIN STYLE function my_custom_admin() @@ -39,3 +83,46 @@ function enqueue_custom_login_stylesheet() wp_enqueue_style('custom-login', get_stylesheet_directory_uri() . '/style-login.css'); } add_action('login_enqueue_scripts', 'enqueue_custom_login_stylesheet'); + + + + +/* ---------------------------------------------------------------------- + REORDER ADMIN MENU & POST TYPE ORDER ON MENU BAR + ------------------------------------------------------------------------*/ +/** + * Activates the 'menu_order' filter and then hooks into 'menu_order' + */ +add_filter('custom_menu_order', function () { + return true; +}); +add_filter('menu_order', 'my_new_admin_menu_order'); +/** + * Filters WordPress' default menu order + */ +function my_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( + 'session-datas-options' => 1, + 'admin.php?page=my_options' => 4, + 'edit.php' => 6, + 'edit.php?post_type=page' => 9, + 'upload.php' => 11, + ); + // helper function to move an element inside an array + function 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)) { + move_element($menu_order, $current_index, $new_index); + } + } + return $menu_order; +};