[wp-trac] [WordPress Trac] #35916: WP_Rewrite::generate_rewrite_rules() ignores boolean $endpoints / $feed parameters for CPT
WordPress Trac
noreply at wordpress.org
Sat Feb 27 02:35:20 UTC 2016
#35916: WP_Rewrite::generate_rewrite_rules() ignores boolean $endpoints / $feed
parameters for CPT
------------------------------------------+------------------------------
Reporter: solo14000 | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Rewrite Rules | Version:
Severity: normal | Resolution:
Keywords: needs-patch needs-unit-tests | Focuses:
------------------------------------------+------------------------------
Changes (by johnbillion):
* keywords: => needs-patch needs-unit-tests
* version: 4.4.2 =>
* component: Permalinks => Rewrite Rules
Old description:
> Hello,
>
> I'm trying to declare custom rewrite rules for a custom post type without
> endpoints and feeds.
> As result, WP ignore the endpoint flag in the
> WP_Rewrite::generate_rewrite_rules().
>
> What I did is as following.
>
> I created a custom post type called 'event' with the following arguments
> for register_post_type() :
>
> {{{#!php
> <?php
> array( // Array of WP post type args
> 'labels' => array( 'name' => 'Events',
> 'singular_name' => 'Event',
> ),
> 'public' => true,
> 'publicly_queryable' => true,
> 'show_ui' => true,
> 'show_in_menu' => true,
> 'query_var' => false,
> 'rewrite' => false,
> 'capability_type' => 'post',
> 'hierarchical' => false,
> 'menu_position' => 5,
> 'menu_icon' => 'dashicons-tickets-alt',
> 'supports' => array(
> 'title',
> 'editor',
> 'thumbnail',
> ),
> 'taxonomies' => array(
> 'post_tag',
> 'my_category',
> ),
> );
> }}}
>
> Then I called
>
> {{{#!php
> <?php
> $args_post_type = array(
> 'feed' => false,
> 'paged' => false,
> 'ep_mask' => EP_NONE,
> 'endpoints' => false,
> );
> add_permastruct('events', 'events/%event%', $args_post_type);
> }}}
>
> The resultings rewrite rules are :
>
> {{{
> 'events/[^/]+/attachment/([^/]+)/?$' => string
> 'index.php?attachment=$matches[1]' (length=32)
> 'events/[^/]+/attachment/([^/]+)/trackback/?$' => string
> 'index.php?attachment=$matches[1]&tb=1' (length=37)
> 'events/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' =>
> string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
> 'events/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string
> 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
> 'events/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => string
> 'index.php?attachment=$matches[1]&cpage=$matches[2]' (length=50)
> 'events/[^/]+/attachment/([^/]+)/embed/?$' => string
> 'index.php?attachment=$matches[1]&embed=true' (length=43)
> 'events/([^/]+)/embed/?$' => string
> 'index.php?event=$matches[1]&embed=true' (length=38)
> 'events/([^/]+)/trackback/?$' => string
> 'index.php?event=$matches[1]&tb=1' (length=32)
> 'events/([^/]+)(?:/([0-9]+))?/?$' => string
> 'index.php?event=$matches[1]&page=$matches[2]' (length=44)
> 'events/[^/]+/([^/]+)/?$' => string 'index.php?attachment=$matches[1]'
> (length=32)
> 'events/[^/]+/([^/]+)/trackback/?$' => string
> 'index.php?attachment=$matches[1]&tb=1' (length=37)
> 'events/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string
> 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
> 'events/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string
> 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
> 'events/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => string
> 'index.php?attachment=$matches[1]&cpage=$matches[2]' (length=50)
> 'events/[^/]+/([^/]+)/embed/?$' => string
> 'index.php?attachment=$matches[1]&embed=true' (length=43)
> }}}
>
> Looking at class-wp-rewrite.php, I noticed in generate_rewrite_rules()
> that piece of code that forces the $post flag for CTP
>
>
> {{{#!php
> <?php
> if ( ! $post ) {
> // For custom post types, we need
> to add on endpoints as well.
> foreach ( get_post_types(
> array('_builtin' => false ) ) as $ptype ) {
> if ( strpos($struct,
> "%$ptype%") !== false ) {
> $post = true;
>
> // This is for
> page style attachment URLs.
> $page =
> is_post_type_hierarchical( $ptype );
> break;
> }
> }
> }
>
> }}}
>
> and that piece of code that unconditionnaly add extra endpoints /
> feeds... for post
>
> {{{#!php
> <?php
> // If we're matching a permalink, add
> those extras (attachments etc) on.
> if ( $post ) {
> // Add trackback.
> $rewrite =
> array_merge(array($trackbackmatch => $trackbackquery), $rewrite);
>
> }}}
>
> Could confirm that problem?
>
> Thanks
New description:
Hello,
I'm trying to declare custom rewrite rules for a custom post type without
endpoints and feeds.
As result, WP ignore the endpoint flag in the
WP_Rewrite::generate_rewrite_rules().
What I did is as following.
I created a custom post type called 'event' with the following arguments
for register_post_type() :
{{{#!php
array( // Array of WP post type args
'labels' => array(
'name' => 'Events',
'singular_name' => 'Event',
),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => false,
'rewrite' => false,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 'dashicons-tickets-alt',
'supports' => array(
'title',
'editor',
'thumbnail',
),
'taxonomies' => array(
'post_tag',
'my_category',
),
);
}}}
Then I called
{{{#!php
$args_post_type = array(
'feed' => false,
'paged' => false,
'ep_mask' => EP_NONE,
'endpoints' => false,
);
add_permastruct('events', 'events/%event%', $args_post_type);
}}}
The resultings rewrite rules are :
{{{
'events/[^/]+/attachment/([^/]+)/?$' => string
'index.php?attachment=$matches[1]' (length=32)
'events/[^/]+/attachment/([^/]+)/trackback/?$' => string
'index.php?attachment=$matches[1]&tb=1' (length=37)
'events/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' =>
string 'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
'events/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string
'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
'events/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => string
'index.php?attachment=$matches[1]&cpage=$matches[2]' (length=50)
'events/[^/]+/attachment/([^/]+)/embed/?$' => string
'index.php?attachment=$matches[1]&embed=true' (length=43)
'events/([^/]+)/embed/?$' => string
'index.php?event=$matches[1]&embed=true' (length=38)
'events/([^/]+)/trackback/?$' => string 'index.php?event=$matches[1]&tb=1'
(length=32)
'events/([^/]+)(?:/([0-9]+))?/?$' => string
'index.php?event=$matches[1]&page=$matches[2]' (length=44)
'events/[^/]+/([^/]+)/?$' => string 'index.php?attachment=$matches[1]'
(length=32)
'events/[^/]+/([^/]+)/trackback/?$' => string
'index.php?attachment=$matches[1]&tb=1' (length=37)
'events/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => string
'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
'events/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => string
'index.php?attachment=$matches[1]&feed=$matches[2]' (length=49)
'events/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => string
'index.php?attachment=$matches[1]&cpage=$matches[2]' (length=50)
'events/[^/]+/([^/]+)/embed/?$' => string
'index.php?attachment=$matches[1]&embed=true' (length=43)
}}}
Looking at class-wp-rewrite.php, I noticed in generate_rewrite_rules()
that piece of code that forces the $post flag for CTP
{{{#!php
if ( ! $post ) {
// For custom post types, we need to add on endpoints as well.
foreach ( get_post_types( array('_builtin' => false ) ) as $ptype
) {
if ( strpos($struct, "%$ptype%") !== false ) {
$post = true;
// This is for page style attachment URLs.
$page = is_post_type_hierarchical( $ptype );
break;
}
}
}
}}}
and that piece of code that unconditionnaly add extra endpoints / feeds...
for post
{{{#!php
// If we're matching a permalink, add those extras (attachments etc) on.
if ( $post ) {
// Add trackback.
$rewrite = array_merge(array($trackbackmatch => $trackbackquery),
$rewrite);
}}}
Could confirm that problem?
Thanks
--
Comment:
Thanks for the report, @solo14000, and welcome to WordPress Trac.
I've confirmed this bug. Rewrite rules for endpoints and feeds still get
applied to the permalink structure in this situation.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35916#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list