Skip to content

Fix hardcoded wp-admin URLs#4095

Open
acicovic wants to merge 3 commits intodevelopfrom
fix/hardcoded-wp-admin-urls
Open

Fix hardcoded wp-admin URLs#4095
acicovic wants to merge 3 commits intodevelopfrom
fix/hardcoded-wp-admin-urls

Conversation

@acicovic
Copy link
Collaborator

@acicovic acicovic commented Mar 26, 2026

Summary

Hardcoded /wp-admin/ paths were used in several places to build links to the Parse.ly settings page and the Boost Engagement dashboard. On WordPress sites installed in a subdirectory (e.g. https://example.org/wordpress), the admin URL differs from the site URL and these links would navigate to the wrong location or 404.

Also fixes a pre-existing bug in check_site_id() where the Site Health check entry was silently discarded due to a local variable never being written back to the return value.

Before

  • class-site-health.php, class-content-helper-feature.php, and sidebar-tools-tab.tsx all used hardcoded /wp-admin/admin.php?page=... paths.
  • On subdirectory installs, these links were broken.
  • check_site_id() populated a local $direct variable but returned the unmodified $tests array, so the parsely health check entry was never visible.

After

  • PHP files use Parsely::get_settings_url(), which wraps get_admin_url() and is multisite-aware.
  • The editor sidebar injects window.wpParselyAdminUrl via wp_add_inline_script, and the TSX component builds its URL from that value using the new getBoostEngagementUrl() helper.
  • The $direct bug in check_site_id() is fixed.
  • Integration tests cover the subdirectory install scenario for both get_settings_url() and the Site Health check.
  • E2E specs that navigated with a leading / (origin-relative, breaking on subdirectory baseURL) now use a baseURL-relative path.
  • A unit test covers getBoostEngagementUrl() for both standard and subdirectory install URLs.

Summary by CodeRabbit

  • New Features

    • Dynamic admin URL generation for subdirectory installs; editor UI now receives the computed admin URL.
  • Bug Fixes

    • Replaced hardcoded admin paths in settings links and Boost Engagement to respect subdirectory installs.
    • Improved translatable settings link handling.
  • Tests

    • Added integration, unit, and end-to-end tests covering subdirectory install URL scenarios and URL generation.

@acicovic acicovic added this to the 3.22.1 milestone Mar 26, 2026
@acicovic acicovic self-assigned this Mar 26, 2026
@acicovic acicovic requested a review from a team as a code owner March 26, 2026 16:06
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 26, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e0cc79fb-4ee8-43f6-8652-83e0adbfdc5f

📥 Commits

Reviewing files that changed from the base of the PR and between e7dc3c6 and b552451.

⛔ Files ignored due to path filters (2)
  • build/content-helper/editor-sidebar.asset.php is excluded by !build/**
  • build/content-helper/editor-sidebar.js is excluded by !build/**
📒 Files selected for processing (2)
  • tests/Integration/UI/SettingsPageTest.php
  • tests/Integration/UI/SiteHealthTest.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/Integration/UI/SettingsPageTest.php
  • tests/Integration/UI/SiteHealthTest.php

📝 Walkthrough

Walkthrough

Replaces hardcoded /wp-admin/ admin links with dynamically resolved admin URLs: adds a global window.wpParselyAdminUrl from PHP, updates PHP-generated links to use Parsely::get_settings_url(), and updates TSX and tests to build/use admin URLs from the injected value.

Changes

Cohort / File(s) Summary
Type Declarations
src/@types/assets/window.d.ts
Add required global Window.wpParselyAdminUrl: string.
Site Health & Content Helper (PHP)
src/UI/class-site-health.php, src/content-helper/common/class-content-helper-feature.php
Replace hardcoded /wp-admin/... links with Parsely::get_settings_url() and use sprintf() for translatable Site Health link.
Editor Sidebar: PHP injection
src/content-helper/editor-sidebar/class-editor-sidebar.php
Inject window.wpParselyAdminUrl via inline script (uses admin_url()), emitted before other editor sidebar inline vars.
Editor Sidebar: TSX
src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx
Add exported getBoostEngagementUrl(adminUrl: string, postId: number) and use getBoostEngagementUrl(window.wpParselyAdminUrl, postId) for Boost Engagement link.
Integration Tests
tests/Integration/UI/SettingsPageTest.php, tests/Integration/UI/SiteHealthTest.php
Add tests covering subdirectory installs for get_settings_url() and Site Health link rendering.
Unit Tests (JS)
tests/js/content-helper/editor-sidebar/sidebar-tools-tab.test.tsx
New Jest suite testing getBoostEngagementUrl() for root and subdirectory admin URLs.
E2E Test updates
tests/e2e/specs/front-end-metadata.spec.ts, tests/e2e/specs/settings-track-post-types-as.spec.ts
Change Playwright navigations from '/wp-admin/...' to 'wp-admin/...' (no leading slash) for correct URL resolution in subdirectory installs.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant PHP as PHP Server
participant EditorRun as Editor_Sidebar::run()
participant Browser as Browser Window
participant TSX as Sidebar Tools TSX
PHP->>EditorRun: render/editor sidebar page
EditorRun->>Browser: inject inline script (window.wpParselyAdminUrl)
Browser->>TSX: TSX reads window.wpParselyAdminUrl and postId
TSX->>Browser: build Boost Engagement URL via getBoostEngagementUrl(adminUrl, postId)
Browser->>User: navigate to constructed admin URL when link clicked

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • #2877 — Modifies the Settings page and related integration tests (overlaps SettingsPageTest.php).
  • #3186 — Also adjusts admin settings URL usage across Site Health and settings-related code paths.
  • #3210 — Adds window.* properties and inline script injections in Editor_Sidebar::run, similar injection changes.

Suggested labels

Maintenance, Feature: Traffic Boost

Suggested reviewers

  • vaurdan
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix hardcoded wp-admin URLs' accurately summarizes the main change: replacing hardcoded URL paths with dynamic resolution.
Description check ✅ Passed The description comprehensively covers all required sections: summary of the problem, before/after comparison, and testing approach with specific examples.
Linked Issues check ✅ Passed The pull request fully addresses all requirements from issue #4094: replaced hardcoded paths in class-site-health.php, class-content-helper-feature.php, and sidebar-tools-tab.tsx with dynamic URL resolution.
Out of Scope Changes check ✅ Passed All changes directly support the issue objectives: hardcoded URL replacement, type definitions, tests, and e2e fixes for subdirectory installs are all in-scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 fix/hardcoded-wp-admin-urls

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.44)

Invalid configuration:
Unexpected item 'parameters › type_coverage'.


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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/Integration/UI/SettingsPageTest.php`:
- Around line 603-610: This test changes the global siteurl and never restores
it; capture the original siteurl with get_option('siteurl') before calling
update_option('siteurl', ...) and ensure it is restored after the assertion (use
a try/finally in the test method surrounding update_option and the
self::$parsely::get_settings_url() assertion, or restore in tearDown) so other
tests are not polluted.

In `@tests/Integration/UI/SiteHealthTest.php`:
- Around line 67-96: Capture the original siteurl before calling
update_option('siteurl', 'http://example.org/wordpress') and restore it in a
finally block so the test doesn't leak global state; e.g., store $original =
get_option('siteurl') before the update, run the existing re-instantiation and
assertions, and in finally call update_option('siteurl', $original) to revert it
(make this change inside the same test method that calls
Site_Health::__construct / Parsely and uses self::$site_health).
🪄 Autofix (Beta)

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 300af20a-52b8-4937-b13b-af688ac11bf9

📥 Commits

Reviewing files that changed from the base of the PR and between 9555c42 and e7dc3c6.

📒 Files selected for processing (10)
  • src/@types/assets/window.d.ts
  • src/UI/class-site-health.php
  • src/content-helper/common/class-content-helper-feature.php
  • src/content-helper/editor-sidebar/class-editor-sidebar.php
  • src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx
  • tests/Integration/UI/SettingsPageTest.php
  • tests/Integration/UI/SiteHealthTest.php
  • tests/e2e/specs/front-end-metadata.spec.ts
  • tests/e2e/specs/settings-track-post-types-as.spec.ts
  • tests/js/content-helper/editor-sidebar/sidebar-tools-tab.test.tsx

@acicovic acicovic added Changelog: Fixed PR to be added under the changelog's "Fixed" section Feature: PCI Ticket/PR related to Content Intelligence labels Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Changelog: Fixed PR to be added under the changelog's "Fixed" section Feature: PCI Ticket/PR related to Content Intelligence

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix hardcoded wp-admin URLs

1 participant