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

Move capabilities check behind admin_init and is_admin #351

Merged

Conversation

BrianHenryIE
Copy link
Contributor

@BrianHenryIE BrianHenryIE commented Sep 13, 2024

Proposed changes

In the ECommerce constructor capabilities checks are being used. In the data module, if the capabilities transient is absent a request is made to Hiive to update it. This expires after four hours.

From what I read, the capabilities checks here are running on every request, meaning every site is polling Hiive for capabilities every four hours.

This change moves the check behind admin_init and is_admin so the capabilities are only fetched when an admin is accessing /wp-admin. The actions and filters that were guarded by the capabilities are all related to admin UI changes (most obviously printing HTML).

8b9c371

https://jira.newfold.com/browse/PRESS0-1016

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Video

Checklist

  • I have read the CONTRIBUTING doc
  • I have viewed my change in a web-browser
  • Linting and tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

  • We are working on related changes in the data module to store the capabilities in an option rather than a transient, and in Hiive to push changes to the capabilities so polling is not necessary.
  • It's unclear to me if the failing tests are caused by this change. One of them is ~expected button not to exist, and the other could not find the my-products table.

@ramyakrishnai ramyakrishnai merged commit 2e8bbee into trunk Sep 18, 2024
5 of 10 checks passed
@ramyakrishnai ramyakrishnai deleted the PRESS0-1016/reduce-http-calls-to-capabilities-endpoint branch September 18, 2024 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants