[wp-trac] [WordPress Trac] #35916: WP_Rewrite::generate_rewrite_rules() ignores boolean $endpoints / $feed parameters for CPT
WordPress Trac
noreply at wordpress.org
Tue Feb 23 08:34:14 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: Permalinks | Version: 4.4.2
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
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
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35916>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list