WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#12507 closed enhancement (fixed)

Make /page/ filterable

Reported by: scribu Owned by: ryan
Milestone: 3.1 Priority: normal
Severity: normal Version:
Component: Permalinks Keywords: has-patch needs-testing
Focuses: Cc:

Description

It should be easy to change the /page/ part of a permalink, for i18n purposes etc.

Attachments (5)

pagination_base.diff (1.6 KB) - added by scribu 4 years ago.
Introduce 'pagination_base' filter
pagination_base.2.diff (1.7 KB) - added by scribu 4 years ago.
Make pagination_base a private var in WP_Rewrite
pagination_base.3.diff (3.7 KB) - added by scribu 4 years ago.
fix canonical redirect and wp_unique_slug()
pagination_base.4.diff (6.4 KB) - added by scribu 4 years ago.
Make <!--nextpage--> links use pagination_base
pagination_base.5.diff (7.7 KB) - added by scribu 4 years ago.
DRY for wp_link_pages()

Download all attachments as: .zip

Change History (19)

scribu4 years ago

Introduce 'pagination_base' filter

comment:1 scribu4 years ago

  • Keywords has-patch needs-testing added

comment:2 nacin4 years ago

If it is for i18n, then we should probably use _x() here and then apply a filter over that.

It may also make sense to also make this a method or property of WP_Rewrite, much like category/tag bases.

comment:3 filosofo4 years ago

Also, it would be good if all the endpoints were defined consistently, say by calling the add_endpoint method in init. Then at the bottom of init we could pass a reference to the WP_Rewrite object which would allow all such rewrite properties to be manipulated by plugin.

I really do like the idea, sort of hinted at in scribu's patch, of having a consistent API shared between rewrite and link generation for determining link structure.

Since its use is limited to 2 places in core, I'm not sure get_pagination_base would need to be a public function.

comment:4 filosofo4 years ago

class WP_Structure {

   function get_pagination_base() {}
   function get_post_structure() {}
   function get_category_structure() {}

   ...
   
   function init() {
      $this->rewrite = new WP_Rewrite;
      $this->rewrite->page_base = $this->get_pagination_base();

   }
}

$wp_structure_class = apply_filters('wp_structure_class', 'WP_Structure');
$wp_structure = new $wp_structure_class;

Everything--links, rewrite rules, etc.--all able to be changed easily in one place by extending WP_Structure.

comment:5 follow-up: scribu4 years ago

Replying to nacin:

If it is for i18n, then we should probably use _x() here and then apply a filter over that.

I agree, but it might cause trouble when a user switches the localization file, since the permalink rules aren't flushed.

It may also make sense to also make this a method or property of WP_Rewrite, much like category/tag bases.

Agreed.

Replying to filosofo:

Also, it would be good if all the endpoints were defined consistently, say by calling the add_endpoint method in init. Then at the bottom of init we could pass a reference to the WP_Rewrite object which would allow all such rewrite properties to be manipulated by plugin.

I really do like the idea, sort of hinted at in scribu's patch, of having a consistent API shared between rewrite and link generation for determining link structure.

Yeah, the rewrite API needs work. What else is new? :)

I like were you're going with this, but please open your own ticket.

comment:6 dphiffer4 years ago

  • Cc dphiffer added

comment:7 in reply to: ↑ 5 filosofo4 years ago

Replying to scribu:

I like were you're going with this, but please open your own ticket.

I will, but my main point here is that get_pagination_base be marked private. No need to expose a public API for this.

scribu4 years ago

Make pagination_base a private var in WP_Rewrite

comment:8 scribu4 years ago

In pagination_base.2.diff I've simply made pagination_base a variable in the WP_Rewrite class. It seems consistent with all the rest of the vars.

comment:9 TobiasBg4 years ago

I like your idea, scribu.

And I suggest not only doing it for /page/, but also for /trackback/ and /comment-page-X/, as they also seem to be hardcoded here.

scribu4 years ago

fix canonical redirect and wp_unique_slug()

comment:11 scribu4 years ago

pagination_base.3.diff makes redirect_canonical() and wp_unique_slug() aware of $wp_rewrite->pagination_base

scribu4 years ago

Make <!--nextpage--> links use pagination_base

scribu4 years ago

DRY for wp_link_pages()

comment:12 scribu4 years ago

  • Milestone changed from Future Release to 3.1

comment:13 scribu4 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [15582]) Don't hardcode the pagination base. Fixes #12507

comment:14 scribu4 years ago

  • Milestone changed from Awaiting Triage to 3.1
Note: See TracTickets for help on using tickets.