Make WordPress Core

Opened 4 years ago

Last modified 3 months ago

#56302 new defect (bug)

Admin menu links have relative URLs

Reported by: iihglobal Owned by:
Priority: normal Milestone: Awaiting Review
Component: Administration Version:
Severity: normal Keywords: has-screenshots dev-feedback has-patch has-test-info has-unit-tests
Cc: Focuses: administration

Description (last modified by sabernhardt)

Hey,

When i opened abc.com/wp-admin/options.php/ and then try to go on submenu under settings then menu link is wrong and not opening page. more information you can see quick recording.

​https://www.loom.com/share/e64670a986df4c5da8e81838799a7ea1

Thank you

Attachments (2)

Settings-menu-29-July-2022.mp4​ (4.1 MB ) - added by sabernhardt 4 years ago.
56302.diff​ (3.5 KB ) - added by costdev 4 years ago.
Use WP_Http::make_absolute_url() with admin_url() to make admin menu links relative to admin_url(). WP_Http::make_absolute_url() documentation states: "If an Absolute URL is provided, no processing of that URL is done."

Change History (8)

#1 @Tyrannous
4 years ago

#56303 was marked as a duplicate.

#2 @sabernhardt
4 years ago

  • Component Menus → Administration
  • Description modified (diff)
  • Summary Menu link on admin side → Admin menu links have relative URLs
  • Version 6.0

The trailing slash at the end of the options.php/ address is important to reproduce the error (@audrasjb tried on #56303). With relative links, the resulting URLs like abc.com/wp-admin/options.php/options-general.php keep opening the options.php page.

A plugin might have added the slash character, but maybe this situation is avoidable.

@costdev
4 years ago

Use WP_Http::make_absolute_url() with admin_url() to make admin menu links relative to admin_url(). WP_Http::make_absolute_url() documentation states: "If an Absolute URL is provided, no processing of that URL is done."

#3 @costdev
4 years ago

  • Keywords dev-feedback has-patch has-testing-info needs-testing added

56302.diff is one way to resolve this issue by converting relative URLs to absolute URLs, relative to admin_url().

Testing Instructions

Steps to Reproduce

  1. Navigate to /wp-admin/options.php/ - Note the trailing slash.
  2. Click General.
  3. 🐞 The contents do not change, but the URL changes to /wp-admin/options.php/options-general.php.
  4. Apply 56302.diff.
  5. Navigate to /wp-admin/options.php/ - Note the trailing slash.
  6. Click General.

Expected Results

  • 🐞 Before the patch: The options.php page's contents remain, but the URL changes to /wp-admin/options.php/options-general.php.
  • ✅ After the patch: The contents change to the General page's contents, and the URL is /wp-admin/options-general.php.

Notes

  • This patch is an example of one approach. Be aware that there are further changes required to the WP_List_Tables views links, as well as all other relative links throughout the Dashboard. Not all would need WP_Http::make_absolute_url(), some just need to be wrapped in admin_url(). I'm happy to continue this work to address the other areas, if this approach is desired.
  • Adding dev-feedback to see if this approach is desired or if there are other ideas of how to manage this throughout the Dashboard.
Last edited 4 years ago by costdev (previous) (diff)

#4 @sumitsingh
4 years ago

  • Keywords has-unit-tests added; needs-testing removed

I have tested as per solution shared by @costdev in 56302.diff and working fine.

Below you can watch the quick recording.

​https://www.awesomescreenshot.com/video/12221736?key=5d95b211f59e65412ba2f0c494036639

#5 @wordpressdotorg
18 months ago

  • Keywords has-test-info added; has-testing-info removed

#6 @arkaprabhachowdhury
3 months ago

Opened [PR #12397](​https://github.com/WordPress/wordpress-develop/pull/12397) to address this ticket. This updates admin menu rendering so generated menu item href values use absolute URLs in the current admin context, while preserving already absolute/external URLs. Validation: - php -l src
wp-admin
menu-header.php - php -l tests
phpunit
tests
admin
menuHeader.php - php vendor
squizlabs
php_codesniffer
bin
phpcbf --standard=phpcs.xml.dist src
wp-admin
menu-header.php tests
phpunit
tests
admin
menuHeader.php - php vendor
squizlabs
php_codesniffer
bin
phpcs --standard=phpcs.xm The PR includes focused regression coverage, and its validation details are recorded in the PR description.

I picked this up because the ticket describes a concrete core behavior or edge case that remains relevant in current WordPress. The proposed change is intentionally scoped to the ticket and is submitted here for code review, with the technical discussion remaining on this ticket.

Note: See TracTickets for help on using tickets.