-
-
Save mikeschinkel/792b7aa5b695d1092520 to your computer and use it in GitHub Desktop.
if a plugin wanted to add an option page, and I had moved and renamed the section they wanted to hook into, could any discrepancies arise, perhaps in how the developer coded it to hook in, that would cause a fail?
It all depends on what the plugin does. If it renames titles and you are using titles then yes, it could cause problems. But no more than going direct to the $menu
or $submenu
variables. My functions do nothing to modify the underlying structure nor do they cache their values so they are as safe as you can get but still no silver bullet. Caveat Emptor!
Hope this helps.
-Mike
BTW, on WordPress dev chat they don't want to discuss including these for v3.1 (mostly because they've already blessed the list of tasks and this was not on it.)
oh yeah, there won't be any way to just move one item to another spot will there ... due to the same issue of not having ids huh? I can't imagine any way that could be >>done ... unless "groups" could be created somehow ... hmmm.
Give me a use-case example specific with item names?
I have swap_admin_menu_sections(); would swap_admin_menu_items() be what you'd need?
Hope this helps.
Here's a use case where simply 'moving' is more preferable than 'swapping'....
Let's say I want to move the 'Comments' section below 'Posts' and above 'Media', but I want to maintain the order of the rest of the menu, ie. 'Media', then 'Links', then 'Pages'.
In order to do that, I have to:
- Swap 'Comments' with 'Media'
- ..then swap 'Media' with 'Links'
- ..then swap 'Links' with 'Pages'
And if I were to put 'Comments' above 'Posts' then I would have to add one more line of 'swap' command.
Is it possible to make this more straightforward? Of course, it would be good if we could have this for menu items as well.
Just a thought.
Cheers!
@bedex78 - Of course it would be possible, but it would also be a lot more complicated because of how WordPress currently stores menus as +5 indexes into a set of arrays. The code to make it work correctly is a lot more work than what I've done so far. Also, I'm not sure what the best API interface would be. Maybe I should ask, if you had this functionality what would the function calls look like? What parameters would you pass?
Good job!
@marcosmlopes - Thanks!
I just found your gist here through your post on the wordpress SE forum. Great stuff! The only thing it's missing is what @bedex78 mentioned - I really want to be able to move things around. It would also be nice if it could handle separators too. You asked before what the function calls would look like for moving a section around. This is what I would have in mind:
<?php
move_admin_menu_section( array(
'slug' => 'upload.php' // slug of section to move
'insert' => 'before', // or 'after'
'neighbor' => 'edit.php' // slug of section to insert next to
'priority' => 10, // similar to wp actions to handle multiple moves
));
Thanks again for your work on this.
@aaemnnosttv Thanks for your kind comments. Right now, I've got my hands full with too many other projects to have time to focus on this, unfortunately. If you want to take a stab a getting this to work I'll be happy to post it as an update.
Hi Mike,
That's a great piece of code ! I don't know if you could take a few minutes to tell me what do I'm doing wrong !
I have an option page that I want to move inside at section created with your code, I've moved multiple custom post type without any problem, but the option page wouldn't moved at all.
I've tried to change the add_action priority it dose not work, i've tried to recreate this subpage with your script but can't figure how to get ride of "you don't have access to this page" and finally I found that I can remove it with the Menu name instead of the slug, but still don't move it around..
$new_section = array(
'title' => 'Google Transit',
'slug' => 'google-transit-export',
'page_title' => 'Exportation des cartes',
'icon_src' => false,
'function' => false,
'capability' => 'edit_posts',
);
$new_section_args = array(
'where' => 'bottom' // top or bottom
);
$google_transmit_menu = add_admin_menu_section($new_section, $new_section_args);
$gt_fares = 'Tarifs'; // Menu Name
$gt_fares = 'admin.php?page=google-transmit-management-system-fares'; // Slug
copy_admin_menu_item($google_transmit_menu,$gt_fares);
remove_admin_menu_item($gt_fares);
remove_admin_menu_section($gt_fares);
Thank you !
I'm having a similar problem to @jonathanlaf. I can't get copy_admin_menu_item() to work with pages added via add_menu_page().
Thanks!
I responded via email on this, sorry, but, I had another question anyway, so, here goes. I'm wondering if you foresee there being any issues with hooking into core menus that have been potentially renamed and relocated.
For instance, if a plugin wanted to add an option page, and I had moved and renamed the section they wanted to hook into, could any discrepancies arise, perhaps in how the developer coded it to hook in, that would cause a fail?
Just curious~