So, while I was working on my Back End Instructions plugin yesterday, I was talking to my husband about the client I had built it for. As a quick notation, it’s a group of women who are of a certain age (no offense to anyone – I’m getting there myself!) and who do not like change. It’s taken me almost three years of pulling teeth to get things to where they are now. They want to change, but man, are they putting up a fight for it.
Anyway, so I was telling my husband that the new plugin I made will make things so easy that even he could understand how to do it, and there would be no excuses for these people to do what they need to do.
(An aside, I really recommend getting a husband – or wife – who is clueless when it comes to computers. They are priceless when it comes to usability testing!)
After the expected “Oh, thanks honey,” comments, I asked him to come down and take a look for himself. He did, and he said I really did make it easy as pie. (Score!) However, he noted that some of the fields I was showing in the back end were not supposed to be touched (as mentioned in the video I made – that some fields were to be left alone) and he said that I should remove them if I didn’t want anyone to mess with them.
He had a point.
What I discovered last night doesn’t really have much to do with the plugin (save it’s handy) but more for WordPress. I was basically just trying to find some method of hiding the “Personal Options” in the profile.php page in the back end. I know for most sites, that should be left alone, but in this case, it’s an option that truly does not need to be messed with.
That’s when I found this post, which made things very interesting. (The following comment by BjornW made it even more interesting.)
It gave me a starting point.
Turns out you can take this a step further. There were some table rows within that profile.php page that I wanted to hide, but leave the rest to show. For example, the rows that contained the “JabberTalk”, “Aim” etc, and the”Bio” section. I wanted to retain the rest, but those fields really aren’t needed. So the question was, how to specify exact rows, while leaving others intact?
Oh, the life of a programmer. I had to know the answer. Lo and behold! I found it
Now the following code is simply to remove certain fields from the profile.php page – but I’m sure it has applications on other pages, if you so desired. On the site I’m using this for, I’m also using the Adminimize plugin, and Justin Tadlock’s “Members” plugin to remove further extraneous information a lot more easily.
So I’ll show you a “before” (i.e. before I added this blip of code to my functions.php file) photo of what the screen looked like:
And after the little blippy function:
Now before I give you the code, I also wanted to mention something I found via a reply in the WordPress forums. It was just a random thing someone mentioned in passing, and had they not, I never would have know this had existed.
Apparently, WordPress has created (recently, I believe) a particular variable that can be globalized in WordPress. Said variable is
$pagenow. This is just an aside for you coders out there who don’t know about this wonderful little variable. Before, when I wanted to know what page I was on (and I couldn’t use anything like “is_page()”), I would grab the URL that was in the address bar, by using
http://' . $_SERVER['HTTP_HOST'] . $_SERVER["REQUEST_URI"]; Then I would use an explode function to separate the string at the “/”, and list each result into a variable (or just using PHP’s end() function), allowing me to grab any part of the url. Usually, all I wanted was the last one: what page I was on. This lovely little variable has made all of that pointless. I just thought I’d share that
So, without making you wait any longer, here is the code: (Updated to reflect Nathan Briggs’ suggestions – thanks Nathan!)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
So basically, the
jQuery("form#your-profile > table:first").hide(); line hides the first table completely – which is the “Personal Options” table. In jQuery, this would also be known as
table.form-table:eq(0). The lovely :eq() function can count – without any extraneous code – where you are. You just have to specify where you want it to start counting, and go from there.
I’m pretty sure this can be used on any back-end page. All I needed it for was the profile page, and you can see how well it cleaned up all that stuff that didn’t need to be there!
Now I just have to test it in IE – and hopefully it doesn’t break!