Alterando a ordem das seções do menu Admin?
5 respostas
- votos
-
- 2010-09-02
hi @binarybit:
Não é de admirar que vocêesteja umpoucofrustrado; Omenu Admin é uma dasimplementaçõesmais obtusoe frustrantes através do Núcleo do WordPress. Honestamente,não sei o queelesestavampensando quandoelesprojetaram assim.
@eamann fez um excelente trabalho deexplicar como osmenus de administradorfuncionamno WordPress (eugostaria deter sido capaz de lerisso sobre 4meses atrás ... :)
Ainda assim,depois queeupercebi comofuncionou queeu aindaestava com umaperdaparatrabalhar comisso sem dedicartempo suficienteparamanterminha cabeça diretamenteenquantoeutentei fazer coisas simples. Então éporisso que construí uma API demenu Isso simplificae simplificae simplifica otrabalho com omenu Admin do WordPress.
Eles são 100% compatíveis com asestruturasexistentes do WordPresse aindamuitoem Alpha,uma vez queeutenho sido o único usando-o. Tenho certeza que há casos de uso que aindanão lidam. Mas voupostar o código aquipara vocêe outrosparaexperimentar.
Vocêpode download o arquivopara cairno diretório do seutema aqui: wp-admin -Menu-classes.php e o que seguemostra como vocêpode chamar asfunçõesno seutema
functions.php
arquivo:<?php require_once('wp-admin-menu-classes.php'); add_action('admin_menu','my_admin_menu'); function my_admin_menu() { swap_admin_menu_sections('Pages','Posts'); // Swap location of Posts Section with Pages Section rename_admin_menu_section('Media','Photos & Video'); // Rename Media Section to "Photos & Video" delete_admin_menu_section('Links'); // Get rid of Links Section $movie_tags_item_array = get_admin_menu_item_array('Movies','Movie Tags'); // Save off the Movie Tags Menu update_admin_menu_section('Movies',array( // Rename two Movie Menu Items and Delete the Movie Tags Item array('rename-item','item'=>'Movies','new_title'=>'List Movies'), array('rename-item','item'=>'Add New','new_title'=>'Add Movie'), array('delete-item','item'=>'Movie Tags'), )); copy_admin_menu_item('Movies',array('Actors','Add New')); // Copy the 'Add New' over from Actors renamed_admin_menu_item('Movies','Add New','Add Actor'); // Rename copied Actor 'Add New' to 'Add Actor add_admin_menu_item('Movies',array( // (Another way to get a 'Add Actor' Link to a section.) 'title' => 'Alt Add Actor ', 'slug' => 'post-new.php?post_type=actor', ), array(// Add Back the Movie Tags at the end. 'where'=>'end' )); add_admin_menu_item('Movies',$movie_tags_item_array,array(// Add Back the Movie Tags at the end. 'where'=>'end' )); delete_admin_menu_section('Actors'); // Finally just get rid of the actors section }
Além disso,essasfunções são até em consideração (comobase)parainclusãono WordPress 3.1 Então,setivermos sorte,issopode setornarpadrão!
Hi @BinaryBit:
It's no wonder you are a bit frustrated; the admin menu is one of the most obtuse and frustrating implementations through WordPress core. Honestly, I don't know what they were thinking when they designed it that way.
@EAMann did an excellent job of explaining how the admin menus work in WordPress (I wish I had been able to read that about 4 months ago... :)
Still, after I figured it out how it worked I was still at a loss to work with it without devoting enough time to keep my head straight while I tried to do simple things. So that's why I built a Menu API that simplifies and streamlines working with the WordPress admin menu.
They are 100% compatible with WordPress' existing structures and still very much in alpha since I've been the only one using it. I'm sure there are use-cases they do not yet handle. But I'll post the code here for you and others to try out.
You can download the file to drop in your theme's directory here: wp-admin-menu-classes.php and what follows shows how you might call the functions in your theme's
functions.php
file:<?php require_once('wp-admin-menu-classes.php'); add_action('admin_menu','my_admin_menu'); function my_admin_menu() { swap_admin_menu_sections('Pages','Posts'); // Swap location of Posts Section with Pages Section rename_admin_menu_section('Media','Photos & Video'); // Rename Media Section to "Photos & Video" delete_admin_menu_section('Links'); // Get rid of Links Section $movie_tags_item_array = get_admin_menu_item_array('Movies','Movie Tags'); // Save off the Movie Tags Menu update_admin_menu_section('Movies',array( // Rename two Movie Menu Items and Delete the Movie Tags Item array('rename-item','item'=>'Movies','new_title'=>'List Movies'), array('rename-item','item'=>'Add New','new_title'=>'Add Movie'), array('delete-item','item'=>'Movie Tags'), )); copy_admin_menu_item('Movies',array('Actors','Add New')); // Copy the 'Add New' over from Actors renamed_admin_menu_item('Movies','Add New','Add Actor'); // Rename copied Actor 'Add New' to 'Add Actor add_admin_menu_item('Movies',array( // (Another way to get a 'Add Actor' Link to a section.) 'title' => 'Alt Add Actor ', 'slug' => 'post-new.php?post_type=actor', ), array(// Add Back the Movie Tags at the end. 'where'=>'end' )); add_admin_menu_item('Movies',$movie_tags_item_array,array(// Add Back the Movie Tags at the end. 'where'=>'end' )); delete_admin_menu_section('Actors'); // Finally just get rid of the actors section }
What's more, these functions are even under consideration (as a base) for inclusion in WordPress 3.1 so if we're lucky these might even become standard!
-
* Fantástico * Além da API!Demoreimesespara adicionarminhaprimeira seção demenupersonalizada com aestruturaexistente (e éporisso queestudei o códigofazermuito) ... Mas sua APIparecemuitomaisintuitiva de usar!*Fantastic* addition to the API! It took me months to add my first custom menu section with the existing framework (which is why I studied the code do much) ... but your API seems much more intuitive to use!
- 0
- 2010-09-02
- EAMann
-
* @ Eamann * - obrigado!Se você quiser oferecer qualquer sugestão ou atémesmo colaborarparamelhorá-lo,adoraria obter algoestabelecido quepoderiatornarmaisfácilparatodos,exceto apenas ospoucos que vêemesta Q & A.*@EAMann* - Thanks! If you want to offer any suggestions or even collaborate on improving it I'd love to get something established that could make it easier for everyone except for just the few who happen to see this Q&A.
- 0
- 2010-09-03
- MikeSchinkel
-
Issofeznúcleo ou éisso ou algoparecido aindanecessárioparamanipular a ordem dositens demenuno administrador?did this make core or is this or something similar still required to manipulate the order of menu items in the admin?
- 0
- 2012-09-12
- Q Studio
-
Tanto quantoeuencontrei,foi adiadapara WP 3.5As far as i have found, it's been postponed to WP 3.5
- 0
- 2012-09-22
- pixeline
-
Heymike - wp_debugjoga umerronestafunção: --------função swap_admin_menu_sections ($from_section,$to_section) { $from_section=get_admin_menu_section ($from_section); if ($from_section) $from_section-> swap_with ($to_section); retornar a seção; } --- Aviso: variávelindefinida: seçãoHey Mike - wp_debug throws an error on this function: -------- function swap_admin_menu_sections($from_section,$to_section) { $from_section = get_admin_menu_section($from_section); if ($from_section) $from_section->swap_with($to_section); return $section; } --- Notice: Undefined variable: section
- 0
- 2012-10-11
- Q Studio
-
- 2012-12-20
Eupercebo queeste é umfio antigo,mas acho que vale apena atualizar com uma soluçãomuitomaisfácil. Porfavor,note queissofunciona com 3.5e nãofoitestado com qualquer outra versão. O código a seguirpode ser colocadoem umplugin ou o arquivofunctions.php.
ver: http://codex.wordpress.org/plugin_api/filter_reference/menu_order . Modificado ligeiramentepara atender àsnecessidades originais do cartaz (porém,espero queeletenhaencontrado uma solução agora ...).
// Rearrange the admin menu function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // Dashboard 'edit.php?post_type=custom_type_one', // Custom type one 'edit.php?post_type=custom_type_two', // Custom type two 'edit.php?post_type=custom_type_three', // Custom type three 'edit.php?post_type=custom_type_four', // Custom type four 'edit.php?post_type=custom_type_five', // Custom type five 'separator1', // First separator 'edit.php?post_type=page', // Pages 'edit.php', // Posts 'upload.php', // Media 'link-manager.php', // Links 'edit-comments.php', // Comments 'separator2', // Second separator 'themes.php', // Appearance 'plugins.php', // Plugins 'users.php', // Users 'tools.php', // Tools 'options-general.php', // Settings 'separator-last', // Last separator ); } add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order add_filter('menu_order', 'custom_menu_order');
Quaisqueritensnomenu Admin quenãoestão listados aquinão serão removidos. Eles serão anexadospara aparteinferior domenu.
I realize this is an old thread, but I think it's worth updating with a MUCH easier solution. Please note that this works with 3.5 and has not been tested with any other version. The following code can be placed in a plugin or the functions.php file.
See: http://codex.wordpress.org/Plugin_API/Filter_Reference/menu_order. Modified slightly to suit the original poster's needs (though, I hope he found a solution by now...).
// Rearrange the admin menu function custom_menu_order($menu_ord) { if (!$menu_ord) return true; return array( 'index.php', // Dashboard 'edit.php?post_type=custom_type_one', // Custom type one 'edit.php?post_type=custom_type_two', // Custom type two 'edit.php?post_type=custom_type_three', // Custom type three 'edit.php?post_type=custom_type_four', // Custom type four 'edit.php?post_type=custom_type_five', // Custom type five 'separator1', // First separator 'edit.php?post_type=page', // Pages 'edit.php', // Posts 'upload.php', // Media 'link-manager.php', // Links 'edit-comments.php', // Comments 'separator2', // Second separator 'themes.php', // Appearance 'plugins.php', // Plugins 'users.php', // Users 'tools.php', // Tools 'options-general.php', // Settings 'separator-last', // Last separator ); } add_filter('custom_menu_order', 'custom_menu_order'); // Activate custom_menu_order add_filter('menu_order', 'custom_menu_order');
Any items in the admin menu that are not listed here won't be removed. They will be appended to the bottom of the menu.
-
Sim,isso émuitomelhor,tambémpara reordenaritens do submenu que vocêpode desblementare depois redefini-los.Yes this is much better, also to re-order submenu items you can unset and then reset them.
- 1
- 2012-12-20
- Wyck
-
- 2010-09-04
Euentendo que vocênão quer usar umplugin,masporpura simplicidade,tente oplugin do Editor de Menu Adminpor Janis Elsts.Reorganize seusmenus de administrador que vocêgosta;tambémpode ocultaritens demenu.
I understand you don't want to use a plugin, but for pure simplicity, try the Admin Menu Editor plugin by Janis Elsts. Rearrange your admin menus any way you like; can also hide menu items.
-
Eutentei estepluginnainstalaçãomultisite. Funcionamelhor. Masprecisamos configurarmanualmente as opçõespara cada sub-site,setivermos umainstalaçãomultisite.I tried this plugin in multisite installation .It works best.But we need to manually configure the options for every sub-site if we have multisite Installation.
- 0
- 2010-10-13
- user391
-
- 2012-11-08
Paramoveritens demenu ao redor,eugosto de usar omenuglobal
$menu
variável.Porexemplo,seeu quisessemover omenu "páginas"para aparteinferior dosmenus,usariaissoem
functions.php
ou umplugin:function admin_menu_items() { global $menu; $menu[102]=$menu[20];//make menu 102 be the same as menu 20 (pages) $menu[20]=array();//make original pages menu disappear } add_action('admin_menu', 'admin_menu_items');
e seeu quisessetrocar aspostagense osmenus de links:
function admin_menu_items() { global $menu; $storemenu = $menu[15];//save links menu into $storemenu $menu[15] = $menu[5];//make links menu = posts menu $menu[5] = $storemenu; //make menu 5/posts = $storemenu/links } add_action('admin_menu', 'admin_menu_items');
Usandoestetruque umpouco,acabou detestar com WP 3.4.1
To move menu items around, I like using the Global
$menu
variable.For example, if I wanted to move the "Pages" menu to the bottom of the menus, I would use this in
functions.php
or a plugin:function admin_menu_items() { global $menu; $menu[102]=$menu[20];//make menu 102 be the same as menu 20 (pages) $menu[20]=array();//make original pages menu disappear } add_action('admin_menu', 'admin_menu_items');
and if I wanted to swap the Posts and Links menus:
function admin_menu_items() { global $menu; $storemenu = $menu[15];//save links menu into $storemenu $menu[15] = $menu[5];//make links menu = posts menu $menu[5] = $storemenu; //make menu 5/posts = $storemenu/links } add_action('admin_menu', 'admin_menu_items');
Been using this trick a little while, just tested with WP 3.4.1
-
Eu sei queeste é umpostmais antigo,mas com relação ao seuprimeiro snippet,encontrei umproblema com a última linhanafunção `admin_menu_items ',quefoi corrigido substituindo-opor"menu $ ");`I know this is an older post but with regards to your first snippet I ran into an issue with the last line in the `admin_menu_items` function which was fixed by replacing it with `unset($menu[20]);`
- 0
- 2017-08-04
- hot_barbara
-
- 2012-03-05
Impressionante. Muito obrigado. Acabei de colocar algumas linhas de códigoem minhasfunções.php
require_once('/extras/wp-admin-menu-classes.php'); add_action('admin_menu','my_admin_menu'); function my_admin_menu() { swap_admin_menu_sections('Pages','Posts'); // Swop location of Posts Section with Pages Section }
mais colocando o wp-admin-menu-classes.php naminhapastatemae agora o ' Botão daspostagens éengasgado com obotão 'páginas'.
Espero queisso setorneparte donúcleoem brevee de umamaneira denãoprecisarescrever omenuinteiro dentro de umafunçãopara apenas reordenar doisbotões.
Na verdade,foi umpouco complicado obter uma ordemmaisespecificadapara 4botões. Para alterar os 4botõespara:páginas,post,mídia,links Euprecisava usar o Código de Follower:
swap_admin_menu_sections('Pages','Posts'); swap_admin_menu_sections('Media','Links'); swap_admin_menu_sections('Posts','Links');
Awesome. Thank you so much. I just put some lines of code into my functions.php
require_once('/extras/wp-admin-menu-classes.php'); add_action('admin_menu','my_admin_menu'); function my_admin_menu() { swap_admin_menu_sections('Pages','Posts'); // Swop location of Posts Section with Pages Section }
Plus placing the wp-admin-menu-classes.php in my theme folder and now the 'posts' button is swopped with the 'pages' button.
I hope this will become part of the core soon and in a way so that we don't need to write the whole menu within a function to just reorder two buttons.
In fact it was a bit tricky to get a more specified order for 4 buttons. In order to change the of 4 buttons to: Pages, Post, Media, Links I needed to use the folowing code:
swap_admin_menu_sections('Pages','Posts'); swap_admin_menu_sections('Media','Links'); swap_admin_menu_sections('Posts','Links');
Euestouficando umpoucofrustradopor aqui depois deterpassado algumas horastentando realizaressatarefabastante simples sem qualquer sorte.
Essencialmenteeutenho 5tipos depostagempersonalizados queeu crieie tudo queeu querofazer émostrar cada um delesem uma ordemespecífica diretamente sob o "painel"
Da documentação do WordPress Parece que vocênãopode realmentefazerissoporque a ordem demenumais altaparece ser "5". E acima L
Euestou supondo alguma leituraespecializada Issopodeme mostrar amaneira simples queeupossoencomendarexatamente omenu de administração damaneira queeu quero utilizar o arquivo defunçõese sem utilizar umplugin (queeu sei).
Porfavor,váem frentee tente criar 5tipos depostagem separadose incluí-losem uma ordemespecífica diretamente sob opainel ...parece queissonão épossível.?? ... Existe algumtipo de hackjqueryparafazerissotrabalho que alguémpoderia compartilhar comigo ou depreferência sem utilizarjQuery?