Make WordPress Core

Opened 16 months ago

#57507 new defect (bug)

function wp_unique_post_slug inconsistent for numerical page slugs, e.g. 404

Reported by: arve5's profile arve5 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version: 6.1.1
Component: Posts, Post Types Keywords: dev-feedback has-testing-info
Focuses: administration Cc:


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.

$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.

Change History (0)

Note: See TracTickets for help on using tickets.