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

Always hide AMP admin menu item and compatibility tool menu items for non-admins role #3005

Merged
merged 8 commits into from
Aug 12, 2019

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Aug 9, 2019

See https://wordpress.org/support/topic/hide-amp-in-side-bar-for-specific-roles-authors/

When a user is not an administrator, they still have access to the AMP settings screen but all of the fields on the screen are disabled and they can't modify anything. This was allowed because the Validated URLs and Validation Error screens are are admin submenu items under the top-level AMP menu page. Thus the top-level page was given edit_posts capability, though all of the settings required manage_options to change.

The thinking here was to allow the users to access the admin screens the compatibility tool even if they cannot manage_options. In reality, this is just noise and non-admins should not be concerned with site-level validation errors. See #2316 (comment) and #2673.

Nevertheless, a case can be made to continue allowing a user to access the Validated URL screen individually for posts that they can edit. This is what this PR does. Non-admin users never see the top-level AMP admin menu item, and they never see the admin menu items for Validated URLs and Validation Errors. The only way they can get to these screens is by causing a validation error, at which point they will see the warning notice in Gutenberg, allowing them to access the screen via the “Review Issues” link.

This PR also hides the Validated URLs from the “At a Glance” dashboard widget, if the user is not an administrator.

Before

Screen Shot 2019-08-09 at 13 21 14

After

Screen Shot 2019-08-09 at 13 20 08


Build for testing: amp.zip - 1.2.1-beta1-20190809T205628Z-303e81ea

Fixes #2702.

@westonruter westonruter added this to the v1.2.1 milestone Aug 9, 2019
@googlebot googlebot added the cla: yes Signed the Google CLA label Aug 9, 2019
@@ -994,6 +975,9 @@ public function test_add_admin_notices() {
* @covers \AMP_Validation_Error_Taxonomy::filter_tag_row_actions()
*/
public function test_filter_tag_row_actions() {
wp_set_current_user( $this->factory()->user->create( [ 'role' => 'administrator' ] ) );
global $pagenow;
$pagenow = 'edit-tags.php';
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm confused as to why this is needed now. Perhaps global state had set it before.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this seems to be the case.

@westonruter westonruter marked this pull request as ready for review August 9, 2019 20:22
Copy link
Collaborator

@swissspidy swissspidy left a comment

Choose a reason for hiding this comment

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

Welcome change! Works as expected.

@swissspidy swissspidy merged commit 2987b5f into develop Aug 12, 2019
@swissspidy swissspidy deleted the fix/admin-menu-items branch August 12, 2019 10:32
westonruter added a commit that referenced this pull request Aug 12, 2019
…p-bind-syntax

* 'develop' of github.com:ampproject/amp-wp:
  RTLCSS all the things (#2977)
  Fix AMP Story editor compatibility with code editor (#3007)
  Update dependency core-js to v3.2.1 (#3011)
  Update amphtml validator spec to v1907301630320 (#3003)
  Improve handling of unlisted Vimeo videos (#2986)
  Always hide AMP admin menu item and compatibility tool menu ite… (#3005)
  Update dependency dom-scroll-into-view to v2.0.1 (#3008)
  Hide tooltips that should be hidden (#2988)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Signed the Google CLA
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inconsistent capability checks on settings page
3 participants