From 0937ec283ddace2e718d11b480ec941709a2b9dd Mon Sep 17 00:00:00 2001 From: Dougal Campbell Date: Mon, 22 Dec 2003 23:00:45 +0000 Subject: [PATCH] Fixed %post_id% token handling. Fixed pingback link detection. git-svn-id: https://develop.svn.wordpress.org/trunk@640 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/options-permalink.php | 9 ++++++--- wp-includes/functions.php | 17 ++++++++++++----- wp-includes/template-functions.php | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/wp-admin/options-permalink.php b/wp-admin/options-permalink.php index 00c192ecdc..20e737dbad 100644 --- a/wp-admin/options-permalink.php +++ b/wp-admin/options-permalink.php @@ -104,19 +104,22 @@ $rewritecode = array( '%year%', '%monthnum%', '%day%', - '%postname%' + '%postname%', + '%post_id%' ); $rewritereplace = array( '([0-9]{4})?', '([0-9]{1,2})?', '([0-9]{1,2})?', - '([0-9a-z-]+)?' + '([0-9a-z-]+)?', + '([0-9]+)?' ); $queryreplace = array ( 'year=', 'monthnum=', 'day=', - 'name=' + 'name=', + 'p=' ); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 8e507d9962..151776b289 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -493,13 +493,15 @@ function url_to_postid($url = '') { '%year%', '%monthnum%', '%day%', - '%postname%' + '%postname%', + '%post_id%' ); $rewritereplace = array( '([0-9]{4})?', '([0-9]{1,2})?', '([0-9]{1,2})?', - '([0-9a-z-]+)?' + '([0-9a-z-]+)?', + '([0-9]+)?' ); // Turn the structure into a regular expression @@ -516,18 +518,23 @@ function url_to_postid($url = '') { $name = $tokens[1][$i]; $value = $values[$i+1]; - // Create a variable named $year, $monthnum, $day, or $postname: + // Create a variable named $year, $monthnum, $day, $postname, or $post_id: $$name = $value; } - // Build a WHERE clause, making the values safe along the way: + // If using %post_id%, we're done: + if (intval($post_id)) return intval($post_id); + + // Otherwise, build a WHERE clause, making the values safe along the way: if ($year) $where .= " AND YEAR(post_date) = " . intval($year); if ($monthnum) $where .= " AND MONTH(post_date) = " . intval($monthnum); if ($day) $where .= " AND DAYOFMONTH(post_date) = " . intval($day); if ($postname) $where .= " AND post_name = '" . $wpdb->escape($postname) . "' "; // Run the query to get the post ID: - return intval($wpdb->get_var("SELECT ID FROM $tableposts WHERE 1 = 1 " . $where)); + $id = intval($wpdb->get_var("SELECT ID FROM $tableposts WHERE 1 = 1 " . $where)); + + return $id; } diff --git a/wp-includes/template-functions.php b/wp-includes/template-functions.php index 3ebec66a98..ad06e7d32b 100644 --- a/wp-includes/template-functions.php +++ b/wp-includes/template-functions.php @@ -419,7 +419,8 @@ function get_permalink($id=false) { date('Y', $unixtime), date('n', $unixtime), date('j', $unixtime), - $post->post_name + $post->post_name, + $post->ID ); return $siteurl . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure')); } else { // if they're not using the fancy permalink option