Skip to content

GH#1716: optimize front-end My Sites toolbar - #1719

Open
superdav42 wants to merge 4 commits into
mainfrom
feature/auto-20260810-142725-gh1716
Open

GH#1716: optimize front-end My Sites toolbar#1719
superdav42 wants to merge 4 commits into
mainfrom
feature/auto-20260810-142725-gh1716

Conversation

@superdav42

@superdav42 superdav42 commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add an opt-in setting to limit front-end My Sites toolbar preparation to the active site.
  • Preserve complete My Sites and administration listings by requiring the WordPress admin-bar initialization call path.
  • Cover the setting default, toolbar scope, and one-site result.

Verification

  • vendor/bin/phpcs inc/class-settings.php inc/managers/class-site-manager.php tests/WP_Ultimo/Managers/Site_Manager_Test.php tests/WP_Ultimo/Settings_Test.php
  • vendor/bin/phpunit --filter test_frontend_my_sites_toolbar_optimization --debug
  • vendor/bin/phpunit --filter Settings_Test

Known verification limitation

vendor/bin/phpunit --filter Site_Manager_Test stops when an existing test accesses unavailable database tables; the three new focused Site_Manager tests pass.

Resolves #1716

Summary by CodeRabbit

  • New Features
    • Added an optional setting to optimize the front-end “My Sites” toolbar.
    • When enabled, the toolbar loads only the current site, improving efficiency.
    • The optimization is disabled by default and applies only to eligible front-end toolbar requests.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a disabled-by-default Sites setting for frontend My Sites toolbar optimization. When enabled for eligible authenticated frontend toolbar requests, the site manager returns only the current site and preserves existing behavior in excluded contexts.

Changes

Frontend My Sites toolbar optimization

Layer / File(s) Summary
Setting and toolbar request scope
inc/class-settings.php, inc/managers/class-site-manager.php, tests/WP_Ultimo/Managers/Site_Manager_Test.php, tests/WP_Ultimo/Settings_Test.php
Registers the optimize_frontend_my_sites_toolbar toggle with default 0. Detects WP_Admin_Bar::initialize requests only when enabled and excludes admin, AJAX, cron, REST, CLI, logged-out, and non-toolbar contexts.
Current-site result path
inc/managers/class-site-manager.php, tests/WP_Ultimo/Managers/Site_Manager_Test.php
Returns the current site in the toolbar’s expected site-object format and verifies that the optimized result contains only the current site. Tests also verify filter application and state cleanup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant WP_Admin_Bar
  participant Site_Manager
  participant Current_Site
  WP_Admin_Bar->>Site_Manager: request frontend toolbar sites
  Site_Manager->>Current_Site: get current site
  Current_Site-->>Site_Manager: current site data
  Site_Manager-->>WP_Admin_Bar: return current site only
Loading

Suggested labels: review-feedback-scanned

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The implementation meets the setting and scoped optimization goals, but it lacks the required performance regression evidence and complete acceptance-test coverage [#1716]. Add bounded performance instrumentation or a regression test, and cover the required admin, non-toolbar, role, and multisite cases [#1716].
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: optimizing the front-end My Sites toolbar.
Out of Scope Changes check ✅ Passed The changes are limited to the requested setting, scoped Site Manager optimization, and related tests [#1716].
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-20260810-142725-gh1716

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@superdav42
superdav42 marked this pull request as ready for review August 10, 2026 20:37
@superdav42

Copy link
Copy Markdown
Collaborator Author

Merge summary

  • Adds an opt-in setting that limits front-end My Sites toolbar preparation to the current site.
  • Scopes the fast path to WP_Admin_Bar::initialize() so wp-admin, REST, CLI, AJAX, cron, and ordinary get_blogs_of_user() calls keep their existing behavior.
  • Adds setting and focused manager coverage.

Verification

  • Passed: vendor/bin/phpcs inc/class-settings.php inc/managers/class-site-manager.php tests/WP_Ultimo/Managers/Site_Manager_Test.php tests/WP_Ultimo/Settings_Test.php (existing warnings only)
  • Passed: vendor/bin/phpunit --filter test_frontend_my_sites_toolbar_optimization --debug
  • Passed: vendor/bin/phpunit --filter Settings_Test
  • Environment limitation: the full Site_Manager_Test filter stops on unavailable database tables outside this change; focused new tests pass.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@ultimate-multisite ultimate-multisite Bot added the status:in-review PR open, awaiting review/merge label Aug 10, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@inc/managers/class-site-manager.php`:
- Around line 1166-1168: Update the optimized branch in pre_get_blogs_of_user so
the result from get_current_site_for_frontend_my_sites_toolbar is passed through
the same get_blogs_of_user filter as the normal path before returning. Add a
regression test covering the frontend My Sites toolbar optimization and
verifying that the filter can modify the returned site list.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fbbced2f-f4e5-4ca5-83dd-a8b2fa780b12

📥 Commits

Reviewing files that changed from the base of the PR and between 75e3b0e and 1a7fd67.

📒 Files selected for processing (4)
  • inc/class-settings.php
  • inc/managers/class-site-manager.php
  • tests/WP_Ultimo/Managers/Site_Manager_Test.php
  • tests/WP_Ultimo/Settings_Test.php

Comment thread inc/managers/class-site-manager.php
@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
tests/WP_Ultimo/Managers/Site_Manager_Test.php (2)

15-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consume the test override parameter.

PHPMD reports $backtrace as an unused formal parameter. Keep the parameter for signature compatibility, then add unset($backtrace); or a targeted suppression.

Proposed fix
 	protected function is_frontend_my_sites_toolbar_request($backtrace = null) {
 
+		unset($backtrace);
+
 		return true;
 	}

Based on static analysis, PHPMD reports UnusedFormalParameter for $backtrace.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WP_Ultimo/Managers/Site_Manager_Test.php` around lines 15 - 17, Update
is_frontend_my_sites_toolbar_request to consume the intentionally retained
$backtrace parameter by unsetting it before returning true, preserving signature
compatibility while resolving PHPMD’s UnusedFormalParameter warning.

Source: Linters/SAST tools


2979-2979: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use wu_create_*() helpers for test users.

The three new tests call $this->factory()->user->create(). Replace these calls with the applicable project helper that returns the required user ID. Keep the super-admin grant and cleanup unchanged.

As per coding guidelines, tests must use wu_create_*() helper functions to set up test data.

Also applies to: 3010-3010, 3043-3043

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WP_Ultimo/Managers/Site_Manager_Test.php` at line 2979, Replace the
three test user setups in the affected tests with the applicable wu_create_*()
helper that returns an administrator user ID. Preserve the existing super-admin
grant and cleanup logic unchanged.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/WP_Ultimo/Managers/Site_Manager_Test.php`:
- Around line 15-17: Update is_frontend_my_sites_toolbar_request to consume the
intentionally retained $backtrace parameter by unsetting it before returning
true, preserving signature compatibility while resolving PHPMD’s
UnusedFormalParameter warning.
- Line 2979: Replace the three test user setups in the affected tests with the
applicable wu_create_*() helper that returns an administrator user ID. Preserve
the existing super-admin grant and cleanup logic unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 908cf389-40b4-4e44-948c-eec983f22d3c

📥 Commits

Reviewing files that changed from the base of the PR and between 1a7fd67 and 4dc8761.

📒 Files selected for processing (2)
  • inc/managers/class-site-manager.php
  • tests/WP_Ultimo/Managers/Site_Manager_Test.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • inc/managers/class-site-manager.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:in-review PR open, awaiting review/merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add an opt-in optimized front-end My Sites toolbar

1 participant