Skip to content

Permit running requests as frontend vs. backend based on URL#216

Merged
swissspidy merged 7 commits intomainfrom
copilot/permit-running-requests-frontend-backend
Mar 20, 2026
Merged

Permit running requests as frontend vs. backend based on URL#216
swissspidy merged 7 commits intomainfrom
copilot/permit-running-requests-frontend-backend

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

When --url points to a wp-admin path, the profiler was still running the full frontend flow (wp() + template loading), causing redirects and failures. The request type should be inferred from the URL, and --context=admin is required for a correct admin simulation.

Changes

  • Admin URL detection (Profiler::run()): Sets $is_admin_request = true when the configured URL matches #/wp-admin(/|$)#i. This fires before any hooks are registered.
  • Enforce --context=admin (Profiler::run()): Emits a fatal error when an admin URL is detected but --context=admin was not supplied, so users are not silently profiling with is_admin() returning false and no admin user set up.
  • Skip frontend stages (load_wordpress_with_template()): Returns early after bootstrap completes when $is_admin_request is true — skips wp() and template-loader.php, which do not apply to admin requests and are the source of the redirect failures.
# Profile bootstrap stage only, as a properly simulated admin request
wp profile stage --url=example.com/wp-admin/ --context=admin --fields=stage

Test

  • Updated the existing Behat scenario to include --context=admin for the successful admin URL case.
  • Added a new Behat scenario asserting that omitting --context=admin with an admin URL produces an error with exit code 1.
Original prompt

This section details on the original issue you should resolve

<issue_title>Permit running requests as frontend vs. backend</issue_title>
<issue_description>We should only load the request as backend when the user explicitly designates such:

wp profile stage --url=domain.com/wp-admin/
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@schlessera</author><body>
@pioneerskies I just tried, as I thought it would be a simple matter of adding an authorized `--user=<user>` to the request, but It seems to always fail because of a redirect. I'll have to investigate this in more detail, but at first glance, the profiling seems to work on the frontend only right now.</body></comment_new>
</comments>


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

@github-actions github-actions bot added command:profile-stage Related to 'profile stage' command scope:distribution Related to distribution labels Mar 19, 2026
@codecov
Copy link

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix request loading as frontend vs backend Permit running requests as frontend vs. backend based on URL Mar 19, 2026
Copilot AI requested a review from swissspidy March 19, 2026 12:54
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
@swissspidy swissspidy marked this pull request as ready for review March 20, 2026 09:47
@swissspidy swissspidy requested a review from a team as a code owner March 20, 2026 09:47
Copilot AI review requested due to automatic review settings March 20, 2026 09:47

This comment was marked as resolved.

swissspidy and others added 3 commits March 20, 2026 11:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@swissspidy swissspidy merged commit 8fb8768 into main Mar 20, 2026
60 checks passed
@swissspidy swissspidy deleted the copilot/permit-running-requests-frontend-backend branch March 20, 2026 11:53
@swissspidy swissspidy added this to the 2.1.7 milestone Mar 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:profile-stage Related to 'profile stage' command scope:distribution Related to distribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Permit running requests as frontend vs. backend

3 participants