-
-
Notifications
You must be signed in to change notification settings - Fork 67
Fix template switching #280
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThe changes expand AJAX endpoint routing for field template rendering, implement a capability-based access control system using 'wu_manage_membership', introduce capability grant logic for administrators, add template string validation, and make minor UI/text adjustments across multiple customer panel pages. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
inc/checkout/signup-fields/class-signup-field-template-selection.php (1)
351-357: Behavioral change in category defaulting logicLine 355 changed from the Elvis operator (
?-) to null coalescing (??), which alters how missing categories are handled. The old?-triggered the fallback for any falsy value (empty array, empty string,false,0), whereas??only triggers onnullorundefined. This means stored field configurations with explicitly empty category lists will now be treated as "no categories" instead of falling back to "all categories". Verify that no existing saved field configurations depend on the previous behavior where empty values implicitly meant "show all categories".
🧹 Nitpick comments (1)
assets/js/checkout.js (1)
734-742: Routewu_render_field_templatethroughlate_ajaxurlIncluding
wu_render_field_templatein the set of actions usingwu_checkout.late_ajaxurlmakes its routing consistent withwu_validate_formandwu_create_order, which should help when template rendering depends on late-bound context. If more actions follow this pattern later, consider extracting the hard-coded list into a small helper/constant for maintainability.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (12)
assets/js/checkout.js(1 hunks)inc/admin-pages/customer-panel/class-account-admin-page.php(1 hunks)inc/admin-pages/customer-panel/class-add-new-site-admin-page.php(1 hunks)inc/admin-pages/customer-panel/class-checkout-admin-page.php(1 hunks)inc/admin-pages/customer-panel/class-my-sites-admin-page.php(1 hunks)inc/admin-pages/customer-panel/class-template-switching-admin-page.php(1 hunks)inc/checkout/signup-fields/class-signup-field-template-selection.php(1 hunks)inc/class-wp-ultimo.php(2 hunks)inc/managers/class-field-templates-manager.php(1 hunks)inc/managers/class-site-manager.php(1 hunks)inc/ui/class-site-actions-element.php(1 hunks)views/admin-pages/fields/field-note.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
views/admin-pages/fields/field-note.php (1)
inc/functions/helper.php (1)
wu_kses_allowed_html(326-589)
inc/class-wp-ultimo.php (1)
inc/functions/customer.php (1)
wu_get_customer_by_user_id(97-100)
inc/checkout/signup-fields/class-signup-field-template-selection.php (1)
inc/models/class-site.php (2)
Site(26-1915)get_all_categories(1840-1884)
inc/ui/class-site-actions-element.php (4)
inc/admin-pages/class-base-admin-page.php (1)
get_id(236-239)inc/limitations/class-limit.php (1)
get_id(168-171)inc/ui/class-base-element.php (1)
get_id(961-964)inc/models/class-base-model.php (1)
get_id(427-430)
🪛 PHPMD (2.15.0)
inc/class-wp-ultimo.php
969-969: Avoid unused parameters such as '$args'. (undefined)
(UnusedFormalParameter)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cypress (8.1, chrome)
- GitHub Check: cypress (8.2, chrome)
🔇 Additional comments (11)
inc/managers/class-site-manager.php (1)
170-172: Clearer not-owner error messageThe updated copy (“add a site to this membership”) is grammatically clearer and better reflects the action, with no behavioral impact.
views/admin-pages/fields/field-note.php (1)
29-32: Safer handling of optional field descriptionDefaulting
$field->descto an empty string before passing towp_kses()makes this view more robust whendescis null or unset, without changing output semantics when it is set.inc/admin-pages/customer-panel/class-my-sites-admin-page.php (1)
71-74: My Sites page now gated bywu_manage_membershipSwitching both
admin_menuanduser_admin_menuto requirewu_manage_membershipaligns this page with the new capability model and centralizes access control. Please confirm that all intended customer/admin roles receive this capability so existing users don’t unexpectedly lose access to the My Sites page.inc/admin-pages/customer-panel/class-add-new-site-admin-page.php (1)
87-90: Add New Site page now restricted towu_manage_membershipRequiring
wu_manage_membershipfor both admin and user panels is consistent with the rest of the customer-panel changes and clearly ties “add site” to membership management. Please verify that customers who should be able to add sites are granted this capability, or they’ll lose access to this page.inc/admin-pages/customer-panel/class-account-admin-page.php (1)
71-74: Account page now requireswu_manage_membershipUsing
wu_manage_membershipfor bothadmin_menuanduser_admin_menustandardizes access control for the Account page with the rest of the customer panel. Please confirm that the new capability grant logic covers all users who should still see their Account page in wp-admin.inc/admin-pages/customer-panel/class-template-switching-admin-page.php (1)
61-64: Template Switching page aligned withwu_manage_membershipcapabilityRequiring
wu_manage_membershipfor both user and admin menus brings the Template Switching page in line with the rest of the membership-driven customer panel. Ensure that any users who previously could switch templates (via the oldreadgating) are correctly grantedwu_manage_membershipso they retain access.inc/class-wp-ultimo.php (2)
214-214: LGTM! Filter hook correctly registered.The
user_has_capfilter is properly registered to enable dynamic capability granting for thewu_manage_membershipcapability.
954-986: Caching is already implemented via the Query class.The customer lookup already benefits from WordPress object caching. The
Customer_Queryclass (which handles customer lookups viaget_by()) is configured withcache_group = 'customers'andglobal_cache = true. The parentQueryclass registers these groups withwp_cache_add_global_groups()in its constructor, so database queries are cached at the WordPress object cache level.No additional caching layer is needed.
inc/ui/class-site-actions-element.php (1)
373-382: LGTM! URL construction improved.The addition of
'admin.php'as the second parameter toget_admin_url()makes the URL construction more explicit and ensures the template switching link targets the correct admin page structure.inc/managers/class-field-templates-manager.php (1)
62-64: LGTM! Essential input validation added.This validation properly guards against malformed template names that would cause array index errors on lines 66 and 72. The check ensures the template string contains the required format (e.g.,
field_type/template_id) before proceeding with rendering.inc/admin-pages/customer-panel/class-checkout-admin-page.php (1)
61-64: Capability change is properly gated and allows legitimate access.The
grant_customer_capabilities()method ininc/class-wp-ultimo.phpcorrectly handles the new'wu_manage_membership'requirement. The logic grants this capability only to users who:
- Have the
'manage_options'capability (administrators)- Are registered as Ultimate Multisite customers
All administrators who are customers will receive access as intended. Non-admin customers and non-customer administrators are properly denied access, which is the intended behavior.
Summary by CodeRabbit
Bug Fixes
Improvements
✏️ Tip: You can customize this high-level summary in your review settings.