Opened 15 years ago
Last modified 6 years ago
#12779 assigned enhancement
Better support for custom post types in WP_Rewrite
Reported by: | nacin | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | Rewrite Rules | Keywords: | has-patch needs-refresh |
Focuses: | Cc: |
Description (last modified by )
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 (16)
#3
@
15 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.
#5
@
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
@
14 years ago
- Milestone changed from Awaiting Triage to Future Release
- Type changed from task (blessed) to feature request
#7
@
14 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...
#10
@
13 years ago
Interesting solution in add_register_epmask.patch, but you mispelt $wp_ep_increment.
#14
@
9 years ago
- Keywords has-patch needs-refresh added
Needs refresh & reconsideration. On refresh, comment:10 needs to be fixed.
Incomplete patch. Incomplete support. Hardly tested. Probably buggy. Probably a better way.