Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken category links when removing category base #4922

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

philipjohn
Copy link
Contributor

@philipjohn philipjohn commented Oct 5, 2023

Description

Calls to get_term_link() and get_category_link() should always return a full URL, but wpcom_vip_load_category_base() has been breaking that behaviour. This fix restores the correct functioning by using home_url() to ensure there is a full URL.

Fixes #4541

Changelog Description

Fix broken category links when removing category base

Calls to get_term_link() and get_category_link() should always return a full URL, but wpcom_vip_load_category_base() has been breaking that behaviour. This fix restores the correct functioning by using home_url() to ensure there is a full URL.

Pre-review checklist

Please make sure the items below have been covered before requesting a review:

  • This change works and has been tested locally (or has an appropriate fallback).
  • This change works and has been tested on a Go sandbox.
  • This change has relevant unit tests (if applicable).
  • This change uses a rollout method to ease with deployment (if applicable - especially for large scale actions that require writes).
  • This change has relevant documentation additions / updates (if applicable).
  • I've created a changelog description that aligns with the provided examples.

Pre-deploy checklist

  • VIP staff: Ensure any alerts added/updated conform to internal standards (see internal documentation).

Steps to Test

  1. Using WP-CLI or theme code, call get_category_link(CATEGORYID) with a valid category ID and note the absolute URL.
  2. Add wpcom_vip_load_category_base(''); to the themes function file or an mu-plugin.
  3. Repeat step 1 and note that you now get a relative URL returned instead of an absolute one.
  4. Apply this patch and repeat step 1 and observe you now have a full URL again

Calls to get_term_link() and get_category_link() should always return a full URL, but wpcom_vip_load_category_base() has been breaking that behaviour. This fix restores the correct functioning by using `home_url()` to ensure there is a full URL.
@philipjohn philipjohn requested a review from a team as a code owner October 5, 2023 10:15
@codecov
Copy link

codecov bot commented Oct 5, 2023

Codecov Report

Merging #4922 (ed0b0c8) into develop (90bd992) will decrease coverage by 3.13%.
Report is 794 commits behind head on develop.
The diff coverage is 0.00%.

@@              Coverage Diff              @@
##             develop    #4922      +/-   ##
=============================================
- Coverage      32.29%   29.17%   -3.13%     
- Complexity      3771     4744     +973     
=============================================
  Files            226      278      +52     
  Lines          16807    20887    +4080     
=============================================
+ Hits            5428     6093     +665     
- Misses         11379    14794    +3415     
Files Coverage Δ
vip-helpers/vip-permastructs.php 0.00% <0.00%> (ø)

... and 177 files with indirect coverage changes

@WPprodigy
Copy link
Contributor

Hey Phillip 😃 !

Thanks for the patch. I'll give this some testing just to make sure there won't be any unexpected side-effects.

As an aside, I rather would like to deprecate the wpcomvip-era custom rewrite rules eventually. Some context in this issue, such as: #1141 (comment)

@WPprodigy
Copy link
Contributor

WPprodigy commented Oct 9, 2023

Setting an empty string as the category base via wpcom_vip_load_category_base( '' ) doesn't seem to really work for me as far as actually loading a category page - WP doesn't seem to find the route. Same with wpcom_vip_load_tag_base( '' );, except it won't even respect the empty string and still defaults to /tag.

That said, I can see the issue with direct function calls like get_category_link(10, 'category'). Tested both child and parent categories and the patch does seem sound. Confirmed that get_term_link() uses home_url() in the same way.

@WPprodigy WPprodigy merged commit f944772 into Automattic:develop Oct 9, 2023
28 of 29 checks passed
andrea-sdl pushed a commit that referenced this pull request Oct 19, 2023
Calls to get_term_link() and get_category_link() should always return a full URL, but wpcom_vip_load_category_base() has been breaking that behaviour. This fix restores the correct functioning by using `home_url()` to ensure there is a full URL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removing category base using wpcom_vip_load_category_base() forces other functions to return a relative URL
2 participants