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

Empty settings page for users with custom role having the manage_options capability #544

Open
2 tasks done
rvdsteege opened this issue Apr 3, 2024 · 3 comments · May be fixed by #546
Open
2 tasks done

Empty settings page for users with custom role having the manage_options capability #544

rvdsteege opened this issue Apr 3, 2024 · 3 comments · May be fixed by #546

Comments

@rvdsteege
Copy link

Confirmation

  • My issue isn't already found on the issue tracker.
  • I have replicated my issue using the latest version of the plugin and it is still present.

WordPress version

6.4.3

Cloudflare-WordPress version

4.12.6

PHP version

7.4.33

Expected result

A user with a custom role which has the manage_options capability, being able to purge the cache through the Settings → Cloudflare page.

Actual result

When clicking the "Cloudflare" admin menu item, an empty page is displayed and CONFIG_FETCH_ERROR and ZONES_FETCH_ERRORS errors occur in the console.

Steps to reproduce

  1. Create a user with custom role, having the manage_options capability (e.g. using the Members plugin; https://wordpress.org/plugins/members/)
  2. Visit Settings → Cloudflare

Additional factoids

It appears that the changes from #529 are causing the issues (released in version 4.12.3). The "Cloudflare" admin menu item requires the manage_options capability and the WordPress AJAX action cloudflare_proxy — which seems needed to load the settings page — is checking for the administrator role.

public function cloudflareConfigPage()
{
if (function_exists('add_options_page')) {
add_options_page(__('Cloudflare Configuration'), __('Cloudflare'), 'manage_options', 'cloudflare', array($this, 'cloudflareIndexPage'));
}
}

public function run()
{
if (!$this->wordpressAPI->isCurrentUserAdministrator()) {
return;
}

It might be better to check against the manage_options capability in the proxy too, so both will be checking the same requirement to access the settings page.


Also, as mentioned in the WordPress developer documentation at https://developer.wordpress.org/reference/functions/current_user_can/, checking against a role instead of a capability using current_user_can() is discouraged:

While checking against particular roles in place of a capability is supported in part, this practice is discouraged as it may produce unreliable results.

/**
* @return boolean
*/
public function isCurrentUserAdministrator()
{
return $this->wordPressWrapper->currentUserCan('administrator');
}

public function currentUserCan($capabilities)
{
return current_user_can($capabilities);
}

References

#529

rvdsteege added a commit to rvdsteege/Cloudflare-WordPress that referenced this issue Jul 29, 2024
Fix empty settings page for users with `manage_options` capability (cloudflare#544).
rvdsteege added a commit to rvdsteege/Cloudflare-WordPress that referenced this issue Jul 29, 2024
Copy link

github-actions bot commented Oct 1, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Oct 1, 2024
@remcotolsma
Copy link

Is there someone from the @cloudflare team who can review the PR and merge it if possible?

@github-actions github-actions bot removed the Stale label Oct 2, 2024
@rvdsteege
Copy link
Author

As I have not heard anything since opening this issue in April, I reported it through Cloudflare support. The case ID is 01317769.

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