Admin menu & submenu separators

After going over it and extending the core API to allow main menu separators in custom positions, I did a quick run through core menu files, dumped the hell out of everything's that in there and found a solution that allows to use the core API also for custom submenu separators.

The result

This is how our menu will look like, after we added the separators.

To make this happen, simply add a small plugin, or throw this snippet in your plugins file or functions.php. Here's an example plugin. As you can see, you'll have to add the parent page where you want your separator to appear. Then you have to add the identifier wp-menu-separator. You can adjust the visibility for user by changing the read-capability to whatever the other items in this menu have. The 11 is just the priority. Adjust it to wherever you want the separator to appear inside the menu.

Seems like a long way to achieve what you want. Why not just include the div in the array, but instead of a div use a span and give it the class="separator"?
–
userabuserFeb 2 '13 at 6:55

I guess it is, but that's because I wanted to get rid of the a tag from the separator. Including the div in the array is a good idea. The reason I used div is to use WP's built-in styling for the separator.
–
GiraldiFeb 2 '13 at 8:05

Seems like a lot of code + (maybe non-accessible) javascript for a simple separator. See my answers.
–
kaiser♦Feb 8 '13 at 9:50

@kaiser: Thanks for the code. I had tried it. It's not any shorter than mine. In fact, it's a lot more. As in regards to my javascript, firstly, it is optional, as I had stated, to remove the a tag so the separator doesn't become a hyperlink (personal preference). Secondly, how is that 'non-accessible' may I ask?
–
GiraldiFeb 10 '13 at 3:32

1

@GiraldiMaggio My mistake, as I've misread your JS part. About the overall length: I just counted those lines that actually add & modify the separator and it's 19/23, so yours is shorter by 4 lines, but highly specific, while my solution is reusable and can be used multiple times and uses the default core API. And adding another separator takes one additional line only. If you look at the linked Gist, which I updated several times, you'll also see that I don't run it on every pageload (when it's not necessary), so performant wise...
–
kaiser♦Feb 10 '13 at 9:12

Yes! This looks like the more straightforward way of doing it. Now we just need to reposition it, I guess.
–
GiraldiFeb 2 '13 at 6:57

You could adapt what you have already done in your function to reposition the item in the sub menu, alternatively I recommending reading this answer which speaks of the exact topic (positioning sub menu items). Also if you take a look at the file I mention as part of the s2member plugin you will see that the position of their "dividers" is based upon the order in which they are declaring the sub menu items.
–
userabuserFeb 2 '13 at 7:13

Thanks for the answer, but actually I'm looking for a separator on the admin submenu section
–
GiraldiFeb 2 '13 at 0:07

@GiraldiMaggio Please add a screenshot to your question, else it's impossible to visualize what you want to have. And with screenshot I don't mean, some purple lines drawn over a default admin menu, I actually mean how you finally want to have it in the UI.
–
kaiser♦Feb 2 '13 at 3:20