Make WordPress Core

Opened 14 years ago

Last modified 5 years ago

#12779 assigned enhancement

Better support for custom post types in WP_Rewrite

Reported by: nacin's profile nacin Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Rewrite Rules Keywords: has-patch needs-refresh
Focuses: Cc:

Description (last modified by nacin)

See also #12605 and [13773].

We currently use bitmasks in WP_Rewrite, which we should remove and convert to an array of URL types that can be checked using in_array(). We currently do not use bitmask operations in WP_Rewrite that would make them preferable for use.

To currently use custom post types with endpoints, a plugin would need to do the following, from dd32 in #12605:

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);

In particular:

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

This would need to be backwards compatible with the existing bitmasks. More or less, WP_Rewrite::add_endpoint() would need to still take bitmasks and convert them to the new format.

Attachments (2)

12779.diff (12.0 KB) - added by nacin 14 years ago.
Incomplete patch. Incomplete support. Hardly tested. Probably buggy. Probably a better way.
add_register_epmask.patch (2.6 KB) - added by WraithKenny 13 years ago.
conflict free EP_MASK defines

Download all attachments as: .zip

Change History (16)

#1 @nacin
14 years ago

  • Description modified (diff)

@nacin
14 years ago

Incomplete patch. Incomplete support. Hardly tested. Probably buggy. Probably a better way.

#2 @unsalkorkmaz
14 years ago

  • Cc unsalkorkmaz added

#3 @dd32
14 years ago

  • Milestone changed from 3.0 to 3.1

As well as using strings like that, I'd like to have a supports style granity to it.

For example, Take adding post_types, they'll all get given the same set of permalinks regardless of if they support a function or not, for example, all will receive paging and comment paging rules regardless of if they actually support it.

This might be part of a larger write to make the rewrite rule generation/parsing more optimized for various cases..

Moving to 3.1 due to lack of full patch and enough testing time for this.

#4 @demetris
14 years ago

  • Cc dkikizas@… added

#5 @mikeschinkel
14 years ago

  • Cc mikeschinkel@… added

-1 on using end_point mask constants for this. Too cryptic for 80% of the people who will be struggling to write the register_post_type() code for what they need. Use strings instead.

#6 @nacin
13 years ago

  • Milestone changed from Awaiting Triage to Future Release
  • Type changed from task (blessed) to feature request

#7 @scribu
13 years ago

  • Type changed from feature request to enhancement

How about bundling all the endpoints in the 'rewrite' arg?

Example:

register_post_type( 'foo', array(
  ...
  'rewrite' => array(
    'slug' => 'fooz',
    'extra_endpoints' => array( 'bar', 'baz' )
  )
);

Sidenote:

Instead of using EP_MASK, I found it much easier to just use add_rewrite_rule(), with the CPT slug prefixed to it. Now, if only add_rewrite_rule() had a $with_front arg...

@WraithKenny
13 years ago

conflict free EP_MASK defines

#8 @WraithKenny
13 years ago

  • Cc Ken@… added

Above patch offered as a quick and easy alternative

#10 @scribu
13 years ago

Interesting solution in add_register_epmask.patch, but you mispelt $wp_ep_increment.

#11 @WraithKenny
13 years ago

Doh! Er, would ya believe "incement" as meaning solid?

#12 @greenshady
12 years ago

  • Cc justin@… added

#13 @ryan
10 years ago

  • Owner ryan deleted
  • Status changed from new to assigned

#14 @chriscct7
8 years ago

  • Keywords has-patch needs-refresh added

Needs refresh & reconsideration. On refresh, comment:10 needs to be fixed.

Note: See TracTickets for help on using tickets.