Skip to content

Conversation

@naxoc
Copy link
Member

@naxoc naxoc commented Feb 8, 2024

All Submissions:

Changes proposed in this Pull Request:

Because WP allows a url that shouldn't really exist when a site has the /%category%/%postname%/ permalink structure, the pager links break. See https://core.trac.wordpress.org/ticket/8905 and https://core.trac.wordpress.org/ticket/21209

This PR tries to help out the pager only on sites with that specific url structure.

How to test the changes in this Pull Request:

Before applying the patch:

  1. On a test site, set the permalink structure to /%category%/%postname%
  2. Create a category (or use an existing one). It needs to have enough posts that it gets a pager. Let's say it's called kitten.
  3. Go to https://your-site.local/kitten This page shouldn't really exist, but it does. Now hover the pager or click "2". You will be taken to /kitten/page/2 and the page 404s.

Now apply the patch

  1. Go to /kitten
  2. Hover over or navigate to an item in the pager.
  3. Verify that you were taken to a page that does not 404 and is correct :)
  4. Try changing the category base and verify that the pager still works.

naxoc added 2 commits February 8, 2024 18:37
On a permalink structure like this /%category%/%postname%/ some fixes to
the pager was needed. Also guard against a post with the slug 'page' to
avoid confusion to routing.
Don't hardcode category base
@naxoc naxoc self-assigned this Feb 8, 2024
@naxoc naxoc requested a review from a team as a code owner February 8, 2024 18:07
Copy link
Contributor

@leogermani leogermani left a comment

Choose a reason for hiding this comment

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

It works well and fixes the issue! I left two comments

* Action callback for init.
*/
public static function on_init() {
if ( '/%category%/%postname%/' === get_option( 'permalink_structure' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've ran some tests and the issue also occurs with other settings, for example /%category%/%post_id%/.

It does not happen if you do /%post_id%//%category% though.

Didn't go too far to get at the bottom of why this happens, but I think we can assume that it happens if the permalink structure starts with category?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch! I changed it to sniff if the permalink structure starts with /%category%/.

/**
* Action callback for init.
*/
public static function on_init() {
Copy link
Contributor

@leogermani leogermani Feb 8, 2024

Choose a reason for hiding this comment

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

WDYT of hooking directly into paginate_links and checking the permalink_structure option there?

I think it's better to have that check done only when really needed than on every single request.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes much better sense. I changed it. Thanks

* PR feedback adressed
* Use 'category' as default if base is empty
@naxoc
Copy link
Member Author

naxoc commented Feb 9, 2024

This is ready for re-review. I also caught that the category_base can be empty (and category is then assumed by WP but not returned in the option, so I'm setting a default now.

@adekbadek
Copy link
Member

(merged in trunk so that CI jobs pass)

@leogermani
Copy link
Contributor

I think this is good to go. @naxoc do you want to turn this into a hotfix so we can release it immediately? Or can it wait the regular release flow?

If you want to make it a hotfix, we need to rebase it against the release branch, and prefix the branch name with hotfix/. (Sorry! I should probably have told you this earlier)

@github-actions github-actions bot added the [Status] Approved The pull request has been reviewed and is ready to merge label Feb 9, 2024
@naxoc naxoc merged commit c851bb6 into trunk Feb 9, 2024
@naxoc naxoc deleted the fix/category-url-pager branch February 9, 2024 17:48
leogermani pushed a commit that referenced this pull request Feb 9, 2024
* fix(categories): fix pager urls

On a permalink structure like this /%category%/%postname%/ some fixes to
the pager was needed. Also guard against a post with the slug 'page' to
avoid confusion to routing.

* fix(categories): fix pager urls

Don't hardcode category base

* Don't hardcode category base and remove unneeded filter

* fix(categories): fix pager urls

* PR feedback adressed
* Use 'category' as default if base is empty

---------

Co-authored-by: Adam Boro <aborowski24@gmail.com>
matticbot pushed a commit that referenced this pull request Feb 9, 2024
# [3.1.0-alpha.2](v3.1.0-alpha.1...v3.1.0-alpha.2) (2024-02-09)

### Bug Fixes

* **categories:** fix pager urls ([#2913](#2913)) ([bb7e534](bb7e534))
matticbot pushed a commit that referenced this pull request Feb 9, 2024
# [3.1.0-alpha.3](v3.1.0-alpha.2...v3.1.0-alpha.3) (2024-02-09)

### Bug Fixes

* **categories:** fix pager urls ([#2913](#2913)) ([c851bb6](c851bb6))
* update path to wide template file ([#2918](#2918)) ([fdd6b69](fdd6b69))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.1.0-alpha.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.1.0-epic-ras-acc.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Feb 20, 2024
# [3.1.0](v3.0.5...v3.1.0) (2024-02-20)

### Bug Fixes

* add frequency tab options for donations, even when tiers are disabled ([#2930](#2930)) ([cb7eb7b](cb7eb7b))
* **categories:** fix pager urls ([#2913](#2913)) ([bb7e534](bb7e534))
* **categories:** fix pager urls ([#2913](#2913)) ([c851bb6](c851bb6))
* **engagement-wizard:** handle error when retrieving subscription lists ([e85c108](e85c108))
* **ras:** only sync spend total and last payment amounts for completed orders ([#2886](#2886)) ([68aaf39](68aaf39))
* redirect to origin from magic link ([9f41947](9f41947))
* typescript errors ([dc27973](dc27973))
* TypeScript usage; add to CI ([#2884](#2884)) ([6f5e7a6](6f5e7a6))
* update newsletter scroll appearance in Sign Up modal ([#2897](#2897)) ([496723a](496723a))
* update path to wide template file ([#2918](#2918)) ([fdd6b69](fdd6b69))

### Features

* **ci:** add epic/* release workflow and rename `master` to `trunk` ([#2895](#2895)) ([ea02075](ea02075)), closes [#2897](#2897) [#2886](#2886)
* **reader-revenue:** make NYP and Stripe Gateway optional ([#2866](#2866)) ([fcfa88c](fcfa88c))
* remove new tab default on image credits ([#2880](#2880)) ([3c996b1](3c996b1))
* **wc:** override cart, checkout, and my-account page templates ([#2893](#2893)) ([68b1836](68b1836))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 3.1.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released on @alpha released on @epic/ras-acc released [Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants