WPThemeReview icon indicating copy to clipboard operation
WPThemeReview copied to clipboard

[New Sniff] Check that capabilities are used not roles

Open khacoder opened this issue 8 years ago • 9 comments

[New Sniff]

Rule:

ERROR : Check that capabilities are used not roles. Functions to check: get_role(), current_user_can(), current_user_can_for_blog(), user_can(), add_..._page()

Ref: https://make.wordpress.org/themes/handbook/review/required/#core-functionality-and-features

To do:

  • [x] Create Unit Tests
  • [x] Create Unit Sniff

khacoder avatar Jul 13 '16 02:07 khacoder

I have essentially got this sniff done, but need a little more time for testing.

khacoder avatar Jul 13 '16 02:07 khacoder

Is this only regarding adding menu pages, or other usages too?

carolinan avatar Jul 13 '16 07:07 carolinan

Is this only regarding adding menu pages, or other usages too?

This should be for all usages

jrfnl avatar Jul 13 '16 14:07 jrfnl

Theme check file (partially) covering this rule:

https://github.com/Otto42/theme-check/blob/master/checks/admin_menu.php

jrfnl avatar Jul 13 '16 14:07 jrfnl

Also in the handbook (related but not the same):

Use edit_theme_options capability for determining user permission to edit options, rather than rely on a role (e.g. “administrator”), or a different capability (e.g. “edit_themes”, “manage_options”).

https://make.wordpress.org/themes/handbook/review/required/#options-and-settings

jrfnl avatar Jul 13 '16 14:07 jrfnl

the sniff I have created is for all pages.

khacoder avatar Jul 13 '16 22:07 khacoder

In the new Theme handbook, the rule has been moved to another section: https://make.wordpress.org/themes/handbook/review/required/#options-and-settings

jrfnl avatar Mar 21 '17 08:03 jrfnl

Created a PR upstream for this https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/pull/1364

grappler avatar May 31 '18 16:05 grappler

@grappler Any news on the upstream issue for this?

dingo-d avatar May 18 '19 13:05 dingo-d