User login

Check if a given uid has a given permission (a query to avoid user_load)

a good D7 query for determining if a user has a specific permission
via agentrickard

what's wrong with user_access('permission', $account) ?

it requires a user_load_multiple() (a user_load to get the roles on the account, turning in the ID is not enough)

which is wasteful if you can do it at the query level

you could see what queries that function runs

it seems like that is a somewhat complicated thing to work out
since users can belong to many roles

how many users is this for at a time? I'd just use user_load() + user_access().

could be 10, could be 10,000
So potentially a lot.

INNER JOIN {users_roles} USING (uid) INNER JOIN {role_permission} USING (rid) WHERE permission = :permission-name

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.