-
Notifications
You must be signed in to change notification settings - Fork 101
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
VIP Cache Manager: implement "Purge page and its assets" admin bar button #1880
Conversation
Nice work! Quick thought: we should add some stats for how often this is used and by which sites (probably easiest using |
btn.removeEventListener('click', onClickHandler); | ||
} catch (err) { | ||
purgeQueried = false; | ||
btn.textContent = '❌ Cache Purge Failed'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there the option to use https://make.wordpress.org/accessibility/handbook/markup/wp-a11y-speak/ here, so that screen reader users get notified on the success / failure of the action?
…-go-cache-manager-action and vip-go-cache-manager-url-purge-by-site for unsuccessful requests
@mjangda I've recreated your suggestions via a separate commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks pretty solid. Spotted a couple of small things.
wp_send_json_error( [ 'error' => 'Malformed payload' ], 400 ); | ||
} | ||
|
||
if ( ! ( current_user_can( 'manage_options' ) && isset( $req->nonce ) && wp_verify_nonce( $req->nonce, 'purge-page' ) ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would split these up because it's very easy to introduce a mistake with a long conditional like this. We can then also separate the deny stats into deny-permissions
and deny-nonce
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, will address.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I've split the check into two, as proposed.
vip-cache-manager/js/admin-bar.js
Outdated
@@ -0,0 +1,69 @@ | |||
(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This javascript file needs more ( nacin spacin )
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prettier
doesn't like ( nacin spacin )
but let me see what I can do short of fixing each occurrence manually :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applied eslint-config-wpvip
to the file (will work on adding it to the repo in a separate PR)
props @mjangda Co-authored-by: Mohammad Jangda <[email protected]>
…issions and the other one for nonces to make it less error-prone and easier to digest
Otherwise load order issues can mean that our onClick doesn't actually register.
No point in triggering a success status there.
Props @emrikol for the initial pass at this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and working great!
stacks-r1307 |
Description
This PR adds an Admin Bar button that allows a user to purge the current page and all its external (as opposed to inline) styles and scripts.
Checklist
Please make sure the items below have been covered before requesting a review:
Steps to Test
Considerations
manage_options
which may limit the usefulness.