Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use capabilities not roles #36

Closed
wants to merge 4 commits into from
Closed

Use capabilities not roles #36

wants to merge 4 commits into from

Conversation

khacoder
Copy link
Contributor

No description provided.

@khacoder khacoder closed this Jul 19, 2016
@khacoder
Copy link
Contributor Author

Sorry, not quite sure what I am doing yet. Can you help me out jrf or grapplerulrich

@grappler
Copy link
Member

@khacoder You don't need to close the PR. We can keep it open and work on it. What do you need help with? Ping me on slack.

@jrfnl
Copy link
Contributor

jrfnl commented Dec 18, 2016

When merged, solves #27

Copy link
Contributor

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The principle of the sniff is sound, but it can do with some more love to make it great.

I would also like to suggest pulling this sniff upstream and moving it into the WP category instead of Theme.
This is a best practice for all WP devs, not just themes.

* Test file: UseCapabilitiesNotRoles Sniff.
*/

add_dashboard_page( 'page_title' , 'menu_title' , 'super_admin' , 'menu_slug' , 'function'); // ERROR.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not important, but the Error/Warning comment should be in normal sentence case, no need for all caps.

@@ -0,0 +1,41 @@
<?php
/**
* Test file: UseCapabilitiesNotRoles Sniff.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is redundant as it is linked to the sniff by the directory and file name.

*
* @var array Capabilities available in core.
*/
protected $core_capabilities = array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing the unfiltered_upload capability. Not that it's used much, but it is a valid capability.

/**
* Array of core capabilities.
*
* @since 0.xx.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note on what logic has been used to order this list.

You may also want to include a link to the core handbook and/or codex which lists these capabilities to make it easier in the future to keep the list up to date.

'manage_network_users' => true,
'manage_network_plugins' => true,
'manage_network_themes' => true,
'manage_network_options' => true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 91-98 is duplicate of line 83-90

Also towards the bottom of the list there is a whole range of additional duplicates for things like edit_posts, delete_posts etc

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes the list was not very good. I have updated it again and it should be good now.

$this->phpcsFile->addWarning(
'The parameter %s is an unknown role or capability. Check %s() to ensure it is a capability and not a role.',
$stackPtr,
'PossibleRoleFound',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested alternative: UnknownCapabilityFound


/**
* Array of core capabilities.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document that these are the valid values.


/**
* Array of core roles.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please document that it is undesirable to use these.

In that respect, I would actually reverse the property order in the file. core_capabilities first, core_roles second.

*
* @var array Function name with parameter position.
*/
protected $target_functions = array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any logic to the function order ? I can see they are semi-grouped, but the groups are not annotated, nor are the functions within a group ordered by any logical order.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a bit more documentation.

'author_can' => 2,
'current_user_can_for_blog' => 2,
);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At a later stage, this sniff should probably also check for certain class methods, like WP_User::has_cap().

Might be useful to add a @todo note in the class comment about this or to open an issue for it as a reminder.

@grappler
Copy link
Member

I am happy to make a PR upstream. I will work on here for the time being till it is fully ready.

@jrfnl
Copy link
Contributor

jrfnl commented Mar 26, 2017

@grappler Okidoki. let me know when you're ready for me to have another look.

@grappler
Copy link
Member

I will update it for PHPCS 3.x and push the PR upstream.

@jrfnl
Copy link
Contributor

jrfnl commented May 31, 2018

Once this has been pulled upstream, this PR can be closed and a new PR will need to be opened just to add the new upstream sniff to the ruleset.

@khacoder
Copy link
Contributor Author

I would like to finish this one if I could please.

@jrfnl
Copy link
Contributor

jrfnl commented Jun 1, 2018

@khacoder FYI: @grappler has actually already pulled an updated version to WPCS upstream which includes your original commit for the credits. This PR will be closed in favour of adding the upstream WPCS version to the ruleset once that PR has been merged, so there is nothing here at this moment to continue with.

If you like, you can look over the upstream PR & give feedback there: WordPress/WordPress-Coding-Standards#1364

@khacoder
Copy link
Contributor Author

khacoder commented Jun 1, 2018

OK no problem, you may as well close this one??

@jrfnl
Copy link
Contributor

jrfnl commented Sep 23, 2018

For history:

This PR was closed when we replaced the master/develop branches with the re-organized stand-alone repo.

It will not be re-opened for the following reasons:

  • Once the upstream WPCS PR has been merged, that sniff should be added to the WPThemeReview ruleset instead (or extended).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants