WordPress Menu Pages and “Cheatin’ Uh?”

When working with WordPress menu page permissions, you there’s a chance that you’ll eventually come across the “Cheatin’ uh?” message.

Cheatin uh

In short, this particular message shows up whenever a user of a certain role with a certain set of capabilities is trying to do something that they aren’t permitted to do. For example, say that you have an Editor who is trying to save options on a page created by the Settings API.

Technically speaking, this should be straightforward:

  1. Create the options menu (via, say, add_menu_page)
  2. Populate the page using the Settings API
  3. Allow the user to save the information

When defining add_menu_page, you have to specify a capability for which the user has the ability to save the options. Luckily, the Codex has a page that makes it really easy to know what capabilities are available to each role.

But what happens when you’ve defined a capability for a menu page and you’re still getting an error message when trying to save the data?

WordPress Menu Page Permissions

Let’s say that you initially have your code setup like this (and for all intents and purposes you’re working with the latest version of WordPress, are familiar with the APIs, and all of that fun stuff):

Everything looks good, but then you create an Editor account to test out the information and everything looks good, but then you click on the ‘Save Changes’ button and you see the error screen from above?

So what’s the deal with that?

To fix this, add the following code: First, define a filter – this may be in the context of a method if it’s in the context of a constructor or as its own method if it’s in a procedural file:

Then define the method itself:

And finally, make sure that the code you’re used to define the menu page (as well as any submenu pages) use the capability you’ve defined.

Note that I write my plugins in an object-oriented fashion so the full code that I’m about to share will be a little different than what I have above, but the gist of what’s happening is still the same.

Here’s how the full code should be structured:

What Gives?

At the time of writing this message, I have dug into core enough to trace exactly why this happens – as far as my understanding is concerned (which is easy to call into question :), it should would without the need for this filter.

Unfortunately, it does require this particular change.

When I have the time to look more into the code behind everything powering this, I’ll likely blog about it. But until then, the code above should resolve the problem that you may experience and should make sure the proper role has the ability to save the data for each of the settings pages to which it has access.

7 Replies to “WordPress Menu Pages and “Cheatin’ Uh?””

  1. Tom, I see “Cheatin’ Uh?” over and over, only in one very specific situation: when, as an Administrator, I simply try to delete a Custom Menu.

    It’s not me — it’s a WordPress bug, and an embarassing one. I wouldn’t be critical of it at all if it didn’t have a misspelled hillbilly-talk error message.

    1. I think the grammar used throughout WordPress is inconsistent. This is one of those areas that could certainly be improved, and I recall it was brought up in a survey and conversation a while ago, though I don’t recall what the end result was.

      Either way, as far as the bug is concerned, I’m hoping it can be fixed in a future release. As far as the grammar, I don’t know. It might be worth trying to bring a little more attention to it and see how people respond.

      That might be fun – I’m curious to see how people may respond :).

      1. True. To be a little clearer, what makes it really annoying here is that I am not “cheatin'” in any sense of the word when I’m subjected to that message.

        So whereas the US-regional-cutesy language is normally just annoying at best, in this context it’s like having someone slam into your car and then yell at you, “Drivin’ purdy bad uh!”

        1. What’s always made it triple-bad for me is the ‘Uh’ part. Even in the remotest areas of the US that slang would be pronounced with an H in front: Huh? Cheatin’, Huh?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.