Opened 3 years ago
Last modified 10 months ago
#12779 new enhancement
Better support for custom post types in WP_Rewrite
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | Future Release |
| Component: | Rewrite Rules | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | unsalkorkmaz, dkikizas@…, mikeschinkel@…, Ken@…, justin@… |
Description (last modified by nacin)
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)
Change History (14)
comment:2
unsalkorkmaz
— 3 years ago
- Cc unsalkorkmaz added
comment:3
dd32
— 3 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.
comment:5
mikeschinkel
— 3 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.
comment:6
nacin
— 3 years ago
- Milestone changed from Awaiting Triage to Future Release
- Type changed from task (blessed) to feature request
comment:7
scribu
— 2 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...
comment:8
WraithKenny
— 2 years ago
- Cc Ken@… added
Above patch offered as a quick and easy alternative
comment:9
WraithKenny
— 23 months ago
Related #16303
comment:10
scribu
— 23 months ago
Interesting solution in add_register_epmask.patch, but you mispelt $wp_ep_increment.
comment:11
WraithKenny
— 23 months ago
Doh! Er, would ya believe "incement" as meaning solid?
comment:12
greenshady
— 10 months ago
- Cc justin@… added
Incomplete patch. Incomplete support. Hardly tested. Probably buggy. Probably a better way.