How to check if user is an admin in WordPress

I’m writing a custom filter in WordPress today for an internal support board powered by AD and WordPress user roles/capabilities.

The logic in the spec (such as it is) is along the lines of Is user posting isn’t an admin, find the admin of the user group (business support, technical support or integration) and send them an email to publish the article.

It’s taken hardly anytime to do this, but Googling for it before I started, I came across some misinformation from uninformed tossers on WordPress.org who looked at the codex and saw is_admin() function and assumed that’ll do the trick.

According to these idiots:

is the solution to the problem of finding out if the logged in user is an administrator.

No it doesn’t you cretin. Quote WordPress Codex:

is_admin() is not intended to be used for security checks. It will return true whenever the current URL is for a page on the admin side of WordPress. It does not check if the user is logged in, nor if the user even has access to the page being requested. It is a convenience function for plugins and themes to use for various purposes, but it is not suitable for validating secured requests.

And if don’t understand what that means, it translates as a check to see if you are in the admin SCREEN!

This is why the internet is full of crap WordPress themes and crap WordPress plugins, because people believe shit like this posted on the forums without double checking first.

If you want to find out if the user is an administrator, try this:

 

List Custom Taxonomy Widget v3.4 (forked)

Working on a WordPress support site for the last week or so, and we wanted to display sidebar dropdown menus for the many taxonomies we’ve created to help support agents find the correct content.

WordPress built in widgets don’t let you choose custom created taxonomies so the hunt was on for a way to do this. Instead of doing some work, I found the List Custom Taxonomy Widget, which suited our needs perfectly. And yet I wasn’t happy with it. For a kick off the submit button says “go »” , the 1990’s called and want their call to action indicator back.

The changes I made to fit my needs for this web site:

  • If FontAwesome Menus is installed show a FontAwesome input box for icon (fa-search for example, see FontAwesome Cheatsheet for the complete list)
  • Custom text on button, default to “Go »” (the 1990’s called again)
  • Add onchange option (The button will still be shown for accessibility purposes. And truly stupid people who need to see a button(!))

Download here and upload to your web shite.

Just for a change, I thought I’d have a blog post that actually involves what I do for a living. Don’t worry, the abuse will continue soon enough 

Dear WordPress hackers

To the hackers in Ukraine, Russia, Vietnam and China who are trying to hack my site… WHY?

I’m lucky to get 10 visitors a day, so I’m a little puzzled why you’d bother. I’m not sure what kudos you’ll get from the hacking fraternity by taking down this shitty web site, but thanks for noticing me.

P.S. As a WordPress developer, do you seriously think I’d have a user called admin as a user on this site? Or even as user ID 1? Or /wp-admin folder?

Good luck anyway.

Bugger all to write again…

But as @Teaandstrumpets pointed out, that’s never stopped me writing shite posts before.

I’ve updated this blog to the Mystique theme since I was sick of the default twentyten one, more so since I made so many alterations and then clicked to receive an update. Silly of me to expect it to backup the old files. And yes I did have a backup but unfortunately it was on one of my USB keys that wife successfully destroyed when she sucked it up with a vacuum.

Quite quiet on Twitter as well, helping a few people with HTC Desire issues and hoping to push people away from buying shite phones like the Samsung Galaxy 🙂

Just as I typed that, as arse appeared in the form of @JoeCienkowski

Bugger all to write

Or is that nothing worth writing?

I’ve got the rest of the week off so looking forward to two days with the wife, though one of those is going to Totnes which is going to be an experience I’m sure. Then again she is working this weekend so I get 12 hours to myself and no matter how good my intentions are on planning to do things, bugger all ever happens.

Like this blog for example, I don’t like this default theme but every time I go to design a new one, I lose interest so I’ve set myself the slightly more achievable aim of just “enhancing” it. I’m sure I can manage a decent background and change the god awful typefaces used, no offence to WordPress of course, but Georgia of all things!

Still struggling for a category name of all the posts that aren’t in the other ones. Hmmm, “Reaction”? “News?”  Ah sod it, too much thinking for one day.

Oh god, Howard Jones has just come on my mp3 player, that isn’t going to make this any easier to write! Next please. Ah, Harry Up Harry Camel! Music to think to Smile

Edit: Actually I’ve just done the background, just inverted one I did two years ago but never used anywhere so that’s one less thing to do now.