Custom Permalinks - Version 0.7.15

Version Description

  • Permalinks are now case-insensitive (thanks to @ericmann)
Download this release

Release Info

Developer michaeltyson
Plugin Icon Custom Permalinks
Version 0.7.15
Comparing to
See all releases

Code changes from version 0.7.14 to 0.7.15

Files changed (2) hide show
  1. custom-permalinks.php +14 -12
  2. readme.txt +5 -1
custom-permalinks.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Custom Permalinks
4
  Plugin URI: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
5
  Donate link: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
6
  Description: Set custom permalinks on a per-post basis
7
- Version: 0.7.14
8
  Author: Michael Tyson
9
  Author URI: http://atastypixel.com/blog
10
  */
@@ -93,7 +93,8 @@ function custom_permalinks_term_link($permalink, $term) {
93
  function custom_permalinks_redirect() {
94
 
95
  // Get request URI, strip parameters
96
- $url = parse_url(get_bloginfo('url')); $url = $url['path'];
 
97
  $request = ltrim(substr($_SERVER['REQUEST_URI'], strlen($url)),'/');
98
  if ( ($pos=strpos($request, "?")) ) $request = substr($request, 0, $pos);
99
 
@@ -113,7 +114,7 @@ function custom_permalinks_redirect() {
113
  $original_permalink = (is_tag() ? custom_permalinks_original_tag_link($theTerm->term_id) :
114
  custom_permalinks_original_category_link($theTerm->term_id));
115
  }
116
-
117
  if ( $custom_permalink &&
118
  (substr($request, 0, strlen($custom_permalink)) != $custom_permalink ||
119
  $request == $custom_permalink."/" ) ) {
@@ -151,23 +152,24 @@ function custom_permalinks_request($query) {
151
  $originalUrl = NULL;
152
 
153
  // Get request URI, strip parameters and /'s
154
- $url = parse_url(get_bloginfo('url')); $url = $url['path'];
 
155
  $request = ltrim(substr($_SERVER['REQUEST_URI'], strlen($url)),'/');
156
  $request = (($pos=strpos($request, '?')) ? substr($request, 0, $pos) : $request);
157
  $request_noslash = preg_replace('@/+@','/', trim($request, '/'));
158
-
159
  if ( !$request ) return $query;
160
 
161
  $sql = "SELECT $wpdb->posts.ID, $wpdb->postmeta.meta_value, $wpdb->posts.post_type FROM $wpdb->posts ".
162
  "LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE ".
163
  " meta_key = 'custom_permalink' AND ".
164
  " meta_value != '' AND ".
165
- " ( meta_value = LEFT('".mysql_escape_string($request_noslash)."', LENGTH(meta_value)) OR ".
166
- " meta_value = LEFT('".mysql_escape_string($request_noslash."/")."', LENGTH(meta_value)) ) ".
167
  "ORDER BY LENGTH(meta_value) DESC LIMIT 1";
168
 
169
  $posts = $wpdb->get_results($sql);
170
-
171
  if ( $posts ) {
172
  // A post matches our request
173
 
@@ -175,13 +177,13 @@ function custom_permalinks_request($query) {
175
  if ( $request_noslash == trim($posts[0]->meta_value,'/') )
176
  $_CPRegisteredURL = $request;
177
 
178
- $originalUrl = preg_replace( '@/+@', '/', str_replace( trim( $posts[0]->meta_value,'/' ),
179
  ( $posts[0]->post_type == 'page' ?
180
  custom_permalinks_original_page_link($posts[0]->ID)
181
  : custom_permalinks_original_post_link($posts[0]->ID) ),
182
- $request_noslash ) );
183
  }
184
-
185
  if ( $originalUrl === NULL ) {
186
  // See if any terms have a matching permalink
187
  $table = get_option('custom_permalink_table');
@@ -230,7 +232,7 @@ function custom_permalinks_request($query) {
230
  $oldValues[$key] = $_REQUEST[$key];
231
  $_REQUEST[$key] = $_GET[$key] = $value;
232
  }
233
-
234
  // Re-run the filter, now with original environment in place
235
  remove_filter( 'request', 'custom_permalinks_request', 10, 1 );
236
  global $wp;
4
  Plugin URI: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
5
  Donate link: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
6
  Description: Set custom permalinks on a per-post basis
7
+ Version: 0.7.15
8
  Author: Michael Tyson
9
  Author URI: http://atastypixel.com/blog
10
  */
93
  function custom_permalinks_redirect() {
94
 
95
  // Get request URI, strip parameters
96
+ $url = parse_url(get_bloginfo('url'));
97
+ $url = isset($url['path']) ? $url['path'] : '';
98
  $request = ltrim(substr($_SERVER['REQUEST_URI'], strlen($url)),'/');
99
  if ( ($pos=strpos($request, "?")) ) $request = substr($request, 0, $pos);
100
 
114
  $original_permalink = (is_tag() ? custom_permalinks_original_tag_link($theTerm->term_id) :
115
  custom_permalinks_original_category_link($theTerm->term_id));
116
  }
117
+
118
  if ( $custom_permalink &&
119
  (substr($request, 0, strlen($custom_permalink)) != $custom_permalink ||
120
  $request == $custom_permalink."/" ) ) {
152
  $originalUrl = NULL;
153
 
154
  // Get request URI, strip parameters and /'s
155
+ $url = parse_url(get_bloginfo('url'));
156
+ $url = isset($url['path']) ? $url['path'] : '';
157
  $request = ltrim(substr($_SERVER['REQUEST_URI'], strlen($url)),'/');
158
  $request = (($pos=strpos($request, '?')) ? substr($request, 0, $pos) : $request);
159
  $request_noslash = preg_replace('@/+@','/', trim($request, '/'));
160
+
161
  if ( !$request ) return $query;
162
 
163
  $sql = "SELECT $wpdb->posts.ID, $wpdb->postmeta.meta_value, $wpdb->posts.post_type FROM $wpdb->posts ".
164
  "LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id) WHERE ".
165
  " meta_key = 'custom_permalink' AND ".
166
  " meta_value != '' AND ".
167
+ " ( LOWER(meta_value) = LEFT(LOWER('".mysql_escape_string($request_noslash)."'), LENGTH(meta_value)) OR ".
168
+ " LOWER(meta_value) = LEFT(LOWER('".mysql_escape_string($request_noslash."/")."'), LENGTH(meta_value)) ) ".
169
  "ORDER BY LENGTH(meta_value) DESC LIMIT 1";
170
 
171
  $posts = $wpdb->get_results($sql);
172
+
173
  if ( $posts ) {
174
  // A post matches our request
175
 
177
  if ( $request_noslash == trim($posts[0]->meta_value,'/') )
178
  $_CPRegisteredURL = $request;
179
 
180
+ $originalUrl = preg_replace( '@/+@', '/', str_replace( trim( strtolower($posts[0]->meta_value),'/' ),
181
  ( $posts[0]->post_type == 'page' ?
182
  custom_permalinks_original_page_link($posts[0]->ID)
183
  : custom_permalinks_original_post_link($posts[0]->ID) ),
184
+ strtolower($request_noslash) ) );
185
  }
186
+
187
  if ( $originalUrl === NULL ) {
188
  // See if any terms have a matching permalink
189
  $table = get_option('custom_permalink_table');
232
  $oldValues[$key] = $_REQUEST[$key];
233
  $_REQUEST[$key] = $_GET[$key] = $value;
234
  }
235
+
236
  // Re-run the filter, now with original environment in place
237
  remove_filter( 'request', 'custom_permalinks_request', 10, 1 );
238
  global $wp;
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://atastypixel.com/blog/wordpress/plugins/custom-permalinks/
4
  Tags: permalink, url, link, address, custom, redirect
5
  Requires at least: 2.6
6
  Tested up to: 3.3.1
7
- Stable tag: 0.7.14
8
 
9
  Set custom permalinks on a per-post, per-tag or per-category basis.
10
 
@@ -29,6 +29,10 @@ within that category.
29
 
30
  == Changelog ==
31
 
 
 
 
 
32
  = 0.7.14 =
33
 
34
  * Delete permalinks upon page/post deletion
4
  Tags: permalink, url, link, address, custom, redirect
5
  Requires at least: 2.6
6
  Tested up to: 3.3.1
7
+ Stable tag: 0.7.15
8
 
9
  Set custom permalinks on a per-post, per-tag or per-category basis.
10
 
29
 
30
  == Changelog ==
31
 
32
+ = 0.7.15 =
33
+
34
+ * Permalinks are now case-insensitive (thanks to @ericmann)
35
+
36
  = 0.7.14 =
37
 
38
  * Delete permalinks upon page/post deletion