Make WordPress Core

Opened 13 years ago

Closed 13 years ago

Last modified 10 years ago

#12605 closed defect (bug) (fixed)

Unable to add Endpoints to custom post_types

Reported by: dd32's profile dd32 Owned by: ryan's profile ryan
Milestone: 3.0 Priority: normal
Severity: normal Version: 3.0
Component: Rewrite Rules Keywords: has-patch
Focuses: Cc:


At present, Its impossible to add/apply Endpoints to custom post_type's due to the Endpoint Mask being applied to the rule creation.

Patch coming up has 2 sections to it

  • Adds support to add_endpoint() to specify a Endpoint mask to apply to the rule, Defaults to EP_NONE as it currently does
    • Changes WP_Rewrite::extra_permastructs from a String to an Array of ($rule, EP_MASK)
      • Backwards compatibility is retained for anything which adds to that directly..
  • Adds support to register_post_type() to specify a "permalink_epmask" arg, This defaults to EP_NONE as current
    • Can be set to, for example, EP_PERMALINK for the same endpoints as posts recieve
    • Used in conjuction with Part 1 of this patch, It allows for a custom value (For example, 215) to be passed with the post AND passed with a Endpoint, The result is being able to register endpoints for a specific custom post_type.

I suspect this also currently would render endpoints for taxonomies not possible, but that would be a much less often used process

Attachments (1)

12605.diff (4.0 KB) - added by dd32 13 years ago.

Download all attachments as: .zip

Change History (8)

13 years ago

#1 @dd32
13 years ago

That patch also includes a change to $ep_mask_specific being undefined. I'm not sure EP_NONE is the correct default for that flag given the location its being used:

#2 @dd32
13 years ago

  • Keywords has-patch added

#3 @unsalkorkmaz
13 years ago

  • Cc unsalkorkmaz added

#4 @dd32
13 years ago

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

(In [13773]) Allow for a custom Endpoint Mask to be passed to add_endpoint(). Allows for endpoints to be targeted to specific rewrite rules. Allow custom post_types to specify their Endpoint mask. Allows for post_type's rewrite rules to inherit Post endpoints, or alternatively, allows for add_endpoint() to target specific post_types. Fixes #12605

#5 follow-up: @dd32
13 years ago

Example use:

define('EP_WIKI', 131072); // 2^17. 2^13 is used by core.
register_post_type('wiki', array(
	'label' => __('Wiki'),
	'public' => true,
	'supports' => array('revisions', 'editor', 'title'),
	'permalink_epmask' => EP_WIKI,
	'hierarchical' => true
add_rewrite_endpoint('history', EP_WIKI);

The post_type 'wiki' rules will now include a /edit/(.../)? endpoint, which does not get applied to any other type of rule that core generates.

Care would need to be taken that any custom endpoints are in 2x format, and not currently in use by any other plugins loaded..

#6 @dd32
13 years ago

The post_type 'wiki' rules will now include a /edit/(.../)? endpoint

Of course, i used the /history/(..../)? example in that code. Result is the same, just wrong name.

#7 in reply to: ↑ 5 @ericlewis
10 years ago

Replying to dd32:

Care would need to be taken that any custom endpoints are in 2x format, and not currently in use by any other plugins loaded..

Indeed. This limits the wide-usage of plugins extending the endpoints API, as a developer would need to inspect code to ensure plugins that create custom endpoints are playing nicely with each other.

Last edited 10 years ago by ericlewis (previous) (diff)
Note: See TracTickets for help on using tickets.