[wp-trac] [WordPress Trac] #57507: function wp_unique_post_slug inconsistent for numerical page slugs, e.g. 404

WordPress Trac noreply at wordpress.org
Thu Jan 19 11:03:36 UTC 2023


#57507: function wp_unique_post_slug inconsistent for numerical page slugs, e.g.
404
-------------------------------+-------------------------------------------
 Reporter:  arve5              |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  6.1.1
 Severity:  minor              |   Keywords:  dev-feedback has-testing-info
  Focuses:  administration     |
-------------------------------+-------------------------------------------
 {{{
 if ( $post_name_check
                         || in_array( $slug, $feeds, true ) || 'embed' ===
 $slug
                         || preg_match(
 "@^($wp_rewrite->pagination_base)?\d+$@", $slug )
                         || $is_bad_hierarchical_slug
                 )
 }}}

 Will always return true for preg_match as long as 'page' is optional and
 it is a numerical slug, e.g. 404


 {{{
 preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )
 preg_match( "@^(page)?\d+$, 404") => 1
 }}}


 Assuming pagination is the point for this check, a possible solution could
 be to check if post pagination navigation exists first.


 {{{#!php
 $pagination_based = get_the_post_navigation() ? preg_match(
 "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) : false;
 if ( $post_name_check
                         || in_array( $slug, $feeds, true ) || 'embed' ===
 $slug
                         || pagination_based
                         || $is_bad_hierarchical_slug
                 )

 }}}


 Suggestion: Either allow numerical slugs if it does not interfere with
 paginations, or disallow it with a warning.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/57507>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list