Custom Permalinks - Version 0.2.2

Version Description

Download this release

Release Info

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

Code changes from version 0.2.1 to 0.2.2

Files changed (2) hide show
  1. custom-permalinks.php +6 -4
  2. readme.txt +4 -2
custom-permalinks.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Custom Permalinks
4
  Plugin URI: http://michael.tyson.id.au/wordpress/plugins/custom-permalinks
5
  Donate link: http://michael.tyson.id.au/wordpress/plugins/custom-permalinks
6
  Description: Set custom permalinks on a per-post basis
7
- Version: 0.2.1
8
  Author: Michael Tyson
9
  Author URI: http://michael.tyson.id.au
10
  */
@@ -77,7 +77,7 @@ function custom_permalinks_term_link($permalink, $term) {
77
  function custom_permalinks_redirect() {
78
 
79
  // Get request URI, strip parameters
80
- $request = substr($_SERVER['REQUEST_URI'], 1);
81
  if ( ($pos=strpos($request, "?")) ) $request = substr($request, 0, $pos);
82
 
83
  global $wp_query;
@@ -118,15 +118,17 @@ function custom_permalinks_request($query) {
118
  if ( !$request ) return $query;
119
 
120
  $posts = get_posts( array('meta_key' => 'custom_permalink', 'meta_value' => $request) );
121
- if ( !$posts ) // Try adding trailing /
122
  $posts = get_posts( array('meta_key' => 'custom_permalink', 'meta_value' => $request.'/') );
 
 
123
  if ( $posts ) {
124
  // A post matches our request
125
  return array('p' => $posts[0]->ID);
126
  }
127
 
128
  $table = get_option('custom_permalink_table');
129
- if ( $table && ($term = $table[$request]) || ($term = $table[$request.'/']) ) {
130
  return array(($term['kind'] == 'category' ? 'category_name' : 'tag') => $term['slug']);
131
  }
132
 
4
  Plugin URI: http://michael.tyson.id.au/wordpress/plugins/custom-permalinks
5
  Donate link: http://michael.tyson.id.au/wordpress/plugins/custom-permalinks
6
  Description: Set custom permalinks on a per-post basis
7
+ Version: 0.2.2
8
  Author: Michael Tyson
9
  Author URI: http://michael.tyson.id.au
10
  */
77
  function custom_permalinks_redirect() {
78
 
79
  // Get request URI, strip parameters
80
+ $request = trim($_SERVER['REQUEST_URI'],'/');
81
  if ( ($pos=strpos($request, "?")) ) $request = substr($request, 0, $pos);
82
 
83
  global $wp_query;
118
  if ( !$request ) return $query;
119
 
120
  $posts = get_posts( array('meta_key' => 'custom_permalink', 'meta_value' => $request) );
121
+ if ( !$posts && $request{strlen($request)-1} != '/' ) // Try adding trailing /
122
  $posts = get_posts( array('meta_key' => 'custom_permalink', 'meta_value' => $request.'/') );
123
+ if ( !$posts && $request{strlen($request)-1} == '/' ) // Try removing trailing /
124
+ $posts = get_posts( array('meta_key' => 'custom_permalink', 'meta_value' => rtrim($request,'/')) );
125
  if ( $posts ) {
126
  // A post matches our request
127
  return array('p' => $posts[0]->ID);
128
  }
129
 
130
  $table = get_option('custom_permalink_table');
131
+ if ( $table && ($term = $table[$request]) || ($term = $table[$request.'/']) || $term = $table[rtrim($request,'/')] ) {
132
  return array(($term['kind'] == 'category' ? 'category_name' : 'tag') => $term['slug']);
133
  }
134
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://michael.tyson.id.au/wordpress/plugins/custom-permalinks
4
  Tags: permalink, url, link, address, custom, redirect
5
  Requires at least: 2.6
6
  Tested up to: 2.6.2
7
- Stable tag: 0.2.1
8
 
9
  Set custom permalinks on a per-post, per-tag or per-category basis.
10
 
@@ -23,8 +23,10 @@ over your site structure.
23
 
24
  == Changelog ==
25
 
 
 
26
  0.2.1: Better handling of trailing slashes
27
 
28
  0.2: Added 'Custom Permalinks' section under 'Manage' to show existing custom permalinks, and allow reverting to the defaults
29
 
30
- 0.1.1: Fixed bug with categories
4
  Tags: permalink, url, link, address, custom, redirect
5
  Requires at least: 2.6
6
  Tested up to: 2.6.2
7
+ Stable tag: 0.2.2
8
 
9
  Set custom permalinks on a per-post, per-tag or per-category basis.
10
 
23
 
24
  == Changelog ==
25
 
26
+ 0.2.2: Fixed bug with not matching permalinks when / appended to the URL, and workaround for infinite redirect when another plugin is enforcing trailing /
27
+
28
  0.2.1: Better handling of trailing slashes
29
 
30
  0.2: Added 'Custom Permalinks' section under 'Manage' to show existing custom permalinks, and allow reverting to the defaults
31
 
32
+ 0.1.1: Fixed bug with categories