Skip to content

Fix hardcoded wp-admin URLs#4095

Merged
acicovic merged 4 commits into
developfrom
fix/hardcoded-wp-admin-urls
Mar 30, 2026
Merged

Fix hardcoded wp-admin URLs#4095
acicovic merged 4 commits into
developfrom
fix/hardcoded-wp-admin-urls

Conversation

@acicovic
Copy link
Copy Markdown
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

    • Editor now receives a computed admin URL via a global browser variable.
    • Added a URL helper for constructing Boost Engagement links.
  • Bug Fixes

    • Replaced hardcoded admin paths in settings links and site health messages to respect subdirectory installs.
    • Improved translatable settings link handling and escaping.
  • 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
Copy Markdown
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: fe52510e-c0e4-4ba2-99d7-1453872dfbb0

📥 Commits

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

⛔ 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 (1)
  • src/content-helper/editor-sidebar/tabs/sidebar-tools-tab.tsx

📝 Walkthrough

Walkthrough

Replaces hardcoded /wp-admin/ admin links with dynamically resolved admin URLs: adds a global window.wpParselyAdminUrl via PHP, updates PHP 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(); Site Health link now built via translatable string with sprintf().
Editor Sidebar: PHP injection
src/content-helper/editor-sidebar/class-editor-sidebar.php
Inject window.wpParselyAdminUrl through an inline script using 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 the Boost Engagement link.
Integration Tests
tests/Integration/UI/SettingsPageTest.php, tests/Integration/UI/SiteHealthTest.php
Add tests for subdirectory installs validating Parsely::get_settings_url() and Site Health link generation.
E2E Tests
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/...' (remove leading slash) for correct resolution in subdirectory installs.
Unit Tests (JS)
tests/js/content-helper/editor-sidebar/sidebar-tools-tab.test.tsx
Add Jest tests asserting getBoostEngagementUrl() constructs correct admin URLs for root and 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, enqueue scripts
EditorRun->>Browser: inject inline script: set window.wpParselyAdminUrl
Browser->>TSX: TSX reads window.wpParselyAdminUrl and postId
TSX->>Browser: build Boost Engagement URL via getBoostEngagementUrl(adminUrl, postId)
Browser->>User: user clicks link -> navigate to constructed admin URL

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • vaurdan
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing hardcoded wp-admin URLs to work on subdirectory WordPress installs.
Description check ✅ Passed The description is comprehensive, covering motivation (subdirectory install issues), solution details (use of get_settings_url, wpParselyAdminUrl injection, helper function), bug fix explanation, and testing approach.
Linked Issues check ✅ Passed All requirements from issue #4094 are met: hardcoded URLs in class-site-health.php, class-content-helper-feature.php, and sidebar-tools-tab.tsx are replaced with dynamic URL resolution using get_settings_url() and getBoostEngagementUrl().
Out of Scope Changes check ✅ Passed All changes directly address the linked issues. The updates to TypeScript types, PHP files, tests, and E2E specs are all necessary to implement dynamic admin URL handling and fix the Site Health bug.
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

Review ran into problems

🔥 Problems

Timed out fetching pipeline failures after 30000ms


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
Copy Markdown
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

Comment thread tests/Integration/UI/SettingsPageTest.php
Comment thread tests/Integration/UI/SiteHealthTest.php
@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
@acicovic acicovic merged commit 766f5b0 into develop Mar 30, 2026
37 checks passed
@acicovic acicovic deleted the fix/hardcoded-wp-admin-urls branch March 30, 2026 07:52
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