From 346d169130bb64a0755b40b11051446d6f36cc56 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Sat, 5 Mar 2005 18:13:31 +0000 Subject: [PATCH] Fix %post_id% and date collision avoidance. http://mosquito.wordpress.org/view.php?id=1027 git-svn-id: https://develop.svn.wordpress.org/trunk@2410 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/classes.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/wp-includes/classes.php b/wp-includes/classes.php index 5bda602bdd..353802399b 100644 --- a/wp-includes/classes.php +++ b/wp-includes/classes.php @@ -858,24 +858,32 @@ class WP_Rewrite { $endians = array('%year%/%monthnum%/%day%', '%day%/%monthnum%/%year%', '%monthnum%/%day%/%year%'); $this->date_structure = ''; + $date_endian = ''; foreach ($endians as $endian) { if (false !== strpos($this->permalink_structure, $endian)) { - $this->date_structure = $this->front . $endian; + $date_endian= $endian; break; } } + if ( empty($date_endian) ) + $date_endian = '%year%/%monthnum%/%day%'; + // Do not allow the date tags and %post_id% to overlap in the permalink // structure. If they do, move the date tags to $front/date/. $front = $this->front; - if ( false !== strpos($this->permalink_structure, $this->front . '%post_id%') ) - $front = $front . 'date/'; - - if (empty($this->date_structure)) { - $this->date_structure = $front . '%year%/%monthnum%/%day%'; + preg_match_all('/%.+?%/', $this->permalink_structure, $tokens); + $tok_index = 1; + foreach ($tokens[0] as $token) { + if ( ($token == '%post_id%') && ($tok_index <= 3) ) { + $front = $front . 'date/'; + break; + } } + $this->date_structure = $front . $date_endian; + return $this->date_structure; }