Add a current_user_can
check to our cache clearing method
#309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
In #90 we introduced an admin setting that allows on-demand clearing of avatar cache, useful for situations where image sizes have changed and SLA still has the old image sizes stored.
This setting outputs a button that when clicked, fires an AJAX request to kick off the cache clearing process. This request does pass and validate a proper nonce but doesn't have any user capability check. This means in theory anyone that has a user account on the site can generate a nonce and make a direct request to the proper AJAX endpoint to trigger that cache clearing.
This PR fixes that by adding a
current_user_can( 'manage_options' )
check, as only users with that capability can access theSettings > Discussion
page to begin with and thus should be the only ones that can initiate this cache clearing.How to test the Change
Settings > Discussion
Clear local avatar cache
setting and click theClear cache
buttonThe test above ensures things still work as expected but does not verify things are more secure. If desired, can provide details on how to test that, which requires making direct requests to the AJAX endpoint.
Changelog Entry
Credits
Props @dkotter, @truonghuuphuc
Checklist: